Fixes #371 - SVG background hack.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 15 Apr 2015 21:56:22 +0000 (22:56 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 15 Apr 2015 21:56:22 +0000 (22:56 +0100)
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;`.

History.md
lib/properties/override-compactor.js
test/properties/override-compacting-test.js

index 1b4fd7c..8872ed9 100644 (file)
@@ -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.
index 8a7e07d..7799f96 100644 (file)
@@ -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)
index 4268195..4ccb415 100644 (file)
@@ -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({