Skip to content

Commit dfca7c5

Browse files
committed
fix: do not consume number token if expression ends with '.'
Fix #132 `\b` also matches '.' so the regex for the number expression would match `41` in `41.7rpx`. Then `UNKNOWN_DIMENSION` would match `.7rpx` and create the invalid sequence `NumberExpression`, `UnknownDimension`.
1 parent 1f2513d commit dfca7c5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/__tests__/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,15 @@ test(
890890
testValue('calc(1px + 2unknown)', 'calc(1px + 2unknown)')
891891
);
892892

893+
test('decimal unknown units', async () => {
894+
const result = await postcss(reduceCalc()).process(
895+
'p{width: calc(120rpx - 41.7rpx)}',
896+
postcssOpts
897+
);
898+
const warnings = result.warnings();
899+
assert.is(warnings.length, 0);
900+
});
901+
893902
test(
894903
'error with parsing',
895904
testThrows(

src/parser.jison

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dpcm\b return 'RES';
4545
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)dppx\b return 'RES';
4646
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)\% return 'PERCENTAGE';
47-
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)\b return 'NUMBER';
47+
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)(?!".")\b return 'NUMBER';
4848

4949
(([0-9]+("."[0-9]+)?|"."[0-9]+)(e(\+|-)[0-9]+)?)-?([a-zA-Z_]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))([a-zA-Z0-9_-]|[\240-\377]|(\\[0-9a-fA-F]{1,6}(\r\n|[ \t\r\n\f])?|\\[^\r\n\f0-9a-fA-F]))*\b return 'UNKNOWN_DIMENSION';
5050

0 commit comments

Comments
 (0)