Skip to content

Commit

Permalink
Fix interpolation lookahead for calculations (#1500)
Browse files Browse the repository at this point in the history
Closes #1499
  • Loading branch information
nex3 committed Sep 22, 2021
1 parent 0806763 commit 8d5d586
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## 1.42.1

* Fix a bug where Sass variables and function calls in calculations weren't
being resolved correctly if there was a parenthesized interpolation elsewhere
in the file.

## 1.42.0

* `min()` and `max()` expressions are once again parsed as calculations as long
Expand Down
46 changes: 35 additions & 11 deletions lib/src/parse/stylesheet.dart
Expand Up @@ -2908,40 +2908,64 @@ abstract class StylesheetParser extends Parser {
var parens = 0;
var brackets = <int>[];

// Scan manually rather than using [scanner] and saving and restoring its
// state to avoid the overhead of updating line and column information.
var string = scanner.string;
for (var i = scanner.position; i < string.length - 1; i++) {
var next = string.codeUnitAt(i);
var start = scanner.state;
while (!scanner.isDone) {
var next = scanner.peekChar();
switch (next) {
case $backslash:
i++;
scanner.readChar();
scanner.readChar();
break;

case $slash:
if (!scanComment()) scanner.readChar();
break;

case $single_quote:
case $double_quote:
interpolatedString();
break;

case $hash:
if (parens == 0 && string.codeUnitAt(i + 1) == $lbrace) return true;
if (parens == 0 && scanner.peekChar(1) == $lbrace) {
scanner.state = start;
return true;
}
scanner.readChar();
break;

case $lparen:
parens++;
continue;
continue left;

left:
case $lbrace:
case $lbracket:
brackets.add(opposite(next));
// dart-lang/sdk#45357
brackets.add(opposite(next!));
scanner.readChar();
break;

case $rparen:
parens--;
continue;
continue right;

right:
case $rbrace:
case $rbracket:
if (brackets.isEmpty || brackets.removeLast() != next) return false;
if (brackets.isEmpty || brackets.removeLast() != next) {
scanner.state = start;
return false;
}
scanner.readChar();
break;

default:
scanner.readChar();
}
}

scanner.state = start;
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.0.0-beta.13

* No user-visible changes.

## 1.0.0-beta.12

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
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: 1.0.0-beta.12
version: 1.0.0-beta.13
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
sass: 1.42.0
sass: 1.42.1

dependency_overrides:
sass: {path: ../..}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: sass
version: 1.42.0
version: 1.42.1
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 8d5d586

Please sign in to comment.