From: Jakub Pawlowicz Date: Thu, 5 Mar 2015 19:38:38 +0000 (+0000) Subject: Fixes #376 - compat option to disable 0[unit] -> 0 minifying. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=997d4d74f4389b12a3af34d925582981defd30a0;p=clean-css.git Fixes #376 - compat option to disable 0[unit] -> 0 minifying. It turns out unit removal messes up with transforms in IE10-12. --- diff --git a/History.md b/History.md index ec4ce370..d730dd06 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/README.md b/README.md index ae5618e9..920fd7c9 100644 --- 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 diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index e822be64..bd0361f8 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -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); diff --git a/lib/utils/compatibility.js b/lib/utils/compatibility.js index 70c38747..3d24301f 100644 --- a/lib/utils/compatibility.js +++ b/lib/utils/compatibility.js @@ -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, diff --git a/test/selectors/optimizers/simple-test.js b/test/selectors/optimizers/simple-test.js index e6122ef4..268d3782 100644 --- a/test/selectors/optimizers/simple-test.js +++ b/test/selectors/optimizers/simple-test.js @@ -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': [ diff --git a/test/utils/compatibility-test.js b/test/utils/compatibility-test.js index cbf7b8c4..5d32c401 100644 --- a/test/utils/compatibility-test.js +++ b/test/utils/compatibility-test.js @@ -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)/);