From: Jakub Pawlowicz Date: Wed, 15 Apr 2015 21:56:22 +0000 (+0100) Subject: Fixes #371 - SVG background hack. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=cddde22e41905ef094a5aa084b1aa97a5d5ed5ad;p=clean-css.git Fixes #371 - SVG background hack. It will work for background-image too, and in general for any combination of two backgrounds where the latter is in the form of `background:...,none;`. --- diff --git a/History.md b/History.md index 1b4fd7ce..8872ed9e 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ * Fixes remote asset rebasing when passing data as a hash. * Improves path resolution inside source maps. * Makes `root` option implicitely default to `process.cwd()`. +* Fixed issue [#371](https://github.com/jakubpawlowicz/clean-css/issues/371) - `background` fallback with `none`. * 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 [#397](https://github.com/jakubpawlowicz/clean-css/issues/397) - support for source map sources. diff --git a/lib/properties/override-compactor.js b/lib/properties/override-compactor.js index 8a7e07df..7799f96c 100644 --- a/lib/properties/override-compactor.js +++ b/lib/properties/override-compactor.js @@ -178,6 +178,14 @@ function isCompactable(property) { return property.name in compactable; } +function noneOverrideHack(left, right) { + return !left.multiplex && + (left.name == 'background' || left.name == 'background-image') && + right.multiplex && + (right.name == 'background' || right.name == 'background-image') && + right.value[right.value.length - 1][0] == 'none'; +} + function compactOverrides(properties, compatibility, validator) { var mayOverride, right, left, component; var i, j, k; @@ -206,6 +214,9 @@ function compactOverrides(properties, compatibility, validator) { if (hasInherit(right)) continue; + if (noneOverrideHack(left, right)) + continue; + if (!left.shorthand && right.shorthand && isComponentOf(right, left)) { // maybe `left` can be overridden by `right` which is a shorthand? if (!right.important && left.important) diff --git a/test/properties/override-compacting-test.js b/test/properties/override-compacting-test.js index 4268195e..4ccb4156 100644 --- a/test/properties/override-compacting-test.js +++ b/test/properties/override-compacting-test.js @@ -522,6 +522,24 @@ vows.describe(optimize) [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']], ]); } + }, + 'background then background - svg hack': { + 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background: __ESCAPED_URL_CLEAN_CSS1__,none}', + 'into': function (topic) { + assert.deepEqual(_optimize(topic), [ + [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__']], + [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS1__'], [','], ['none']] + ]); + } + }, + 'background-image then background-image - svg hack': { + 'topic': 'p{background-image:__ESCAPED_URL_CLEAN_CSS0__;background-image: __ESCAPED_URL_CLEAN_CSS1__,none}', + 'into': function (topic) { + assert.deepEqual(_optimize(topic), [ + [['background-image', false , false], ['__ESCAPED_URL_CLEAN_CSS0__']], + [['background-image', false , false], ['__ESCAPED_URL_CLEAN_CSS1__'], [','], ['none']] + ]); + } } }) .addBatch({