Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the string representations of the Sass AST #1682

Merged
merged 2 commits into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/ast/sass/argument_declaration.dart
Expand Up @@ -161,7 +161,7 @@ class ArgumentDeclaration implements SassNode {
}

String toString() => [
for (var arg in arguments) arg.toString(),
if (restArgument != null) '$restArgument...'
for (var arg in arguments) '\$$arg',
if (restArgument != null) '\$$restArgument...'
].join(', ');
}
2 changes: 1 addition & 1 deletion lib/src/ast/sass/argument_invocation.dart
Expand Up @@ -48,7 +48,7 @@ class ArgumentInvocation implements SassNode {
String toString() {
var components = [
...positional,
for (var name in named.keys) "$name: ${named[name]}",
for (var name in named.keys) "\$$name: ${named[name]}",
if (rest != null) "$rest...",
if (keywordRest != null) "$keywordRest..."
];
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ast/sass/expression/list.dart
Expand Up @@ -53,8 +53,8 @@ class ListExpression implements Expression {
if (expression.contents.length < 2) return false;
if (expression.hasBrackets) return false;
return separator == ListSeparator.comma
? separator == ListSeparator.comma
: separator != ListSeparator.undecided;
? expression.separator == ListSeparator.comma
: expression.separator != ListSeparator.undecided;
}

if (separator != ListSeparator.space) return false;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/ast/sass/import/static.dart
Expand Up @@ -3,7 +3,6 @@
// https://opensource.org/licenses/MIT.

import 'package:meta/meta.dart';
import 'package:charcode/charcode.dart';
import 'package:source_span/source_span.dart';

import '../import.dart';
Expand Down Expand Up @@ -36,7 +35,6 @@ class StaticImport implements Import {
var buffer = StringBuffer(url);
if (supports != null) buffer.write(" supports($supports)");
if (media != null) buffer.write(" $media");
buffer.writeCharCode($semicolon);
return buffer.toString();
}
}
17 changes: 17 additions & 0 deletions lib/src/ast/sass/statement/declaration.dart
Expand Up @@ -2,6 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:charcode/charcode.dart';
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

Expand Down Expand Up @@ -62,4 +63,20 @@ class Declaration extends ParentStatement {
}

T accept<T>(StatementVisitor<T> visitor) => visitor.visitDeclaration(this);

String toString() {
var buffer = StringBuffer();
buffer.write(name);
buffer.writeCharCode($colon);

if (value != null) {
if (!isCustomProperty) {
buffer.writeCharCode($space);
}
buffer.write("$value");
}

var children = this.children;
return children == null ? "$buffer;" : "$buffer {${children.join(" ")}}";
}
}
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/extend_rule.dart
Expand Up @@ -32,5 +32,5 @@ class ExtendRule implements Statement {

T accept<T>(StatementVisitor<T> visitor) => visitor.visitExtendRule(this);

String toString() => "@extend $selector";
String toString() => "@extend $selector${isOptional ? ' !optional' : ''};";
}
2 changes: 1 addition & 1 deletion lib/src/ast/sass/statement/if_rule.dart
Expand Up @@ -44,7 +44,7 @@ class IfRule implements Statement {
String toString() {
var result = clauses
.mapIndexed((index, clause) =>
"@${index == 0 ? 'if' : 'else if'} {${clause.children.join(' ')}}")
"@${index == 0 ? 'if' : 'else if'} ${clause.expression} {${clause.children.join(' ')}}")
.join(' ');

var lastClause = this.lastClause;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/ast/sass/statement/variable_declaration.dart
Expand Up @@ -90,9 +90,9 @@ class VariableDeclaration implements Statement, SassDeclaration {
visitor.visitVariableDeclaration(this);

String toString() {
var buffer = StringBuffer("\$");
var buffer = StringBuffer();
if (namespace != null) buffer.write("$namespace.");
buffer.write("$name: $expression;");
buffer.write("\$$name: $expression;");
return buffer.toString();
}
}