Produce a better error for invalid function contents (#587)

Closes #584
This commit is contained in:
Natalie Weizenbaum 2019-02-04 13:14:25 -08:00 committed by GitHub
parent a81017275a
commit 7ca989a4f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View File

@ -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 that are missing the closing
`}`. `}`.
* Produce a better error message for style rules and property declarations
within `@function` rules.
### Command-Line Interface ### Command-Line Interface
* Passing a directory on the command line now compiles all Sass source files in * Passing a directory on the command line now compiles all Sass source files in

View File

@ -451,7 +451,7 @@ abstract class StylesheetParser extends Parser {
// here should be mirrored there. // here should be mirrored there.
var start = scanner.state; var start = scanner.state;
scanner.expectChar($at); scanner.expectChar($at, name: "@-rule");
var name = interpolatedIdentifier(); var name = interpolatedIdentifier();
whitespace(); whitespace();
@ -536,6 +536,23 @@ abstract class StylesheetParser extends Parser {
/// Consumes an at-rule allowed within a function. /// Consumes an at-rule allowed within a function.
Statement _functionAtRule() { 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; var start = scanner.state;
switch (_plainAtRuleName()) { switch (_plainAtRuleName()) {
case "debug": case "debug":
@ -563,7 +580,7 @@ abstract class StylesheetParser extends Parser {
/// Consumes an at-rule's name, with interpolation disallowed. /// Consumes an at-rule's name, with interpolation disallowed.
String _plainAtRuleName() { String _plainAtRuleName() {
scanner.expectChar($at); scanner.expectChar($at, name: "@-rule");
var name = identifier(); var name = identifier();
whitespace(); whitespace();
return name; return name;

View File

@ -1,5 +1,5 @@
name: sass name: sass
version: 1.17.0-dev version: 1.17.0
description: A Sass implementation in Dart. description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org> author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass homepage: https://github.com/sass/dart-sass