Fixes #655 - shorthand override merging.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 9 Sep 2015 12:26:48 +0000 (13:26 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 14 Sep 2015 12:12:53 +0000 (13:12 +0100)
When multiplex shorthand follows a non-multiplex shorthand then skip
merging as it's likely a fallback.

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

index 3ccd4fe..c61e9e2 100644 (file)
@@ -1,6 +1,7 @@
 [3.4.2 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.1...3.4)
 ==================
 
+* Fixed issue [#655](https://github.com/jakubpawlowicz/clean-css/issues/655) - shorthands override merging.
 * Fixed issue [#660](https://github.com/jakubpawlowicz/clean-css/issues/660) - !important token overriding.
 * Fixed issue [#662](https://github.com/jakubpawlowicz/clean-css/issues/662) - !important selector reducing.
 
index c25ce79..d795be6 100644 (file)
@@ -306,6 +306,9 @@ function compactOverrides(properties, compatibility, validator) {
       } else if (left.shorthand && right.shorthand && left.name == right.name) {
         // merge if all components can be merged
 
+        if (!left.multiplex && right.multiplex)
+          continue;
+
         if (!right.important && left.important) {
           right.unused = true;
           continue propertyLoop;
index ec9b07d..7a73b40 100644 (file)
@@ -473,6 +473,15 @@ vows.describe(optimize)
     }
   })
   .addBatch({
+    'shorthand then shorthand multiplex': {
+      'topic': 'p{background:url(one.png);background:url(two.png) center 1px,url(three.png) center 2px}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['background'], ['url(one.png)']],
+          [['background'], ['url(two.png)'], ['center'], ['1px'], [','], ['url(three.png)'], ['center'], ['2px']]
+        ]);
+      }
+    },
     'shorthand then longhand multiplex': {
       'topic': 'p{background:top left;background-repeat:no-repeat,no-repeat}',
       'into': function (topic) {