Fixes #553 - another style of SVG fallback.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 May 2015 14:03:33 +0000 (15:03 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 May 2015 14:14:06 +0000 (15:14 +0100)
This addresses any version of SVG fallback when one layer is set to
none. It's not future proof though since:

* it may bo none + sth
* it may be an empty linear gradient

Once we have #407 in place we'll be able to actually see which URL is
a SVG and decide based on that.

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

index 91b345b..1d1f45e 100644 (file)
@@ -13,6 +13,7 @@
 ==================
 
 * Fixed issue [#551](https://github.com/jakubpawlowicz/clean-css/issues/551) - edge case in restructuring.
+* Fixed issue [#553](https://github.com/jakubpawlowicz/clean-css/issues/553) - another style of SVG fallback.
 * Fixed issue [#558](https://github.com/jakubpawlowicz/clean-css/issues/558) - units in same selector merging.
 
 [3.2.6 / 2015-04-28](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.5...v3.2.6)
index 7799f96..5811dd3 100644 (file)
@@ -183,7 +183,35 @@ function noneOverrideHack(left, right) {
     (left.name == 'background' || left.name == 'background-image') &&
     right.multiplex &&
     (right.name == 'background' || right.name == 'background-image') &&
-    right.value[right.value.length - 1][0] == 'none';
+    anyLayerIsNone(right.value);
+}
+
+function anyLayerIsNone(values) {
+  var layers = intoLayers(values);
+
+  for (var i = 0, l = layers.length; i < l; i++) {
+    if (layers[i].length == 1 && layers[i][0][0] == 'none')
+      return true;
+  }
+
+  return false;
+}
+
+function intoLayers(values) {
+  var layers = [];
+
+  for (var i = 0, layer = [], l = values.length; i < l; i++) {
+    var value = values[i];
+    if (value[0] == MULTIPLEX_SEPARATOR) {
+      layers.push(layer);
+      layer = [];
+    } else {
+      layer.push(value);
+    }
+  }
+
+  layers.push(layer);
+  return layers;
 }
 
 function compactOverrides(properties, compatibility, validator) {
index 6266a29..b90bea8 100644 (file)
@@ -524,7 +524,7 @@ vows.describe(optimize)
       }
     },
     'background then background - svg hack': {
-      'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background: __ESCAPED_URL_CLEAN_CSS1__,none}',
+      '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__']],
@@ -532,6 +532,15 @@ vows.describe(optimize)
         ]);
       }
     },
+    'background then background - inverted svg hack': {
+      'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background:none,__ESCAPED_URL_CLEAN_CSS1__}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__']],
+          [['background', false , false], ['0 0'], [','], ['__ESCAPED_URL_CLEAN_CSS1__']]
+        ]);
+      }
+    },
     '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) {