Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
46 changes: 46 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down