From: Jakub Pawlowicz Date: Tue, 20 Jan 2015 21:00:25 +0000 (+0000) Subject: Refixes #414 - source map position fallback. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f5d3efb0fb54889c95d69edc467aa8988c79111a;p=clean-css.git Refixes #414 - source map position fallback. 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. --- diff --git a/History.md b/History.md index 189755ba..5d2c85d3 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/selectors/source-map-stringifier.js b/lib/selectors/source-map-stringifier.js index bf9a8b2a..3dcdad42 100644 --- a/lib/selectors/source-map-stringifier.js +++ b/lib/selectors/source-map-stringifier.js @@ -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; } diff --git a/test/source-map-test.js b/test/source-map-test.js index 3c90f0fe..4e06678e 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -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({