Fixes #558 - units in same selector merging.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 May 2015 13:29:15 +0000 (14:29 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 May 2015 14:14:05 +0000 (15:14 +0100)
We apparently had a `joinAt` in wrong order so adjacent properties
were not merged correctly when in compatibility mode.

History.md
lib/selectors/optimizers/advanced.js
test/selectors/optimizer-test.js

index cbedfb7..91b345b 100644 (file)
@@ -13,6 +13,7 @@
 ==================
 
 * Fixed issue [#551](https://github.com/jakubpawlowicz/clean-css/issues/551) - edge case in restructuring.
+* 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 b4662d4..d20c8c4 100644 (file)
@@ -279,6 +279,7 @@ AdvancedOptimizer.prototype.mergeNonAdjacentBySelector = function (tokens) {
         var moved = topToBottom ? tokenOne : tokenTwo;
         var target = topToBottom ? tokenTwo : tokenOne;
         var movedProperties = extractProperties(moved);
+        var joinAt;
 
         while (from != to) {
           var traversedProperties = extractProperties(tokens[from]);
@@ -295,11 +296,12 @@ AdvancedOptimizer.prototype.mergeNonAdjacentBySelector = function (tokens) {
             continue directionIterator;
         }
 
-        var joinAt = topToBottom ? [target[2].length] : [moved[2].length];
         if (topToBottom) {
+          joinAt = [moved[2].length];
           Array.prototype.push.apply(moved[2], target[2]);
           target[2] = moved[2];
         } else {
+          joinAt = [target[2].length];
           Array.prototype.push.apply(target[2], moved[2]);
         }
 
index a39d9f6..bacd564 100644 (file)
@@ -299,6 +299,14 @@ vows.describe(SelectorsOptimizer)
       ]
     }, { advanced: true, aggressiveMerging: true })
   )
+  .addBatch(
+    optimizerContext('advanced on & aggressive merging on - IE8 mode', {
+      'units': [
+        '.one{width:1px;width:1rem;display:block}.two{color:red}.one{width:2px;width:1.1rem}',
+        '.one{display:block;width:2px;width:1.1rem}.two{color:red}'
+      ]
+    }, { advanced: true, aggressiveMerging: true, compatibility: 'ie8' })
+  )
   .addBatch(
     optimizerContext('advanced on & aggressive merging off', {
       'repeated' : [