File tree 3 files changed +14
-0
lines changed
3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 38
38
([0-9] + ("." [0-9] + )? | "." [0-9] + )\b return ' NUMBER' ;
39
39
40
40
(calc) return ' NESTED_CALC' ;
41
+ (var\( . * \) ) return ' CSS_VAR' ;
41
42
([a-z] + ) return ' PREFIX' ;
42
43
43
44
"(" return ' LPAREN' ;
@@ -68,6 +69,7 @@ expression
68
69
| LPAREN math_expression RPAREN { $$ = $2 ; }
69
70
| NESTED_CALC LPAREN math_expression RPAREN { $$ = $3 ; }
70
71
| SUB PREFIX SUB NESTED_CALC LPAREN math_expression RPAREN { $$ = $6 ; }
72
+ | css_variable { $$ = $1 ; }
71
73
| css_value { $$ = $1 ; }
72
74
| value { $$ = $1 ; }
73
75
;
@@ -77,6 +79,10 @@ expression
77
79
| SUB NUMBER { $$ = { type: ' Value' , value: parseFloat ($2 ) * - 1 }; }
78
80
;
79
81
82
+ css_variable
83
+ : CSS_VAR { $$ = { type: ' CssVariable' , value: $1 }; }
84
+ ;
85
+
80
86
css_value
81
87
: LENGTH { $$ = { type: ' LengthValue' , value: parseFloat ($1 ), unit: / [a-z ] + / .exec ($1 )[0 ] }; }
82
88
| ANGLE { $$ = { type: ' AngleValue' , value: parseFloat ($1 ), unit: / [a-z ] + / .exec ($1 )[0 ] }; }
Original file line number Diff line number Diff line change 84
84
'-webkit-calc(50% - 25px)'
85
85
)
86
86
87
+ test (
88
+ 'should ignore calc with css variables' ,
89
+ testFixture ,
90
+ 'calc(var(--mouseX) * 1px)'
91
+ )
92
+
87
93
test (
88
94
'should reduce calc with newline characters' ,
89
95
testFixture ,
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ function stringify(node, prec) {
35
35
}
36
36
case "Value" :
37
37
return round ( node . value , prec )
38
+ case 'CssVariable' :
39
+ return node . value
38
40
default :
39
41
return round ( node . value , prec ) + node . unit
40
42
}
You can’t perform that action at this time.
0 commit comments