diff --git a/lib/src/ast/css/node.dart b/lib/src/ast/css/node.dart index 5362be4d..2b781646 100644 --- a/lib/src/ast/css/node.dart +++ b/lib/src/ast/css/node.dart @@ -55,7 +55,7 @@ abstract class CssNode extends AstNode { _parent = null; } - String toString() => toCss(this, inspect: true); + String toString() => serialize(this, inspect: true); } // NOTE: New at-rule implementations should add themselves to [AtRootRule]'s diff --git a/lib/src/ast/selector.dart b/lib/src/ast/selector.dart index 10948cf3..e2bbe3c0 100644 --- a/lib/src/ast/selector.dart +++ b/lib/src/ast/selector.dart @@ -33,5 +33,5 @@ abstract class Selector { /// Calls the appropriate visit method on [visitor]. T accept(SelectorVisitor visitor); - String toString() => selectorToCss(this, inspect: true); + String toString() => serializeSelector(this, inspect: true); } diff --git a/lib/src/compile.dart b/lib/src/compile.dart index 597adff4..cba1cbdf 100644 --- a/lib/src/compile.dart +++ b/lib/src/compile.dart @@ -48,7 +48,7 @@ String compileString(String source, : new Stylesheet.parseScss(source, url: url, color: color); var cssTree = evaluate(sassTree, color: color, packageResolver: packageResolver, loadPaths: loadPaths); - return toCss(cssTree, + return serialize(cssTree, style: style, useSpaces: useSpaces, indentWidth: indentWidth, diff --git a/lib/src/value.dart b/lib/src/value.dart index d1120f05..d1c54ba6 100644 --- a/lib/src/value.dart +++ b/lib/src/value.dart @@ -301,14 +301,14 @@ abstract class Value { /// isn't valid CSS. /// /// If [quote] is `false`, quoted strings are emitted without quotes. - String toCssString({bool quote: true}) => valueToCss(this, quote: quote); + String toCssString({bool quote: true}) => serializeValue(this, quote: quote); /// Returns a string representation of [this]. /// /// Note that this is equivalent to calling `inspect()` on the value, and thus /// won't reflect the user's output settings. [toCssString] should be used /// instead to convert [this] to CSS. - String toString() => valueToCss(this, inspect: true); + String toString() => serializeValue(this, inspect: true); /// Throws a [SassScriptException] with the given [message]. SassScriptException _exception(String message, [String name]) => diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 7ad6f9c5..e540590b 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -938,7 +938,7 @@ class _EvaluateVisitor var value = node.expression.accept(this); var string = value is SassString ? value.text - : _toCss(value, node.expression.span); + : _serialize(value, node.expression.span); stderr.writeln("WARNING: $string"); }); @@ -1016,8 +1016,8 @@ class _EvaluateVisitor var right = node.right.accept(this); var result = left.dividedBy(right); if (node.allowsSlash && left is SassNumber && right is SassNumber) { - var leftSlash = left.asSlash ?? _toCss(left, node.left.span); - var rightSlash = right.asSlash ?? _toCss(right, node.left.span); + var leftSlash = left.asSlash ?? _serialize(left, node.left.span); + var rightSlash = right.asSlash ?? _serialize(right, node.left.span); return (result as SassNumber).withSlash("$leftSlash/$rightSlash"); } else { return result; @@ -1212,7 +1212,7 @@ class _EvaluateVisitor var rest = arguments.rest?.accept(this); if (rest != null) { if (!first) buffer.write(", "); - buffer.write(_toCss(rest, arguments.rest.span)); + buffer.write(_serialize(rest, arguments.rest.span)); } buffer.writeCharCode($rparen); @@ -1461,7 +1461,7 @@ class _EvaluateVisitor var result = expression.accept(this); return result is SassString ? result.text - : _toCss(result, expression.span, quote: false); + : _serialize(result, expression.span, quote: false); }).join(), quotes: node.hasQuotes); } @@ -1530,7 +1530,7 @@ class _EvaluateVisitor expression.span); } - return _toCss(result, expression.span, quote: false); + return _serialize(result, expression.span, quote: false); }).join(); } @@ -1541,11 +1541,11 @@ class _EvaluateVisitor /// 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); + _serialize(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}) => + String _serialize(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 diff --git a/lib/src/visitor/serialize.dart b/lib/src/visitor/serialize.dart index 44d9d9bf..a36bef87 100644 --- a/lib/src/visitor/serialize.dart +++ b/lib/src/visitor/serialize.dart @@ -28,14 +28,14 @@ import 'interface/value.dart'; /// source structure. Note however that, although this will be valid SCSS, it /// may not be valid CSS. If [inspect] is `false` and [node] contains any values /// that can't be represented in plain CSS, throws a [SassException]. -String toCss(CssNode node, +String serialize(CssNode node, {OutputStyle style, bool inspect: false, bool useSpaces: true, int indentWidth, LineFeed lineFeed}) { indentWidth ??= 2; - var visitor = new _SerializeCssVisitor( + var visitor = new _SerializeVisitor( style: style, inspect: inspect, useSpaces: useSpaces, @@ -57,8 +57,8 @@ String toCss(CssNode node, /// represented in plain CSS, throws a [SassScriptException]. /// /// If [quote] is `false`, quoted strings are emitted without quotes. -String valueToCss(Value value, {bool inspect: false, bool quote: true}) { - var visitor = new _SerializeCssVisitor(inspect: inspect, quote: quote); +String serializeValue(Value value, {bool inspect: false, bool quote: true}) { + var visitor = new _SerializeVisitor(inspect: inspect, quote: quote); value.accept(visitor); return visitor._buffer.toString(); } @@ -69,15 +69,14 @@ String valueToCss(Value value, {bool inspect: false, bool quote: true}) { /// source structure. Note however that, although this will be valid SCSS, it /// may not be valid CSS. If [inspect] is `false` and [selector] can't be /// represented in plain CSS, throws a [SassScriptException]. -String selectorToCss(Selector selector, {bool inspect: false}) { - var visitor = new _SerializeCssVisitor(inspect: inspect); +String serializeSelector(Selector selector, {bool inspect: false}) { + var visitor = new _SerializeVisitor(inspect: inspect); selector.accept(visitor); return visitor._buffer.toString(); } /// A visitor that converts CSS syntax trees to plain strings. -class _SerializeCssVisitor - implements CssVisitor, ValueVisitor, SelectorVisitor { +class _SerializeVisitor implements CssVisitor, ValueVisitor, SelectorVisitor { /// A buffer that contains the CSS produced so far. final _buffer = new StringBuffer(); @@ -100,7 +99,7 @@ class _SerializeCssVisitor /// The characters to use for a line feed. final LineFeed _lineFeed; - _SerializeCssVisitor( + _SerializeVisitor( {OutputStyle style, bool inspect: false, bool quote: true, diff --git a/test/dart_script_test.dart b/test/dart_script_test.dart index 1117d544..0e87dbc7 100644 --- a/test/dart_script_test.dart +++ b/test/dart_script_test.dart @@ -20,7 +20,8 @@ main() { var resolver = new SyncPackageResolver.config( {"fake_package": p.toUri(p.join(d.sandbox, 'subdir'))}); - var css = compile(p.join(d.sandbox, "test.scss"), packageResolver: resolver); + var css = + compile(p.join(d.sandbox, "test.scss"), packageResolver: resolver); expect(css, equals("a {\n b: 3;\n}")); });