diff --git a/CHANGELOG.md b/CHANGELOG.md index fa55d0a34..8b9808aae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/src/ast/sass/statement/declaration.dart b/lib/src/ast/sass/statement/declaration.dart index 1f55e22a2..ad7505664 100644 --- a/lib/src/ast/sass/statement/declaration.dart +++ b/lib/src/ast/sass/statement/declaration.dart @@ -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 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(StatementVisitor visitor) => visitor.visitDeclaration(this); diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index e45ad4b97..06ff03a53 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -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) {