Skip to content
Open
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
9 changes: 6 additions & 3 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
if (
generatedPosition.lastColumn === Infinity &&
nextSection &&
generatedPosition.line === nextSection.generatedOffset.generatedLine
generatedPosition.line + lineShift ===
nextSection.generatedOffset.generatedLine
) {
generatedPosition.lastColumn =
nextSection.generatedOffset.generatedColumn - 2;
Expand Down Expand Up @@ -964,7 +965,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
if (
generatedPosition.lastColumn === Infinity &&
nextSection &&
generatedPosition.line === nextSection.generatedOffset.generatedLine
generatedPosition.line + lineShift ===
nextSection.generatedOffset.generatedLine
) {
generatedPosition.lastColumn =
nextSection.generatedOffset.generatedColumn - 2;
Expand Down Expand Up @@ -997,7 +999,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
if (
mapping.lastGeneratedColumn === Infinity &&
nextSection &&
mapping.generatedLine === nextSection.generatedOffset.generatedLine
mapping.generatedLine + lineShift ===
nextSection.generatedOffset.generatedLine
) {
mapping.lastGeneratedColumn =
nextSection.generatedOffset.generatedColumn - 2;
Expand Down
72 changes: 72 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,78 @@ exports["test computeColumnSpans"] = async function (assert) {
map.destroy();
};

exports["test computeColumnSpans with nonzero line offset sections (#542)"] = async function (assert) {
const section = source => ({ version: 3, sources: [source], names: [], mappings: "AAAA" });

const map = await new SourceMapConsumer({
version: 3,
sections: [
{ offset: { line: 0, column: 0 }, map: section("a.js") },
{ offset: { line: 2, column: 0 }, map: section("b.js") },
{ offset: { line: 2, column: 10 }, map: section("c.js") },
],
});
map.computeColumnSpans();

const pos = map.generatedPositionFor({ source: "b.js", line: 1, column: 0 });
assert.equal(pos.line, 3);
assert.equal(pos.column, 0);
assert.equal(pos.lastColumn, 9);

const all = map.allGeneratedPositionsFor({ source: "b.js", line: 1, column: 0 });
assert.equal(all.length, 1);
assert.equal(all[0].line, 3);
assert.equal(all[0].column, 0);
assert.equal(all[0].lastColumn, 9);

const eachMappings = [];
map.eachMapping(m => eachMappings.push(m));
const bMapping = eachMappings.find(m => m.source === "b.js");
assert.equal(bMapping.lastGeneratedColumn, 9);

map.destroy();
};

exports["test computeColumnSpans with first section nonzero line offset (#539)"] = async function (assert) {
const consumer = await new SourceMapConsumer({
version: 3,
sections: [
{
offset: { line: 4, column: 3 },
map: { version: 3, sources: ["first.js"], names: [], mappings: "AAAA" },
},
{
offset: { line: 4, column: 10 },
map: { version: 3, sources: ["second.js"], names: [], mappings: "AAAA" },
},
],
});
try {
consumer.computeColumnSpans();
const pos = consumer.generatedPositionFor({
source: "first.js", line: 1, column: 0,
});
assert.equal(pos.line, 5);
assert.equal(pos.column, 3);
assert.equal(pos.lastColumn, 9);

const all = consumer.allGeneratedPositionsFor({
source: "first.js", line: 1, column: 0,
});
assert.equal(all.length, 1);
assert.equal(all[0].line, 5);
assert.equal(all[0].column, 3);
assert.equal(all[0].lastColumn, 9);

const eachMappings = [];
consumer.eachMapping(m => eachMappings.push(m));
const firstMapping = eachMappings.find(m => m.source === "first.js");
assert.equal(firstMapping.lastGeneratedColumn, 9);
} finally {
consumer.destroy();
}
};

exports["test sourceRoot + originalPositionFor"] = async function (assert) {
let map = new SourceMapGenerator({
sourceRoot: "foo/bar",
Expand Down