Skip to content

Commit

Permalink
Don't generate extra */s for trailing whitespace in Sass (#2383)
Browse files Browse the repository at this point in the history
Closes #2381
  • Loading branch information
nex3 authored Oct 12, 2024
1 parent 164224f commit 73ff9a9
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 12 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 fix:** 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
36 changes: 36 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 @@ -253,6 +254,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.isDone && !scanner.peekChar().isNewline) {
var errorStart = scanner.state;
while (!scanner.isDone && !scanner.peekChar().isNewline) {
scanner.readChar();
}
throw 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
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.6

* No user-visible changes.

## 0.2.5

* Add support for parsing the `@supports` rule.
Expand Down
2 changes: 1 addition & 1 deletion pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-parser",
"version": "0.2.5",
"version": "0.2.6",
"description": "A PostCSS-compatible wrapper of the official Sass parser",
"repository": "sass/sass",
"author": "Google Inc.",
Expand Down
5 changes: 5 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 13.0.1

* Fix a bug where `LoudComment`s parsed from the indented syntax would include
whitespace after the closing `*/`.

## 13.0.0

* The `Interpolation()` constructor now takes an additional `List<FileSpan?>`
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 13.0.0
version: 13.0.1
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
sass: 1.79.5
sass: 1.79.6

dev_dependencies:
dartdoc: ^8.0.14
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 73ff9a9

Please sign in to comment.