Skip to content

Commit e183c4d

Browse files
ben-ebMoOx
authored andcommitted
Fixed: Don't reduce expression containing CSS variables. (MoOx#9)
This fixes cssnano/cssnano#168.
1 parent 9efab98 commit e183c4d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ function reduceCSSCalc(value, decimalPrecision) {
5151

5252
var units = getUnitsInExpression(expression)
5353

54-
// If multiple units let the expression be (i.e. browser calc())
55-
if (units.length > 1) {
54+
// If the expression contains multiple units or CSS variables,
55+
// then let the expression be (i.e. browser calc())
56+
if (units.length > 1 || expression.indexOf("var(") > -1) {
5657
return functionIdentifier + "(" + expression + ")"
5758
}
5859

test/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ test("ignore unrecognized values", function(t) {
102102

103103
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")
104104

105+
t.equal(reduceCSSCalc("calc(100% - var(--my-var))"), "calc(100% - var(--my-var))", "should not try to reduce 100% - var");
105106
t.end()
106107
})
107108

0 commit comments

Comments
 (0)