diff --git a/lib/source-map/source-map-consumer.js b/lib/source-map/source-map-consumer.js index a3b9dc08..58906951 100644 --- a/lib/source-map/source-map-consumer.js +++ b/lib/source-map/source-map-consumer.js @@ -312,7 +312,7 @@ define(function (require, exports, module) { "generatedColumn", util.compareByGeneratedPositions); - if (mapping) { + if (mapping && mapping.generatedLine === needle.generatedLine) { var source = util.getArg(mapping, 'source', null); if (source && this.sourceRoot) { source = util.join(this.sourceRoot, source); diff --git a/test/source-map/test-dog-fooding.js b/test/source-map/test-dog-fooding.js index d831b926..26757b2d 100644 --- a/test/source-map/test-dog-fooding.js +++ b/test/source-map/test-dog-fooding.js @@ -42,6 +42,12 @@ define(function (require, exports, module) { generated: { line: 5, column: 2 } }); + smg.addMapping({ + source: 'gza.coffee', + original: { line: 5, column: 10 }, + generated: { line: 6, column: 12 } + }); + var smc = new SourceMapConsumer(smg.toString()); // Exact @@ -49,24 +55,30 @@ define(function (require, exports, module) { util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, smc, assert); util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, smc, assert); util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 10, null, smc, assert); // Fuzzy - // Original to generated + // Generated to original util.assertMapping(2, 0, null, null, null, null, smc, assert, true); util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true); - util.assertMapping(3, 0, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true); + util.assertMapping(3, 0, null, null, null, null, smc, assert, true); util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true); - util.assertMapping(4, 0, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true); + util.assertMapping(4, 0, null, null, null, null, smc, assert, true); util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true); - util.assertMapping(5, 0, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true); + util.assertMapping(5, 0, null, null, null, null, smc, assert, true); util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert, true); + util.assertMapping(6, 0, null, null, null, null, smc, assert, true); + util.assertMapping(6, 9, null, null, null, null, smc, assert, true); + util.assertMapping(6, 13, '/wu/tang/gza.coffee', 5, 10, null, smc, assert, true); - // Generated to original + // Original to generated util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, smc, assert, null, true); util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, smc, assert, null, true); util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 6, null, smc, assert, null, true); util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, smc, assert, null, true); + util.assertMapping(5, 2, '/wu/tang/gza.coffee', 5, 9, null, smc, assert, null, true); + util.assertMapping(6, 12, '/wu/tang/gza.coffee', 6, 19, null, smc, assert, null, true); }; }); diff --git a/test/source-map/test-source-map-consumer.js b/test/source-map/test-source-map-consumer.js index f2c65a7f..4bda682e 100644 --- a/test/source-map/test-source-map-consumer.js +++ b/test/source-map/test-source-map-consumer.js @@ -80,6 +80,30 @@ define(function (require, exports, module) { util.assertMapping(2, 9, '/the/root/two.js', 1, 16, null, map, assert, null, true); }; + exports['test mappings and end of lines'] = function (assert, util) { + var smg = new SourceMapGenerator({ + file: 'foo.js' + }); + smg.addMapping({ + original: { line: 1, column: 1 }, + generated: { line: 1, column: 1 }, + source: 'bar.js' + }); + smg.addMapping({ + original: { line: 2, column: 2 }, + generated: { line: 2, column: 2 }, + source: 'bar.js' + }); + + var map = SourceMapConsumer.fromSourceMap(smg); + + // When finding original positions, mappings end at the end of the line. + util.assertMapping(2, 1, null, null, null, null, map, assert, true) + + // When finding generated positions, mappings do not end at the end of the line. + util.assertMapping(1, 1, 'bar.js', 2, 1, null, map, assert, null, true); + }; + exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) { assert.doesNotThrow(function () { var map = new SourceMapConsumer(")]}'" + JSON.stringify(util.testMap));