Fixes #376 - compat option to disable 0[unit] -> 0 minifying.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 5 Mar 2015 19:38:38 +0000 (19:38 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 5 Mar 2015 19:54:00 +0000 (19:54 +0000)
It turns out unit removal messes up with transforms in IE10-12.

History.md
README.md
lib/selectors/optimizers/simple.js
lib/utils/compatibility.js
test/selectors/optimizers/simple-test.js
test/utils/compatibility-test.js

index ec4ce37..d730dd0 100644 (file)
@@ -1,6 +1,7 @@
 [3.2.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.1...HEAD)
 ==================
 
+* Fixed issue [#376](https://github.com/jakubpawlowicz/clean-css/issues/376) - option to disable 0[unit] -> 0.
 * Fixed issue [#396](https://github.com/jakubpawlowicz/clean-css/issues/396) - better input source maps tracking.
 * Fixed issue [#480](https://github.com/jakubpawlowicz/clean-css/issues/480) - extracting upcase property names.
 
index ae5618e..920fd7c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -310,6 +310,7 @@ with the following options available:
 * `'[+-]properties.backgroundSizeMerging'` - turn on / off background-size merging into shorthand
 * `'[+-]properties.merging'` - turn on / off property merging based on understandability
 * `'[+-]properties.spaceAfterClosingBrace'` - turn on / off removing space after closing brace - `url() no-repeat` into `url()no-repeat`
+* `'[+-]properties.zeroUnits'` - turn on / off units removal after a `0` value
 * `'[+-]selectors.adjacentSpace'` - turn on / off extra space before `nav` element
 * `'[+-]selectors.ie7Hack'` - turn on / off IE7 selector hack removal (`*+html...`)
 * `'[+-]units.rem'` - turn on / off treating `rem` as a proper unit
index e822be6..bd0361f 100644 (file)
@@ -221,8 +221,10 @@ function reduce(body, options) {
 
     value = precisionMinifier(property, value, options.precision);
     value = zeroMinifier(property, value);
-    value = zeroDegMinifier(property, value);
-    value = unitMinifier(property, value, options.unitsRegexp);
+    if (options.compatibility.properties.zeroUnits) {
+      value = zeroDegMinifier(property, value);
+      value = unitMinifier(property, value, options.unitsRegexp);
+    }
     value = multipleZerosMinifier(property, value);
     value = colorMininifier(property, value, options.compatibility);
 
index 70c3874..3d24301 100644 (file)
@@ -10,7 +10,8 @@ var DEFAULTS = {
       iePrefixHack: false, // underscore / asterisk prefix hacks on IE
       ieSuffixHack: false, // \9 suffix hacks on IE
       merging: true, // merging properties into one
-      spaceAfterClosingBrace: false // 'url() no-repeat' to 'url()no-repeat'
+      spaceAfterClosingBrace: false, // 'url() no-repeat' to 'url()no-repeat'
+      zeroUnits: true // 0[unit] -> 0
     },
     selectors: {
       adjacentSpace: false, // div+ nav Android stock browser hack
@@ -30,7 +31,8 @@ var DEFAULTS = {
       iePrefixHack: true,
       ieSuffixHack: true,
       merging: false,
-      spaceAfterClosingBrace: true
+      spaceAfterClosingBrace: true,
+      zeroUnits: true
     },
     selectors: {
       adjacentSpace: false,
@@ -50,7 +52,8 @@ var DEFAULTS = {
       iePrefixHack: true,
       ieSuffixHack: true,
       merging: false,
-      spaceAfterClosingBrace: true
+      spaceAfterClosingBrace: true,
+      zeroUnits: true
     },
     selectors: {
       adjacentSpace: false,
index e6122ef..268d378 100644 (file)
@@ -495,6 +495,34 @@ vows.describe(SimpleOptimizer)
       ]
     })
   )
+  .addBatch(
+    propertyContext('zeros with disabled zeroUnits', {
+      '10.0em': [
+        'a{margin:10.0em}',
+        ['margin:10em']
+      ],
+      '0px': [
+        'a{margin:0px}',
+        ['margin:0px']
+      ],
+      '0px 0px': [
+        'a{margin:0px 0px}',
+        ['margin:0px 0px']
+      ],
+      '0deg': [
+        'div{transform:rotate(0deg) skew(0deg)}',
+        ['transform:rotate(0deg) skew(0deg)']
+      ],
+      '0%': [
+        'a{height:0%}',
+        ['height:0%']
+      ],
+      '10%': [
+        'a{width:10%}',
+        ['width:10%']
+      ]
+    }, { compatibility: { properties: { zeroUnits: false } } })
+  )
   .addBatch(
     propertyContext('comments', {
       'comment': [
index cbf7b8c..5d32c40 100644 (file)
@@ -35,6 +35,7 @@ vows.describe(Compatibility)
         assert.isFalse(options.properties.backgroundSizeMerging);
         assert.isTrue(options.properties.merging);
         assert.isFalse(options.properties.spaceAfterClosingBrace);
+        assert.isTrue(options.properties.zeroUnits);
         assert.isFalse(options.units.rem);
         assert.isTrue(options.colors.opacity);
         assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right)/);
@@ -52,6 +53,7 @@ vows.describe(Compatibility)
         assert.isFalse(options.properties.backgroundSizeMerging);
         assert.isFalse(options.properties.merging);
         assert.isTrue(options.properties.spaceAfterClosingBrace);
+        assert.isTrue(options.properties.zeroUnits);
         assert.isFalse(options.units.rem);
         assert.isFalse(options.colors.opacity);
         assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not)/);
@@ -67,6 +69,7 @@ vows.describe(Compatibility)
         assert.isFalse(options.properties.backgroundSizeMerging);
         assert.isFalse(options.properties.merging);
         assert.isTrue(options.properties.spaceAfterClosingBrace);
+        assert.isTrue(options.properties.zeroUnits);
         assert.isFalse(options.units.rem);
         assert.isFalse(options.colors.opacity);
         assert.deepEqual(options.selectors.special, /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:focus|:before|:after|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not)/);