mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 05:41:14 +01:00
Add spans to toCssValue() errors.
This commit is contained in:
parent
b9aed9f8d6
commit
d86c90bb0b
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:charcode/charcode.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:source_span/source_span.dart';
|
import 'package:source_span/source_span.dart';
|
||||||
import 'package:stack_trace/stack_trace.dart';
|
import 'package:stack_trace/stack_trace.dart';
|
||||||
@ -618,8 +619,8 @@ class _PerformVisitor
|
|||||||
var url = _interpolationToValue(import.url);
|
var url = _interpolationToValue(import.url);
|
||||||
var supports = import.supports;
|
var supports = import.supports;
|
||||||
var resolvedSupports = supports is SupportsDeclaration
|
var resolvedSupports = supports is SupportsDeclaration
|
||||||
? "(${supports.name.accept(this).toCssString()}: "
|
? "(${_evaluateToCss(supports.name)}: "
|
||||||
"${supports.value.accept(this).toCssString()})"
|
"${_evaluateToCss(supports.value)})"
|
||||||
: (supports == null ? null : _visitSupportsCondition(supports));
|
: (supports == null ? null : _visitSupportsCondition(supports));
|
||||||
var mediaQuery =
|
var mediaQuery =
|
||||||
import.media == null ? null : _visitMediaQueries(import.media);
|
import.media == null ? null : _visitMediaQueries(import.media);
|
||||||
@ -836,10 +837,10 @@ class _PerformVisitor
|
|||||||
} else if (condition is SupportsNegation) {
|
} else if (condition is SupportsNegation) {
|
||||||
return "not ${_parenthesize(condition.condition)}";
|
return "not ${_parenthesize(condition.condition)}";
|
||||||
} else if (condition is SupportsInterpolation) {
|
} else if (condition is SupportsInterpolation) {
|
||||||
return condition.expression.accept(this).toCssString(quote: false);
|
return _evaluateToCss(condition.expression, quote: false);
|
||||||
} else if (condition is SupportsDeclaration) {
|
} else if (condition is SupportsDeclaration) {
|
||||||
return "(${condition.name.accept(this).toCssString()}: "
|
return "(${_evaluateToCss(condition.name)}: "
|
||||||
"${condition.value.accept(this).toCssString()})";
|
"${_evaluateToCss(condition.value)})";
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -876,7 +877,9 @@ class _PerformVisitor
|
|||||||
Value visitWarnRule(WarnRule node) {
|
Value visitWarnRule(WarnRule node) {
|
||||||
_addExceptionSpan(node.span, () {
|
_addExceptionSpan(node.span, () {
|
||||||
var value = node.expression.accept(this);
|
var value = node.expression.accept(this);
|
||||||
var string = value is SassString ? value.text : value.toCssString();
|
var string = value is SassString
|
||||||
|
? value.text
|
||||||
|
: _toCss(value, node.expression.span);
|
||||||
stderr.writeln("WARNING: $string");
|
stderr.writeln("WARNING: $string");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -932,8 +935,8 @@ class _PerformVisitor
|
|||||||
case BinaryOperator.dividedBy:
|
case BinaryOperator.dividedBy:
|
||||||
var result = left.dividedBy(right);
|
var result = left.dividedBy(right);
|
||||||
if (node.allowsSlash && left is SassNumber && right is SassNumber) {
|
if (node.allowsSlash && left is SassNumber && right is SassNumber) {
|
||||||
var leftSlash = left.asSlash ?? left.toCssString();
|
var leftSlash = left.asSlash ?? _toCss(left, node.left.span);
|
||||||
var rightSlash = right.asSlash ?? right.toCssString();
|
var rightSlash = right.asSlash ?? _toCss(right, node.left.span);
|
||||||
return (result as SassNumber).withSlash("$leftSlash/$rightSlash");
|
return (result as SassNumber).withSlash("$leftSlash/$rightSlash");
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
@ -1106,15 +1109,26 @@ class _PerformVisitor
|
|||||||
"Plain CSS functions don't support keyword arguments.", span);
|
"Plain CSS functions don't support keyword arguments.", span);
|
||||||
}
|
}
|
||||||
|
|
||||||
var argumentValues = arguments.positional
|
var buffer = new StringBuffer("${callable.name}(");
|
||||||
.map((expression) => expression.accept(this))
|
var first = true;
|
||||||
.toList();
|
for (var argument in arguments.positional) {
|
||||||
// TODO: if rest is an arglist that has keywords, error out.
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
buffer.write(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.write(_evaluateToCss(argument));
|
||||||
|
}
|
||||||
|
|
||||||
var rest = arguments.rest?.accept(this);
|
var rest = arguments.rest?.accept(this);
|
||||||
if (rest != null) argumentValues.add(rest);
|
if (rest != null) {
|
||||||
return new SassString("${callable.name}(" +
|
if (!first) buffer.write(", ");
|
||||||
argumentValues.map((argument) => argument.toCssString()).join(', ') +
|
buffer.write(_toCss(rest, arguments.rest.span));
|
||||||
")");
|
}
|
||||||
|
buffer.writeCharCode($rparen);
|
||||||
|
|
||||||
|
return new SassString(buffer.toString());
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1352,10 +1366,11 @@ class _PerformVisitor
|
|||||||
return new SassString(
|
return new SassString(
|
||||||
node.text.contents.map((value) {
|
node.text.contents.map((value) {
|
||||||
if (value is String) return value;
|
if (value is String) return value;
|
||||||
var result = (value as Expression).accept(this);
|
var expression = value as Expression;
|
||||||
|
var result = expression.accept(this);
|
||||||
return result is SassString
|
return result is SassString
|
||||||
? result.text
|
? result.text
|
||||||
: result.toCssString(quote: false);
|
: _toCss(result, expression.span, quote: false);
|
||||||
}).join(),
|
}).join(),
|
||||||
quotes: node.hasQuotes);
|
quotes: node.hasQuotes);
|
||||||
}
|
}
|
||||||
@ -1396,8 +1411,9 @@ class _PerformVisitor
|
|||||||
String _performInterpolation(Interpolation interpolation) {
|
String _performInterpolation(Interpolation interpolation) {
|
||||||
return interpolation.contents.map((value) {
|
return interpolation.contents.map((value) {
|
||||||
if (value is String) return value;
|
if (value is String) return value;
|
||||||
var result = (value as Expression).accept(this);
|
var expression = value as Expression;
|
||||||
return result.toCssString(quote: false);
|
var result = expression.accept(this);
|
||||||
|
return _toCss(result, expression.span, quote: false);
|
||||||
}).join();
|
}).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1405,6 +1421,16 @@ class _PerformVisitor
|
|||||||
CssValue<Value> _performExpression(Expression expression) =>
|
CssValue<Value> _performExpression(Expression expression) =>
|
||||||
new CssValue(expression.accept(this), expression.span);
|
new CssValue(expression.accept(this), expression.span);
|
||||||
|
|
||||||
|
/// Evaluates [expression] and calls `toCssString()` and wraps a
|
||||||
|
/// [SassScriptException] to associate it with [span].
|
||||||
|
String _evaluateToCss(Expression expression, {bool quote: true}) =>
|
||||||
|
_toCss(expression.accept(this), expression.span, quote: quote);
|
||||||
|
|
||||||
|
/// Calls `value.toCssString()` and wraps a [SassScriptException] to associate
|
||||||
|
/// it with [span].
|
||||||
|
String _toCss(Value value, FileSpan span, {bool quote: true}) =>
|
||||||
|
_addExceptionSpan(span, () => value.toCssString(quote: quote));
|
||||||
|
|
||||||
/// Adds [node] as a child of the current parent, then runs [callback] with
|
/// Adds [node] as a child of the current parent, then runs [callback] with
|
||||||
/// [node] as the current parent.
|
/// [node] as the current parent.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user