Readds minification feedback for non-adjacent optimizer.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 23 Feb 2014 16:16:16 +0000 (16:16 +0000)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 23 Feb 2014 16:25:28 +0000 (16:25 +0000)
lib/selectors/optimizer.js

index cbf3e7f..0b6e6ce 100644 (file)
@@ -153,11 +153,15 @@ module.exports = function Optimizer(data, context, options) {
       }
     }
 
-    _reduceSimpleNonAdjacentCases(tokens, moreThanOnce, candidates);
-    _reduceComplexNonAdjacentCases(tokens, candidates);
+    var reducedInSimple = _reduceSimpleNonAdjacentCases(tokens, moreThanOnce, candidates);
+    var reducedInComplex = _reduceComplexNonAdjacentCases(tokens, candidates);
+
+    minificationsMade.unshift(reducedInSimple || reducedInComplex);
   };
 
   var _reduceSimpleNonAdjacentCases = function(tokens, matches, positions) {
+    var reduced = false;
+
     for (var i = 0, l = matches.length; i < l; i++) {
       var selector = matches[i];
       var data = positions[selector];
@@ -171,14 +175,20 @@ module.exports = function Optimizer(data, context, options) {
           return data[idx].partial && bodies.length === 0;
         },
         callback: function(token, newBody, processedCount, tokenIdx) {
-          if (!data[processedCount - tokenIdx - 1].partial)
+          if (!data[processedCount - tokenIdx - 1].partial) {
             token.body = newBody.join(';');
+            reduced = true;
+          }
         }
       });
     }
+
+    return reduced;
   };
 
   var _reduceComplexNonAdjacentCases = function(tokens, positions) {
+    var reduced = false;
+
     allSelectors:
     for (var complexSelector in positions) {
       if (complexSelector.indexOf(',') == -1) // simplification, as :not() can have commas too
@@ -213,7 +223,10 @@ module.exports = function Optimizer(data, context, options) {
       }
 
       intoToken.body = reducedBodies[0];
+      reduced = true;
     }
+
+    return reduced;
   };
 
   var _reduceSelector = function(tokens, selector, data, options) {