Fixes non-adjacent optimizations for source maps.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 26 Aug 2015 05:11:00 +0000 (06:11 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 27 Aug 2015 06:44:52 +0000 (07:44 +0100)
We've been comparing wrong things as AST is different.

lib/selectors/reduce-non-adjacent.js

index c3d7efb..1ad9c06 100644 (file)
@@ -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;