Refixes #414 - source map position fallback.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 20 Jan 2015 21:00:25 +0000 (21:00 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 20 Jan 2015 21:22:22 +0000 (21:22 +0000)
Apparently the original fix does not always work as selectors are
being sorted during optimizations so we cannot predict how many
fallback needs to be taken.

Fortunately doing all fallbacks for selector list is also safe, given
a source map is properly built.

It won't be needed anymore once #396 is in place.
Test case provided by @unlok in #438.

History.md
lib/selectors/source-map-stringifier.js
test/source-map-test.js

index 189755b..5d2c85d 100644 (file)
@@ -1,4 +1,4 @@
-[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.5...v3.1.0)
+[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.6...v3.1.0)
 ==================
 
 * Adds 0deg to 0 minification where possible.
@@ -9,6 +9,11 @@
 * Fixed issue [#357](https://github.com/GoalSmashers/clean-css/issues/357) - non-standard but valid URLs.
 * Fixed issue [#416](https://github.com/GoalSmashers/clean-css/issues/416) - accepts hash as `minify` argument.
 
+[3.0.6 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.5...v3.0.6)
+==================
+
+* Refixed issue [#414](https://github.com/GoalSmashers/clean-css/issues/414) - source maps position fallback.
+
 [3.0.5 / 2015-01-18](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.4...v3.0.5)
 ==================
 
index bf9a8b2..3dcdad4 100644 (file)
@@ -50,7 +50,7 @@ Rebuilder.prototype.rebuildValue = function (list, separator, isSelector) {
       if (i === l - 1 && escaped > 0)
         this.output.splice(this.output.length - escaped - 1, 1);
     } else {
-      this.store(el, isSelector ? i : 0);
+      this.store(el, isSelector ? l : 0);
       this.store(i < l - 1 ? separator : '');
       escaped = 0;
     }
index 3c90f0f..4e06678 100644 (file)
@@ -579,6 +579,56 @@ vows.describe('source-map')
         };
         assert.deepEqual(minified.sourceMap._mappings._array[3], mapping);
       }
+    },
+    'input source map with missing mutliselector sortable input': {
+      'topic': new CleanCSS({ sourceMap: '{"version":3,"sources":["source.css"],"names":[],"mappings":"AAAA;;;;IAII,YAAW;EACd"}' }).minify('a.button:link,\na.button:visited,\na.button:hover\n{\n    color: red;\n}'),
+      'should have 4 mappings': function (minified) {
+        assert.lengthOf(minified.sourceMap._mappings._array, 4);
+      },
+      'should have "a.button:hover" mapping': function (minified) {
+        var mapping = {
+          generatedLine: 1,
+          generatedColumn: 0,
+          originalLine: 1,
+          originalColumn: 0,
+          source: 'source.css',
+          name: null
+        };
+        assert.deepEqual(minified.sourceMap._mappings._array[0], mapping);
+      },
+      'should have "a.button:link" mapping': function (minified) {
+        var mapping = {
+          generatedLine: 1,
+          generatedColumn: 15,
+          originalLine: 1,
+          originalColumn: 0,
+          source: 'source.css',
+          name: null
+        };
+        assert.deepEqual(minified.sourceMap._mappings._array[1], mapping);
+      },
+      'should have "a.button:visited" mapping': function (minified) {
+        var mapping = {
+          generatedLine: 1,
+          generatedColumn: 29,
+          originalLine: 1,
+          originalColumn: 0,
+          source: 'source.css',
+          name: null
+        };
+        assert.deepEqual(minified.sourceMap._mappings._array[2], mapping);
+      },
+      'should have "color:red" mapping': function (minified) {
+        var mapping = {
+          generatedLine: 1,
+          generatedColumn: 46,
+          originalLine: 5,
+          originalColumn: 4,
+          source: 'source.css',
+          name: null
+        };
+        assert.deepEqual(minified.sourceMap._mappings._array[3], mapping);
+      }
     }
   })
   .addBatch({