Fixes #223 - adjacent selectors merging.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 9 Feb 2014 21:15:39 +0000 (21:15 +0000)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 9 Feb 2014 21:19:40 +0000 (21:19 +0000)
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
lib/selectors/optimizer.js
test/unit-test.js

index 2d31c02..4352117 100644 (file)
@@ -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.
 
index 09f2b31..3fbef0d 100644 (file)
@@ -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;
     }
   };
 
index 4de8768..8288dcf 100644 (file)
@@ -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({