diff --git a/CHANGELOG.md b/CHANGELOG.md index 201738ff..f829f18e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ * Produce a better error message for style rules that are missing the closing `}`. +* Produce a better error message for style rules and property declarations + within `@function` rules. + ### Command-Line Interface * Passing a directory on the command line now compiles all Sass source files in diff --git a/lib/src/parse/stylesheet.dart b/lib/src/parse/stylesheet.dart index 388beb88..d6d88def 100644 --- a/lib/src/parse/stylesheet.dart +++ b/lib/src/parse/stylesheet.dart @@ -451,7 +451,7 @@ abstract class StylesheetParser extends Parser { // here should be mirrored there. var start = scanner.state; - scanner.expectChar($at); + scanner.expectChar($at, name: "@-rule"); var name = interpolatedIdentifier(); whitespace(); @@ -536,6 +536,23 @@ abstract class StylesheetParser extends Parser { /// Consumes an at-rule allowed within a function. Statement _functionAtRule() { + if (scanner.peekChar() != $at) { + var position = scanner.position; + Statement statement; + try { + statement = _declarationOrStyleRule(); + } on SourceSpanFormatException catch (_) { + // If we can't parse a valid declaration or style rule, throw a more + // generic error message. + scanner.error("expected @-rule", position: position); + } + + error( + "@function rules may not contain " + "${statement is StyleRule ? "style rules" : "declarations"}.", + statement.span); + } + var start = scanner.state; switch (_plainAtRuleName()) { case "debug": @@ -563,7 +580,7 @@ abstract class StylesheetParser extends Parser { /// Consumes an at-rule's name, with interpolation disallowed. String _plainAtRuleName() { - scanner.expectChar($at); + scanner.expectChar($at, name: "@-rule"); var name = identifier(); whitespace(); return name; diff --git a/pubspec.yaml b/pubspec.yaml index 77d6401b..2bd3bcb6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.17.0-dev +version: 1.17.0 description: A Sass implementation in Dart. author: Dart Team homepage: https://github.com/sass/dart-sass