Skip to content

Commit

Permalink
Return an error when using a custom property in a propset instead of …
Browse files Browse the repository at this point in the history
…crashing (#1874)

Fixes: #1857
See: sass/sass-spec#1873
  • Loading branch information
Goodwine authored Jan 24, 2023
1 parent b98fa4f commit 0248608
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Produce a better error message for a number with a leading `+` or `-`, a
decimal point, but no digits.

* Produce a better error message for a nested property whose name starts with
`--`.

## 1.57.1

* No user-visible changes.
Expand Down
15 changes: 2 additions & 13 deletions lib/src/ast/sass/statement/declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,14 @@ class Declaration extends ParentStatement {
bool get isCustomProperty => name.initialPlain.startsWith('--');

/// Creates a declaration with no children.
Declaration(this.name, this.value, this.span) : super(null) {
if (isCustomProperty && value is! StringExpression) {
throw ArgumentError(
'Declarations whose names begin with "--" must have StringExpression '
'values (was `$value` of type ${value.runtimeType}).');
}
}
Declaration(this.name, this.value, this.span) : super(null);

/// Creates a declaration with children.
///
/// For these declarations, a value is optional.
Declaration.nested(this.name, Iterable<Statement> children, this.span,
{this.value})
: super(List.unmodifiable(children)) {
if (isCustomProperty && value is! StringExpression) {
throw ArgumentError(
'Declarations whose names begin with "--" may not be nested.');
}
}
: super(List.unmodifiable(children));

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

Expand Down
5 changes: 5 additions & 0 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,11 @@ class _EvaluateVisitor
throw _exception(
"Declarations may only be used within style rules.", node.span);
}
if (_declarationName != null && node.isCustomProperty) {
throw _exception(
'Declarations whose names begin with "--" may not be nested.',
node.span);
}

var name = _interpolationToValue(node.name, warnForColor: true);
if (_declarationName != null) {
Expand Down

0 comments on commit 0248608

Please sign in to comment.