Skip to content

Commit

Permalink
Allow adjacent forward slashes in plain CSS expressions (#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Mar 12, 2024
1 parent fa4d909 commit 6e2d637
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.72.0

* Support adjacent `/`s without whitespace in between when parsing plain CSS
expressions.

* Allow the Node.js `pkg:` importer to load Sass stylesheets for `package.json`
`exports` field entries without extensions.

Expand Down
4 changes: 3 additions & 1 deletion lib/src/parse/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class CssParser extends ScssParser {

CssParser(super.contents, {super.url, super.logger});

void silentComment() {
bool silentComment() {
if (inExpression) return false;

var start = scanner.state;
super.silentComment();
error("Silent comments aren't allowed in plain CSS.",
Expand Down
8 changes: 5 additions & 3 deletions lib/src/parse/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class Parser {

switch (scanner.peekChar(1)) {
case $slash:
silentComment();
return true;
return silentComment();
case $asterisk:
loudComment();
return true;
Expand All @@ -135,12 +134,15 @@ class Parser {
}

/// Consumes and ignores a silent (Sass-style) comment.
///
/// Returns whether the comment was consumed.
@protected
void silentComment() {
bool silentComment() {
scanner.expect("//");
while (!scanner.isDone && !scanner.peekChar().isNewline) {
scanner.readChar();
}
return true;
}

/// Consumes and ignores a loud (CSS-style) comment.
Expand Down
10 changes: 10 additions & 0 deletions lib/src/parse/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ abstract class StylesheetParser extends Parser {
/// Whether the parser is currently within a parenthesized expression.
var _inParentheses = false;

/// Whether the parser is currently within an expression.
@protected
bool get inExpression => _inExpression;
var _inExpression = false;

/// A map from all variable names that are assigned with `!global` in the
/// current stylesheet to the nodes where they're defined.
///
Expand Down Expand Up @@ -1686,7 +1691,9 @@ abstract class StylesheetParser extends Parser {
}

var start = scanner.state;
var wasInExpression = _inExpression;
var wasInParentheses = _inParentheses;
_inExpression = true;

// We use the convention below of referring to nullable variables that are
// shared across anonymous functions in this method with a trailing
Expand Down Expand Up @@ -2039,11 +2046,13 @@ abstract class StylesheetParser extends Parser {
_inParentheses = wasInParentheses;
var singleExpression = singleExpression_;
if (singleExpression != null) commaExpressions.add(singleExpression);
_inExpression = wasInExpression;
return ListExpression(commaExpressions, ListSeparator.comma,
scanner.spanFrom(beforeBracket ?? start),
brackets: bracketList);
} else if (bracketList && spaceExpressions != null) {
resolveOperations();
_inExpression = wasInExpression;
return ListExpression(spaceExpressions..add(singleExpression_!),
ListSeparator.space, scanner.spanFrom(beforeBracket!),
brackets: true);
Expand All @@ -2054,6 +2063,7 @@ abstract class StylesheetParser extends Parser {
ListSeparator.undecided, scanner.spanFrom(beforeBracket!),
brackets: true);
}
_inExpression = wasInExpression;
return singleExpression_!;
}
}
Expand Down

0 comments on commit 6e2d637

Please sign in to comment.