Skip to content

Commit 35d355f

Browse files
committed
Allow values such as 10.px without throwing.
1 parent 8176c07 commit 35d355f

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

parser.jison

+27-27
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@
99
"+" return 'ADD';
1010
"-" return 'SUB';
1111

12-
([0-9]+("."[0-9]+)?|"."[0-9]+)px\b return 'LENGTH';
13-
([0-9]+("."[0-9]+)?|"."[0-9]+)cm\b return 'LENGTH';
14-
([0-9]+("."[0-9]+)?|"."[0-9]+)mm\b return 'LENGTH';
15-
([0-9]+("."[0-9]+)?|"."[0-9]+)in\b return 'LENGTH';
16-
([0-9]+("."[0-9]+)?|"."[0-9]+)pt\b return 'LENGTH';
17-
([0-9]+("."[0-9]+)?|"."[0-9]+)pc\b return 'LENGTH';
18-
([0-9]+("."[0-9]+)?|"."[0-9]+)deg\b return 'ANGLE';
19-
([0-9]+("."[0-9]+)?|"."[0-9]+)grad\b return 'ANGLE';
20-
([0-9]+("."[0-9]+)?|"."[0-9]+)rad\b return 'ANGLE';
21-
([0-9]+("."[0-9]+)?|"."[0-9]+)turn\b return 'ANGLE';
22-
([0-9]+("."[0-9]+)?|"."[0-9]+)s\b return 'TIME';
23-
([0-9]+("."[0-9]+)?|"."[0-9]+)ms\b return 'TIME';
24-
([0-9]+("."[0-9]+)?|"."[0-9]+)Hz\b return 'FREQ';
25-
([0-9]+("."[0-9]+)?|"."[0-9]+)kHz\b return 'FREQ';
26-
([0-9]+("."[0-9]+)?|"."[0-9]+)dpi\b return 'RES';
27-
([0-9]+("."[0-9]+)?|"."[0-9]+)dpcm\b return 'RES';
28-
([0-9]+("."[0-9]+)?|"."[0-9]+)dppx\b return 'RES';
29-
([0-9]+("."[0-9]+)?|"."[0-9]+)em\b return 'EMS';
30-
([0-9]+("."[0-9]+)?|"."[0-9]+)ex\b return 'EXS';
31-
([0-9]+("."[0-9]+)?|"."[0-9]+)ch\b return 'CHS';
32-
([0-9]+("."[0-9]+)?|"."[0-9]+)rem\b return 'REMS';
33-
([0-9]+("."[0-9]+)?|"."[0-9]+)vw\b return 'VWS';
34-
([0-9]+("."[0-9]+)?|"."[0-9]+)vh\b return 'VHS';
35-
([0-9]+("."[0-9]+)?|"."[0-9]+)vmin\b return 'VMINS';
36-
([0-9]+("."[0-9]+)?|"."[0-9]+)vmax\b return 'VMAXS';
37-
([0-9]+("."[0-9]+)?|"."[0-9]+)\% return 'PERCENTAGE';
38-
([0-9]+("."[0-9]+)?|"."[0-9]+)\b return 'NUMBER';
12+
([0-9]+("."[0-9]*)?|"."[0-9]+)px\b return 'LENGTH';
13+
([0-9]+("."[0-9]*)?|"."[0-9]+)cm\b return 'LENGTH';
14+
([0-9]+("."[0-9]*)?|"."[0-9]+)mm\b return 'LENGTH';
15+
([0-9]+("."[0-9]*)?|"."[0-9]+)in\b return 'LENGTH';
16+
([0-9]+("."[0-9]*)?|"."[0-9]+)pt\b return 'LENGTH';
17+
([0-9]+("."[0-9]*)?|"."[0-9]+)pc\b return 'LENGTH';
18+
([0-9]+("."[0-9]*)?|"."[0-9]+)deg\b return 'ANGLE';
19+
([0-9]+("."[0-9]*)?|"."[0-9]+)grad\b return 'ANGLE';
20+
([0-9]+("."[0-9]*)?|"."[0-9]+)rad\b return 'ANGLE';
21+
([0-9]+("."[0-9]*)?|"."[0-9]+)turn\b return 'ANGLE';
22+
([0-9]+("."[0-9]*)?|"."[0-9]+)s\b return 'TIME';
23+
([0-9]+("."[0-9]*)?|"."[0-9]+)ms\b return 'TIME';
24+
([0-9]+("."[0-9]*)?|"."[0-9]+)Hz\b return 'FREQ';
25+
([0-9]+("."[0-9]*)?|"."[0-9]+)kHz\b return 'FREQ';
26+
([0-9]+("."[0-9]*)?|"."[0-9]+)dpi\b return 'RES';
27+
([0-9]+("."[0-9]*)?|"."[0-9]+)dpcm\b return 'RES';
28+
([0-9]+("."[0-9]*)?|"."[0-9]+)dppx\b return 'RES';
29+
([0-9]+("."[0-9]*)?|"."[0-9]+)em\b return 'EMS';
30+
([0-9]+("."[0-9]*)?|"."[0-9]+)ex\b return 'EXS';
31+
([0-9]+("."[0-9]*)?|"."[0-9]+)ch\b return 'CHS';
32+
([0-9]+("."[0-9]*)?|"."[0-9]+)rem\b return 'REMS';
33+
([0-9]+("."[0-9]*)?|"."[0-9]+)vw\b return 'VWS';
34+
([0-9]+("."[0-9]*)?|"."[0-9]+)vh\b return 'VHS';
35+
([0-9]+("."[0-9]*)?|"."[0-9]+)vmin\b return 'VMINS';
36+
([0-9]+("."[0-9]*)?|"."[0-9]+)vmax\b return 'VMAXS';
37+
([0-9]+("."[0-9]*)?|"."[0-9]+)\% return 'PERCENTAGE';
38+
([0-9]+("."[0-9]*)?|"."[0-9]+)\b return 'NUMBER';
3939

4040
(calc) return 'NESTED_CALC';
4141
(var\(.*\)) return 'CSS_VAR';

src/__tests__/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,21 @@ test(
6363
'calc(100% - 10px)'
6464
)
6565

66+
test(
67+
'should handle fractions',
68+
testFixture,
69+
'calc(10.px + .0px)',
70+
'10px'
71+
)
72+
6673
test(
6774
'should ignore value surrounding calc function (1)',
6875
testFixture,
6976
'a calc(1px + 1px)',
7077
'a 2px'
7178
)
7279

80+
7381
test(
7482
'should ignore value surrounding calc function (2)',
7583
testFixture,

0 commit comments

Comments
 (0)