Skip to content

Commit b7c8f27

Browse files
authored
Don't add extra newlines to StyleRule.selector (#2853)
This was causing a crash when mapping errors in the selector back to the original text. Closes #2848
1 parent 72446f8 commit b7c8f27

5 files changed

Lines changed: 27 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 1.104.1-dev
22

3+
* Fix a bug in which an invalid selector at the end of an indented syntax
4+
stylesheet would cause the parser to crash instead of emitting a useful error
5+
message.
6+
37
### Command Line Interface
48

59
* Many-to-many compilations no longer compile any files that appear in the

lib/src/parse/sass.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ class SassParser(super.contents, {super.url, super.parseSelectors})
4646
var start = scanner.state;
4747

4848
var buffer = InterpolationBuffer();
49-
do {
49+
while (true) {
5050
buffer.addInterpolation(almostAnyValue(omitComments: true));
51-
buffer.writeCharCode($lf);
52-
} while (buffer.trailingString.trimRight().endsWith(',') &&
53-
scanCharIf((char) => char.isNewline));
51+
if (buffer.trailingString.trimRight().endsWith(',') &&
52+
scanCharIf((char) => char.isNewline)) {
53+
buffer.writeCharCode($lf);
54+
} else {
55+
break;
56+
}
57+
}
5458

5559
return buffer.interpolation(spanFrom(start));
5660
}

lib/src/parse/stylesheet.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,17 @@ abstract class StylesheetParser(
540540
buffer.addInterpolation(interpolation);
541541
interpolation = buffer.interpolation(spanFrom(start));
542542
}
543-
if (interpolation.contents.isEmpty) scanner.error('expected "}".');
543+
if (interpolation.contents.isEmpty) {
544+
var unknown = _interpolatedDeclarationValue(
545+
allowEmpty: true,
546+
allowOpenBrace: false,
547+
);
548+
if (unknown.contents.isEmpty) {
549+
scanner.error('expected end of rule.');
550+
} else {
551+
error('unrecognized syntax', unknown.span);
552+
}
553+
}
544554

545555
return _withStyleRuleChildren(
546556
interpolation,

pkg/sass-parser/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.4.55-dev
22

3-
* No user-visible changes.
3+
* Omit an extra newline that was being added to the end of `Rule.selector` in
4+
the indented syntax.
45

56
## 0.4.54
67

pkg/sass_api/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 17.10.1-dev
22

3-
* No user-visible changes.
3+
* Omit an extra newline that was being added to the end of `StyleRule.selector`
4+
in the indented syntax.
45

56
## 17.10.0
67

0 commit comments

Comments
 (0)