fixed expressions parsing
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 162975f..783393d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.16.1
+
+- Fixed a crash caused by parsing certain calc() expressions and variables names that contain numbers.
+
## 0.16.0
- Removed support for the shadow-piercing comibnators `/deep/` and `>>>`. These
diff --git a/lib/parser.dart b/lib/parser.dart
index fbf291c..d8ba671 100644
--- a/lib/parser.dart
+++ b/lib/parser.dart
@@ -1681,14 +1681,8 @@
}
if (keepParsing && value != null) {
- LiteralTerm unitTerm;
- // Don't process the dimension if MINUS or PLUS is next.
- if (_peek() != TokenKind.MINUS && _peek() != TokenKind.PLUS) {
- unitTerm = processDimension(termToken, value, _makeSpan(start));
- }
- if (unitTerm == null) {
- unitTerm = LiteralTerm(value, value.name, _makeSpan(start));
- }
+ LiteralTerm unitTerm =
+ processDimension(termToken, value, _makeSpan(start));
expressions.add(unitTerm);
value = null;
@@ -2498,12 +2492,13 @@
_next(); // Skip the unit
break;
default:
- if (value != null && t != null) {
- term = (value is Identifier)
- ? LiteralTerm(value, value.name, span)
- : NumberTerm(value, t.text, span);
+ if (value != null) {
+ if (value is Identifier) {
+ term = LiteralTerm(value, value.name, span);
+ } else if (t != null) {
+ term = NumberTerm(value, t.text, span);
+ }
}
- break;
}
return term;
diff --git a/test/compiler_test.dart b/test/compiler_test.dart
index 3e1852a..c9e8375 100644
--- a/test/compiler_test.dart
+++ b/test/compiler_test.dart
@@ -727,6 +727,27 @@
}''');
}
+void testExpressionParsing() {
+ var errors = <Message>[];
+ var input = r'''
+.foobar {
+ border-radius: calc(0 - 1px);
+ border-width: calc(0 + 1px);
+}''';
+ var stylesheet = parseCss(input, errors: errors);
+
+ expect(stylesheet != null, true);
+ expect(errors.isEmpty, true, reason: errors.toString());
+
+ walkTree(stylesheet);
+
+ expect(prettyPrint(stylesheet), r'''
+.foobar {
+ border-radius: calc(0 - 1px);
+ border-width: calc(0 + 1px);
+}''');
+}
+
main() {
test('Classes', testClass);
test('Classes 2', testClass2);
@@ -744,4 +765,5 @@
test('stringEscape', testStringEscape);
test('Parse List<int> as input', testArrayOfChars);
test('Simple Emitter', testEmitter);
+ test('Expression parsing', testExpressionParsing);
}
diff --git a/test/var_test.dart b/test/var_test.dart
index 4d6edf6..d1e689e 100644
--- a/test/var_test.dart
+++ b/test/var_test.dart
@@ -34,10 +34,12 @@
var-c: #00ff00;
var-b: var(c);
var-a: var(b);
+ var-level-1-normal: 1px;
}
.testIt {
color: var(color-foreground);
background: var(color-background);
+ border-radius: var(level-1-normal);
}
''';
@@ -48,10 +50,12 @@
var-c: #0f0;
var-b: var(c);
var-a: var(b);
+ var-level-1-normal: 1px;
}
.testIt {
color: var(color-foreground);
background: var(color-background);
+ border-radius: var(level-1-normal);
}''';
final generatedPolyfill = '''
@@ -60,6 +64,7 @@
.testIt {
color: #00f;
background: #f00;
+ border-radius: 1px;
}''';
compileAndValidate(input, generated);