From 6b238a5da9d781c632788e677fcb26bea31785cd Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 26 Oct 2014 11:32:38 +0000 Subject: [PATCH] Clarifies conditions in advanced processing. --- lib/selectors/optimizers/advanced.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/selectors/optimizers/advanced.js b/lib/selectors/optimizers/advanced.js index 45667769..d1da9958 100644 --- a/lib/selectors/optimizers/advanced.js +++ b/lib/selectors/optimizers/advanced.js @@ -100,7 +100,8 @@ AdvancedOptimizer.prototype.reduceNonAdjacent = function (tokens) { if (token.kind != 'selector') continue; - var selectors = token.value.length > 1 && !this.isSpecial(token.metadata.selector) ? + var isComplexAndNotSpecial = token.value.length > 1 && !this.isSpecial(token.metadata.selector); + var selectors = isComplexAndNotSpecial ? [token.metadata.selector].concat(token.metadata.selectorsList) : [token.metadata.selector]; @@ -114,8 +115,9 @@ AdvancedOptimizer.prototype.reduceNonAdjacent = function (tokens) { candidates[selector].push({ where: i, - partial: selector != token.metadata.selector, - list: token.metadata.selectorsList + list: token.metadata.selectorsList, + isPartial: isComplexAndNotSpecial && j > 0, + isComplex: isComplexAndNotSpecial && j === 0 }); } } @@ -133,16 +135,13 @@ AdvancedOptimizer.prototype.reduceSimpleNonAdjacentCases = function (tokens, rep var selector = repeated[i]; var data = candidates[selector]; - if (data.length < 2) - continue; - /* jshint loopfunc: true */ this.reduceSelector(tokens, selector, data, { filterOut: function (idx, bodies) { - return data[idx].partial && bodies.length === 0; + return data[idx].isPartial && bodies.length === 0; }, callback: function (token, newBody, processedCount, tokenIdx) { - if (!data[processedCount - tokenIdx - 1].partial) { + if (!data[processedCount - tokenIdx - 1].isPartial) { changeBodyOf(token, newBody); reduced = true; } @@ -158,10 +157,10 @@ AdvancedOptimizer.prototype.reduceComplexNonAdjacentCases = function (tokens, ca allSelectors: for (var complexSelector in candidates) { - if (complexSelector.indexOf(',') == -1) + var into = candidates[complexSelector]; + if (!into[0].isComplex) continue; - var into = candidates[complexSelector]; var intoPosition = into[into.length - 1].where; var intoToken = tokens[intoPosition]; -- 2.34.1