Skip to content

Commit 73ff9a9

Browse files
authored
Don't generate extra */s for trailing whitespace in Sass (#2383)
Closes #2381
1 parent 164224f commit 73ff9a9

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.79.6
2+
3+
* Fix a bug where Sass would add an extra `*/` after loud comments with
4+
whitespace after an explicit `*/` in the indented syntax.
5+
6+
* **Potentially breaking bug fix:** Adding text after an explicit `*/` in the
7+
indented syntax is now an error, rather than silently generating invalid CSS.
8+
19
## 1.79.5
210

311
* Changes to how `selector.unify()` and `@extend` combine selectors:

lib/src/parse/parser.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,14 +719,6 @@ class Parser {
719719

720720
throwWithTrace(map.mapException(error), error, stackTrace);
721721
}
722-
} on SourceSpanFormatException catch (error, stackTrace) {
723-
var span = error.span as FileSpan;
724-
if (startsWithIgnoreCase(error.message, "expected")) {
725-
span = _adjustExceptionSpan(span);
726-
}
727-
728-
throwWithTrace(
729-
SassFormatException(error.message, span), error, stackTrace);
730722
} on MultiSourceSpanFormatException catch (error, stackTrace) {
731723
var span = error.span as FileSpan;
732724
var secondarySpans = error.secondarySpans.cast<FileSpan, String>();
@@ -743,6 +735,14 @@ class Parser {
743735
error.message, span, error.primaryLabel, secondarySpans),
744736
error,
745737
stackTrace);
738+
} on SourceSpanFormatException catch (error, stackTrace) {
739+
var span = error.span as FileSpan;
740+
if (startsWithIgnoreCase(error.message, "expected")) {
741+
span = _adjustExceptionSpan(span);
742+
}
743+
744+
throwWithTrace(
745+
SassFormatException(error.message, span), error, stackTrace);
746746
}
747747
}
748748

lib/src/parse/sass.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:charcode/charcode.dart';
66
import 'package:string_scanner/string_scanner.dart';
77

88
import '../ast/sass.dart';
9+
import '../exception.dart';
910
import '../interpolation_buffer.dart';
1011
import '../util/character.dart';
1112
import '../value.dart';
@@ -253,6 +254,41 @@ class SassParser extends StylesheetParser {
253254
buffer.writeCharCode(scanner.readChar());
254255
}
255256

257+
case $asterisk:
258+
if (scanner.peekChar(1) == $slash) {
259+
buffer.writeCharCode(scanner.readChar());
260+
buffer.writeCharCode(scanner.readChar());
261+
var span = scanner.spanFrom(start);
262+
whitespace();
263+
264+
// For backwards compatibility, allow additional comments after
265+
// the initial comment is closed.
266+
while (scanner.peekChar().isNewline &&
267+
_peekIndentation() > parentIndentation) {
268+
while (_lookingAtDoubleNewline()) {
269+
_expectNewline();
270+
}
271+
_readIndentation();
272+
whitespace();
273+
}
274+
275+
if (!scanner.isDone && !scanner.peekChar().isNewline) {
276+
var errorStart = scanner.state;
277+
while (!scanner.isDone && !scanner.peekChar().isNewline) {
278+
scanner.readChar();
279+
}
280+
throw MultiSpanSassFormatException(
281+
"Unexpected text after end of comment",
282+
scanner.spanFrom(errorStart),
283+
"extra text",
284+
{span: "comment"});
285+
} else {
286+
return LoudComment(buffer.interpolation(span));
287+
}
288+
} else {
289+
buffer.writeCharCode(scanner.readChar());
290+
}
291+
256292
case _:
257293
buffer.writeCharCode(scanner.readChar());
258294
}

pkg/sass-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.6
2+
3+
* No user-visible changes.
4+
15
## 0.2.5
26

37
* Add support for parsing the `@supports` rule.

pkg/sass-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-parser",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "A PostCSS-compatible wrapper of the official Sass parser",
55
"repository": "sass/sass",
66
"author": "Google Inc.",

pkg/sass_api/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 13.0.1
2+
3+
* Fix a bug where `LoudComment`s parsed from the indented syntax would include
4+
whitespace after the closing `*/`.
5+
16
## 13.0.0
27

38
* The `Interpolation()` constructor now takes an additional `List<FileSpan?>`

pkg/sass_api/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: sass_api
22
# Note: Every time we add a new Sass AST node, we need to bump the *major*
33
# version because it's a breaking change for anyone who's implementing the
44
# visitor interface(s).
5-
version: 13.0.0
5+
version: 13.0.1
66
description: Additional APIs for Dart Sass.
77
homepage: https://github.com/sass/dart-sass
88

99
environment:
1010
sdk: ">=3.0.0 <4.0.0"
1111

1212
dependencies:
13-
sass: 1.79.5
13+
sass: 1.79.6
1414

1515
dev_dependencies:
1616
dartdoc: ^8.0.14

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.79.5
2+
version: 1.79.6-dev
33
description: A Sass implementation in Dart.
44
homepage: https://github.com/sass/dart-sass
55

0 commit comments

Comments
 (0)