File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,9 @@ function reduceCSSCalc(value, decimalPrecision) {
106
106
* @returns {String }
107
107
*/
108
108
function evaluateNestedExpression ( expression , call ) {
109
+ // Remove the calc part from nested expressions to ensure
110
+ // better browser compatibility
111
+ expression = expression . replace ( / ( (?: \- [ a - z ] + \- ) ? c a l c ) / g, "" )
109
112
var evaluatedPart = ""
110
113
var nonEvaluatedPart = expression
111
114
var matches
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ test("ignore unrecognized values", function(t) {
103
103
t . equal ( reduceCSSCalc ( "calc((4px + 8px) + (--foo) + (10% * 20%))" ) , "calc(12px + (--foo) + 2%)" , "ignore unrecognized part between parenthesis" )
104
104
t . equal ( reduceCSSCalc ( "calc((4px + 8px) + var(--foo) + (10% * 20%))" ) , "calc(12px + var(--foo) + 2%)" , "ignore unrecognized function" )
105
105
106
- t . equal ( reduceCSSCalc ( "calc(calc(4px + 8px) + calc(var(--foo) + 10px) + calc(10% * 20%))" ) , "calc(12px + calc (var(--foo) + 10px) + 2%)" , "ignore unrecognized nested call" )
106
+ t . equal ( reduceCSSCalc ( "calc(calc(4px + 8px) + calc(var(--foo) + 10px) + calc(10% * 20%))" ) , "calc(12px + (var(--foo) + 10px) + 2%)" , "ignore unrecognized nested call" )
107
107
108
108
t . equal ( reduceCSSCalc ( "calc(100% - var(--my-var))" ) , "calc(100% - var(--my-var))" , "should not try to reduce 100% - var" ) ;
109
109
t . end ( )
@@ -127,3 +127,10 @@ test("should handle calc() with values without leading 0", function(t) {
127
127
t . equal ( reduceCSSCalc ( "calc(.1 + .1 + 1.1 + 0.2)" ) , "1.5" , "addition" )
128
128
t . end ( )
129
129
} )
130
+
131
+ test ( "should remove calc from unresolved nested expressions" , function ( t ) {
132
+ t . equal ( reduceCSSCalc ( "-webkit-calc(21vh + -webkit-calc(21vh + 80px * 1/3 + 5px) + -webkit-calc(10vw + 80px * 2/3))" ) , "-webkit-calc(21vh + (21vh + 80px * 1/3 + 5px) + (10vw + 80px * 2/3))" )
133
+ t . equal ( reduceCSSCalc ( "-moz-calc(21vh + -moz-calc(21vh + 80px * 1/3 + 5px) + -moz-calc(10vw + 80px * 2/3))" ) , "-moz-calc(21vh + (21vh + 80px * 1/3 + 5px) + (10vw + 80px * 2/3))" )
134
+ t . equal ( reduceCSSCalc ( "calc(21vh + calc(21vh + 80px * 1/3 + 5px) + calc(10vw + 80px * 2/3))" ) , "calc(21vh + (21vh + 80px * 1/3 + 5px) + (10vw + 80px * 2/3))" )
135
+ t . end ( )
136
+ } )
You can’t perform that action at this time.
0 commit comments