Removes empty element removal from `mergeAdjacent`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 22 Mar 2015 16:56:28 +0000 (16:56 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 22 Mar 2015 16:56:28 +0000 (16:56 +0000)
After all we do it now in one pass at the end.

lib/selectors/optimizers/advanced.js

index 2ed2fc8..ac8036e 100644 (file)
@@ -62,7 +62,6 @@ AdvancedOptimizer.prototype.removeDuplicates = function (tokens) {
 };
 
 AdvancedOptimizer.prototype.mergeAdjacent = function (tokens) {
-  var forRemoval = [];
   var lastToken = [null, [], []];
   var adjacentSpace = this.options.compatibility.selectors.adjacentSpace;
 
@@ -77,19 +76,15 @@ AdvancedOptimizer.prototype.mergeAdjacent = function (tokens) {
     if (lastToken[0] == 'selector' && stringifySelector(token[1]) == stringifySelector(lastToken[1])) {
       var joinAt = [lastToken[2].length];
       lastToken[2] = this.propertyOptimizer.process(token[1], lastToken[2].concat(token[2]), joinAt, true);
-      forRemoval.push(i);
+      token[2] = [];
     } else if (lastToken[0] == 'selector' && stringifyBody(token[2]) == stringifyBody(lastToken[2]) &&
         !this.isSpecial(stringifySelector(token[1])) && !this.isSpecial(stringifySelector(lastToken[1]))) {
       lastToken[1] = CleanUp.selectors(lastToken[1].concat(token[1]), false, adjacentSpace);
-      forRemoval.push(i);
+      token[2] = [];
     } else {
       lastToken = token;
     }
   }
-
-  for (var j = 0, m = forRemoval.length; j < m; j++) {
-    tokens.splice(forRemoval[j] - j, 1);
-  }
 };
 
 AdvancedOptimizer.prototype.reduceNonAdjacent = function (tokens) {