Skip to content

Commit

Permalink
Don't generate extra */s for trailing whitespace in Sass
Browse files Browse the repository at this point in the history
Closes #2381
  • Loading branch information
nex3 committed Oct 11, 2024
1 parent 7290399 commit 23690dc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.79.6

* Fix a bug where Sass would add an extra `*/` after loud comments with
whitespace after an explicit `*/` in the indented syntax.

* **Potentially breaking bug fxi:** Adding text after an explicit `*/` in the
indented syntax is now an error, rather than silently generating invalid CSS.

## 1.79.5

* Changes to how `selector.unify()` and `@extend` combine selectors:
Expand Down
16 changes: 8 additions & 8 deletions lib/src/parse/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -719,14 +719,6 @@ class Parser {

throwWithTrace(map.mapException(error), error, stackTrace);
}
} on SourceSpanFormatException catch (error, stackTrace) {
var span = error.span as FileSpan;
if (startsWithIgnoreCase(error.message, "expected")) {
span = _adjustExceptionSpan(span);
}

throwWithTrace(
SassFormatException(error.message, span), error, stackTrace);
} on MultiSourceSpanFormatException catch (error, stackTrace) {
var span = error.span as FileSpan;
var secondarySpans = error.secondarySpans.cast<FileSpan, String>();
Expand All @@ -743,6 +735,14 @@ class Parser {
error.message, span, error.primaryLabel, secondarySpans),
error,
stackTrace);
} on SourceSpanFormatException catch (error, stackTrace) {
var span = error.span as FileSpan;
if (startsWithIgnoreCase(error.message, "expected")) {
span = _adjustExceptionSpan(span);
}

throwWithTrace(
SassFormatException(error.message, span), error, stackTrace);
}
}

Expand Down
37 changes: 37 additions & 0 deletions lib/src/parse/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:charcode/charcode.dart';
import 'package:string_scanner/string_scanner.dart';

import '../ast/sass.dart';
import '../exception.dart';
import '../interpolation_buffer.dart';
import '../util/character.dart';
import '../value.dart';
Expand Down Expand Up @@ -216,6 +217,7 @@ class SassParser extends StylesheetParser {
scanner.expect("/*");

var first = true;
var closed = false;
var buffer = InterpolationBuffer()..write("/*");
var parentIndentation = currentIndentation;
while (true) {
Expand Down Expand Up @@ -253,6 +255,41 @@ class SassParser extends StylesheetParser {
buffer.writeCharCode(scanner.readChar());
}

case $asterisk:
if (scanner.peekChar(1) == $slash) {
buffer.writeCharCode(scanner.readChar());
buffer.writeCharCode(scanner.readChar());
var span = scanner.spanFrom(start);
whitespace();

// For backwards compatibility, allow additional comments after
// the initial comment is closed.
while (scanner.peekChar().isNewline && _peekIndentation() > parentIndentation) {
while (_lookingAtDoubleNewline()) {
_expectNewline();
}
_readIndentation();
whitespace();
}

if (!scanner.peekChar().isNewline) {
var errorStart = scanner.state;
while (!scanner.isDone && !scanner.peekChar().isNewline) {
scanner.readChar();
}
throw new MultiSpanSassFormatException(
"Unexpected text after end of comment",
scanner.spanFrom(errorStart),
"extra text",
{span: "comment"}
);
} else {
return LoudComment(buffer.interpolation(span));
}
} else {
buffer.writeCharCode(scanner.readChar());
}

case _:
buffer.writeCharCode(scanner.readChar());
}
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.79.5
version: 1.79.6-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 23690dc

Please sign in to comment.