From 6bda91f1a9957cbd0d3ed4557c86d7fcb6393cf5 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 3 May 2015 14:29:15 +0100 Subject: [PATCH] Fixes #558 - units in same selector merging. We apparently had a `joinAt` in wrong order so adjacent properties were not merged correctly when in compatibility mode. --- History.md | 1 + lib/selectors/optimizers/advanced.js | 4 +++- test/selectors/optimizer-test.js | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index cbedfb7d..91b345be 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/selectors/optimizers/advanced.js b/lib/selectors/optimizers/advanced.js index b4662d49..d20c8c45 100644 --- a/lib/selectors/optimizers/advanced.js +++ b/lib/selectors/optimizers/advanced.js @@ -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]); } diff --git a/test/selectors/optimizer-test.js b/test/selectors/optimizer-test.js index a39d9f6d..bacd5642 100644 --- a/test/selectors/optimizer-test.js +++ b/test/selectors/optimizer-test.js @@ -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' : [ -- 2.34.1