From 4a57848b556a03ac0a7d0be29ef76aa24befa36e Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 9 Feb 2014 21:15:39 +0000 Subject: [PATCH] Fixes #223 - adjacent selectors merging. Makes sure removing duplicates and merging adjacent selectors is run twice, beforehand the latter was not the case. This is because adjacent selectors may be merged in the first pass creating opportunity to further improve minification. --- History.md | 1 + lib/selectors/optimizer.js | 5 +---- test/unit-test.js | 4 ++++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/History.md b/History.md index 2d31c024..43521172 100644 --- a/History.md +++ b/History.md @@ -17,6 +17,7 @@ * Fixed issue [#217](https://github.com/GoalSmashers/clean-css/issues/217) - whitespace inside attribute selectors and urls. * Fixed issue [#218](https://github.com/GoalSmashers/clean-css/issues/218) - `@import` statements cleanup. * Fixed issue [#220](https://github.com/GoalSmashers/clean-css/issues/220) - selector between comments. +* Fixed issue [#223](https://github.com/GoalSmashers/clean-css/issues/223) - two-pass adjacent selectors merging. * Fixed issue [#229](https://github.com/GoalSmashers/clean-css/issues/229) - improved processing of fraction numbers. * Fixed issue [#230](https://github.com/GoalSmashers/clean-css/issues/230) - better handling of zero values. diff --git a/lib/selectors/optimizer.js b/lib/selectors/optimizer.js index 09f2b311..3fbef0d3 100644 --- a/lib/selectors/optimizer.js +++ b/lib/selectors/optimizer.js @@ -195,9 +195,8 @@ module.exports = function Optimizer(data, context, options) { }; var optimize = function(tokens) { - var firstRun = true; var noChanges = function() { - return !firstRun && + return minificationsMade.length > 4 && minificationsMade[0] === false && minificationsMade[1] === false; }; @@ -228,8 +227,6 @@ module.exports = function Optimizer(data, context, options) { if (noChanges()) break; reduceNonAdjacent(tokens); - - firstRun = false; } }; diff --git a/test/unit-test.js b/test/unit-test.js index 4de87681..8288dcf4 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -1365,6 +1365,10 @@ title']{display:block}", 'two adjacent with hex color definitions': [ 'a:link,a:visited{color:#fff}.one{display:block}a:link,a:visited{color:red}', '.one{display:block}a:link,a:visited{color:red}' + ], + 'in two passes': [ + 'a{color:red}a{background:red}b{color:red}b{background:red}', + 'a,b{color:red;background:red}' ] }), 'same non-adjacent selectors': cssContext({ -- 2.34.1