From 2bfee412e1165b029f894a9b64092916c595f78c Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Mon, 4 May 2015 10:20:35 +0100 Subject: [PATCH] Fixes #517 - turning off color optimizations. With `-properties.colors` / `properties: { colors: false }` switch it's possible to turn off all color optimizations now. --- History.md | 1 + README.md | 1 + lib/selectors/optimizers/simple.js | 3 ++- lib/utils/compatibility.js | 3 +++ test/selectors/optimizers/simple-test.js | 16 ++++++++++++++++ test/utils/compatibility-test.js | 3 +++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index c749921b..9f0ab96c 100644 --- a/History.md +++ b/History.md @@ -9,6 +9,7 @@ * Moves URL rebasing & rewriting into lib/urls. * Fixed issue [#436](https://github.com/jakubpawlowicz/clean-css/issues/436) - refactors URI rewriting. * Fixed issue [#448](https://github.com/jakubpawlowicz/clean-css/issues/448) - rebasing no protocol URIs. +* Fixed issue [#517](https://github.com/jakubpawlowicz/clean-css/issues/517) - turning off color optimizations. * Fixed issue [#542](https://github.com/jakubpawlowicz/clean-css/issues/542) - space after closing brace in IE. [3.2.7 / 2015-05-03](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.6...v3.2.7) diff --git a/README.md b/README.md index 4fddbc6c..e5542067 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,7 @@ Since clean-css 3 a fine grained control is available over with the following options available: * `'[+-]colors.opacity'` - - turn on (+) / off (-) `rgba()` / `hsla()` declarations removal +* `'[+-]properties.colors'` - turn on / off any color optimizations * `'[+-]properties.iePrefixHack'` - turn on / off IE prefix hack removal * `'[+-]properties.ieSuffixHack'` - turn on / off IE suffix hack removal * `'[+-]properties.backgroundSizeMerging'` - turn on / off background-size merging into shorthand diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index 428c9a52..d73a1f29 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -259,7 +259,8 @@ function optimizeBody(properties, options) { value = zeroDegMinifier(name, value); value = unitMinifier(name, value, options.unitsRegexp); } - value = colorMininifier(name, value, options.compatibility); + if (options.compatibility.properties.colors) + value = colorMininifier(name, value, options.compatibility); property[j][0] = value; } diff --git a/lib/utils/compatibility.js b/lib/utils/compatibility.js index 3ac5a5cf..ff1823ab 100644 --- a/lib/utils/compatibility.js +++ b/lib/utils/compatibility.js @@ -7,6 +7,7 @@ var DEFAULTS = { }, properties: { backgroundSizeMerging: false, // background-size to shorthand + colors: true, // any kind of color transformations, like `#ff00ff` to `#f0f` or `#fff` into `red` iePrefixHack: false, // underscore / asterisk prefix hacks on IE ieSuffixHack: false, // \9 suffix hacks on IE merging: true, // merging properties into one @@ -29,6 +30,7 @@ var DEFAULTS = { }, properties: { backgroundSizeMerging: false, + colors: true, iePrefixHack: true, ieSuffixHack: true, merging: false, @@ -51,6 +53,7 @@ var DEFAULTS = { }, properties: { backgroundSizeMerging: false, + colors: true, iePrefixHack: true, ieSuffixHack: true, merging: false, diff --git a/test/selectors/optimizers/simple-test.js b/test/selectors/optimizers/simple-test.js index c6314f48..a9725983 100644 --- a/test/selectors/optimizers/simple-test.js +++ b/test/selectors/optimizers/simple-test.js @@ -260,6 +260,22 @@ vows.describe(SimpleOptimizer) ] }, { compatibility: 'ie8' }) ) + .addBatch( + propertyContext('colors - no optimizations', { + 'long hex into short': [ + 'a{color:#ff00ff}', + [['color', '#ff00ff']] + ], + 'short hex into name': [ + 'a{color:#f00}', + [['color', '#f00']] + ], + 'name into hex': [ + 'a{color:white}', + [['color', 'white']] + ] + }, { compatibility: { properties: { colors: false } } }) + ) .addBatch( propertyContext('@filter', { 'spaces after comma': [ diff --git a/test/utils/compatibility-test.js b/test/utils/compatibility-test.js index b4c87f25..36201bb2 100644 --- a/test/utils/compatibility-test.js +++ b/test/utils/compatibility-test.js @@ -9,6 +9,7 @@ vows.describe(Compatibility) return new Compatibility({}).toOptions(); }, 'gets default options': function(options) { + assert.isTrue(options.properties.colors); assert.isFalse(options.properties.iePrefixHack); assert.isFalse(options.properties.ieSuffixHack); assert.isFalse(options.selectors.adjacentSpace); @@ -55,6 +56,7 @@ vows.describe(Compatibility) return new Compatibility('ie8').toOptions(); }, 'gets template options': function(options) { + assert.isTrue(options.properties.colors); assert.isTrue(options.properties.iePrefixHack); assert.isTrue(options.properties.ieSuffixHack); assert.isFalse(options.selectors.adjacentSpace); @@ -74,6 +76,7 @@ vows.describe(Compatibility) return new Compatibility('ie7').toOptions(); }, 'gets template options': function(options) { + assert.isTrue(options.properties.colors); assert.isTrue(options.properties.iePrefixHack); assert.isTrue(options.properties.ieSuffixHack); assert.isTrue(options.selectors.ie7Hack); -- 2.34.1