diff --git a/lib/source-map-consumer.js b/lib/source-map-consumer.js index 9b68e393..91c4c0f1 100644 --- a/lib/source-map-consumer.js +++ b/lib/source-map-consumer.js @@ -785,7 +785,7 @@ class IndexedSourceMapConsumer extends SourceMapConsumer { return cmp; } - return (aNeedle.generatedColumn - + return ((aNeedle.generatedColumn + 1) - section.generatedOffset.generatedColumn); }); const section = this._sections[sectionIndex]; diff --git a/test/test-source-map-consumer.js b/test/test-source-map-consumer.js index 3d86b39e..7f2ed4aa 100644 --- a/test/test-source-map-consumer.js +++ b/test/test-source-map-consumer.js @@ -692,6 +692,52 @@ exports["test index map + generatedPositionFor"] = async function(assert) { map.destroy(); }; +exports["test index map + originalPositionFor"] = async function(assert) { + const map = await new SourceMapConsumer(util.indexedTestMapWithMappingsAtSectionStart); + + let pos = map.originalPositionFor({ + line: 1, + column: 0 + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 0); + assert.equal(pos.source, "foo.js"); + assert.equal(pos.name, "first"); + + pos = map.originalPositionFor({ + line: 1, + column: 1 + }); + + assert.equal(pos.line, 2); + assert.equal(pos.column, 1); + assert.equal(pos.source, "bar.js"); + assert.equal(pos.name, "second"); + + pos = map.originalPositionFor({ + line: 1, + column: 2 + }); + + assert.equal(pos.line, 1); + assert.equal(pos.column, 0); + assert.equal(pos.source, "baz.js"); + assert.equal(pos.name, "third"); + + pos = map.originalPositionFor({ + line: 1, + column: 3 + }); + + assert.equal(pos.line, 2); + assert.equal(pos.column, 1); + assert.equal(pos.source, "quux.js"); + assert.equal(pos.name, "fourth"); + + map.destroy(); +}; + exports["test allGeneratedPositionsFor for line"] = async function(assert) { let map = new SourceMapGenerator({ file: "generated.js" diff --git a/test/util.js b/test/util.js index 3f2c25c9..3e4972aa 100644 --- a/test/util.js +++ b/test/util.js @@ -265,6 +265,29 @@ exports.indexedTestMapColumnOffset = { } ] }; +exports.indexedTestMapWithMappingsAtSectionStart = { + version: 3, + sections: [ + { + offset: {"line": 0, "column": 0}, + map: { + version: 3, + names: ["first", "second"], + sources: ["foo.js", "bar.js"], + mappings: "AAAAA,CCCCC" + } + }, + { + offset: {"line": 0, "column": 2}, + map: { + version: 3, + names: ["third", "fourth"], + sources: ["baz.js", "quux.js"], + mappings: "AAAAA,CCCCC" + } + } + ] +}; exports.testMapWithSourcesContent = { version: 3, file: "min.js",