From: Jakub Pawlowicz Date: Wed, 26 Aug 2015 05:11:00 +0000 (+0100) Subject: Fixes non-adjacent optimizations for source maps. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6d3d2e9bfb8bf6cfa2791f65247c58886a66c6ab;p=clean-css.git Fixes non-adjacent optimizations for source maps. We've been comparing wrong things as AST is different. --- diff --git a/lib/selectors/reduce-non-adjacent.js b/lib/selectors/reduce-non-adjacent.js index c3d7efb7..1ad9c066 100644 --- a/lib/selectors/reduce-non-adjacent.js +++ b/lib/selectors/reduce-non-adjacent.js @@ -17,8 +17,9 @@ function reduceNonAdjacent(tokens, options, validator) { var selectorAsString = stringifySelectors(token[1]); var isComplexAndNotSpecial = token[1].length > 1 && !isSpecial(options, selectorAsString); + var wrappedSelectors = options.sourceMap ? wrappedSelectorsFrom(token[1]) : token[1]; var selectors = isComplexAndNotSpecial ? - [selectorAsString].concat(token[1]) : + [selectorAsString].concat(wrappedSelectors) : [selectorAsString]; for (var j = 0, m = selectors.length; j < m; j++) { @@ -31,7 +32,7 @@ function reduceNonAdjacent(tokens, options, validator) { candidates[selector].push({ where: i, - list: token[1], + list: wrappedSelectors, isPartial: isComplexAndNotSpecial && j > 0, isComplex: isComplexAndNotSpecial && j === 0 }); @@ -42,6 +43,16 @@ function reduceNonAdjacent(tokens, options, validator) { reduceComplexNonAdjacentCases(tokens, candidates, options, validator); } +function wrappedSelectorsFrom(list) { + var wrapped = []; + + for (var i = 0; i < list.length; i++) { + wrapped.push([list[i][0]]); + } + + return wrapped; +} + function reduceSimpleNonAdjacentCases(tokens, repeated, candidates, options, validator) { function filterOut(idx, bodies) { return data[idx].isPartial && bodies.length === 0;