Skip to content

Commit

Permalink
Produce a better error for invalid function contents (#587)
Browse files Browse the repository at this point in the history
Closes #584
  • Loading branch information
nex3 authored Feb 4, 2019
1 parent a810172 commit 7ca989a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.17.0-dev
version: 1.17.0
description: A Sass implementation in Dart.
author: Dart Team <[email protected]>
homepage: https://github.com/sass/dart-sass
Expand Down

0 comments on commit 7ca989a

Please sign in to comment.