Skip to content

Commit

Permalink
Add support for var() with an empty fallback argument (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Jun 21, 2022
1 parent 8705c06 commit c5e1f0b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 1.52.4
## 1.53.0

* Add support for calling `var()` with an empty second argument, such as
`var(--side, )`.

### JS API

Expand Down
13 changes: 11 additions & 2 deletions lib/src/parse/css.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,26 @@ class CssParser extends ScssParser {
var identifier = interpolatedIdentifier();
var plain = identifier.asPlain!; // CSS doesn't allow non-plain identifiers

var specialFunction = trySpecialFunction(plain.toLowerCase(), start);
var lower = plain.toLowerCase();
var specialFunction = trySpecialFunction(lower, start);
if (specialFunction != null) return specialFunction;

var beforeArguments = scanner.state;
if (!scanner.scanChar($lparen)) return StringExpression(identifier);

var allowEmptySecondArg = lower == 'var';
var arguments = <Expression>[];
if (!scanner.scanChar($rparen)) {
do {
whitespace();
arguments.add(expression(singleEquals: true));
if (allowEmptySecondArg &&
arguments.length == 1 &&
scanner.peekChar() == $rparen) {
arguments.add(StringExpression.plain('', scanner.emptySpan));
break;
}

arguments.add(expressionUntilComma(singleEquals: true));
whitespace();
} while (scanner.scanChar($comma));
scanner.expectChar($rparen);
Expand Down
Loading

0 comments on commit c5e1f0b

Please sign in to comment.