Fixes #521 - unit optimizations inside `calc()`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 14 Apr 2015 20:39:38 +0000 (21:39 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 14 Apr 2015 20:39:38 +0000 (21:39 +0100)
It's used as a hack so we should not optimize such expressions.

History.md
lib/selectors/optimizers/simple.js
test/selectors/optimizers/simple-test.js

index ef06fad..cec96cc 100644 (file)
@@ -17,6 +17,7 @@
 * Fixed issue [#500](https://github.com/jakubpawlowicz/clean-css/issues/500) - merging duplicate adjacent properties.
 * Fixed issue [#507](https://github.com/jakubpawlowicz/clean-css/issues/507) - merging longhands into many shorthands.
 * Fixed issue [#508](https://github.com/jakubpawlowicz/clean-css/issues/508) - removing duplicate media queries.
+* Fixed issue [#521](https://github.com/jakubpawlowicz/clean-css/issues/521) - unit optimizations inside `calc()`.
 * Fixed issue [#526](https://github.com/jakubpawlowicz/clean-css/issues/526) - shorthand overriding into a function.
 
 [3.1.9 / 2015-04-04](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.8...v3.1.9)
index 66fabb9..f4f47bb 100644 (file)
@@ -100,6 +100,9 @@ function precisionMinifier(_, value, precisionOptions) {
 }
 
 function unitMinifier(_, value, unitsRegexp) {
+  if (/^(?:\-moz\-calc|\-webkit\-calc|calc)\(/.test(value))
+    return value;
+
   return value.replace(unitsRegexp, '$1' + '0');
 }
 
index 61d6b03..5bc0fc6 100644 (file)
@@ -429,6 +429,10 @@ vows.describe(SimpleOptimizer)
       'mixed vales': [
         'a{padding:10px 0em 30% 0rem}',
         [['padding', '10px', '0', '30%', '0']]
+      ],
+      'inside calc': [
+        'a{font-size:calc(100% + 0px)}',
+        [['font-size', 'calc(100% + 0px)']]
       ]
     })
   )