File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed
Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 3838([0-9] + ("." [0-9] + )? | "." [0-9] + )\b return ' NUMBER' ;
3939
4040(calc) return ' NESTED_CALC' ;
41+ (var\( . * \) ) return ' CSS_VAR' ;
4142([a-z] + ) return ' PREFIX' ;
4243
4344"(" return ' LPAREN' ;
@@ -68,6 +69,7 @@ expression
6869 | LPAREN math_expression RPAREN { $$ = $2 ; }
6970 | NESTED_CALC LPAREN math_expression RPAREN { $$ = $3 ; }
7071 | SUB PREFIX SUB NESTED_CALC LPAREN math_expression RPAREN { $$ = $6 ; }
72+ | css_variable { $$ = $1 ; }
7173 | css_value { $$ = $1 ; }
7274 | value { $$ = $1 ; }
7375 ;
@@ -77,6 +79,10 @@ expression
7779 | SUB NUMBER { $$ = { type: ' Value' , value: parseFloat ($2 ) * - 1 }; }
7880 ;
7981
82+ css_variable
83+ : CSS_VAR { $$ = { type: ' CssVariable' , value: $1 }; }
84+ ;
85+
8086 css_value
8187 : LENGTH { $$ = { type: ' LengthValue' , value: parseFloat ($1 ), unit: / [a-z ] + / .exec ($1 )[0 ] }; }
8288 | ANGLE { $$ = { type: ' AngleValue' , value: parseFloat ($1 ), unit: / [a-z ] + / .exec ($1 )[0 ] }; }
Original file line number Diff line number Diff line change 8484 '-webkit-calc(50% - 25px)'
8585)
8686
87+ test (
88+ 'should ignore calc with css variables' ,
89+ testFixture ,
90+ 'calc(var(--mouseX) * 1px)'
91+ )
92+
8793test (
8894 'should reduce calc with newline characters' ,
8995 testFixture ,
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ function stringify(node, prec) {
3535 }
3636 case "Value" :
3737 return round ( node . value , prec )
38+ case 'CssVariable' :
39+ return node . value
3840 default :
3941 return round ( node . value , prec ) + node . unit
4042 }
You can’t perform that action at this time.
0 commit comments