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 @@ -918,6 +918,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
}
}

generatedPosition.line += lineShift;

if (
generatedPosition.lastColumn === Infinity &&
nextSection &&
Expand All @@ -926,7 +928,6 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
generatedPosition.lastColumn =
nextSection.generatedOffset.generatedColumn - 2;
}
generatedPosition.line += lineShift;

return generatedPosition;
}
Expand Down Expand Up @@ -961,6 +962,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
}
}

generatedPosition.line += lineShift;

if (
generatedPosition.lastColumn === Infinity &&
nextSection &&
Expand All @@ -969,7 +972,6 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
generatedPosition.lastColumn =
nextSection.generatedOffset.generatedColumn - 2;
}
generatedPosition.line += lineShift;

return generatedPosition;
});
Expand All @@ -994,6 +996,8 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
}
}

mapping.generatedLine += lineShift;

if (
mapping.lastGeneratedColumn === Infinity &&
nextSection &&
Expand All @@ -1002,7 +1006,6 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
mapping.lastGeneratedColumn =
nextSection.generatedOffset.generatedColumn - 2;
}
mapping.generatedLine += lineShift;

aCallback.call(this, mapping);
},
Expand Down
38 changes: 38 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2192,3 +2192,41 @@ exports["test a mapping at the boundary of indexed source map offset"] =
util.assertMapping(1, 0, "/the/root/one.js", 1, 0, null, null, map, assert);
map.destroy();
};

exports[
"test computeColumnSpans with an indexed map whose sections do not start on line 1"
] = 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();

// "b.js" ends where "c.js" begins on generated line 3.
assert.deepEqual(
map.generatedPositionFor({ source: "b.js", line: 1, column: 0 }),
{ line: 3, column: 0, lastColumn: 9 }
);
assert.deepEqual(map.allGeneratedPositionsFor({ source: "b.js", line: 1 }), [
{ line: 3, column: 0, lastColumn: 9 },
]);

const lastColumns = {};
map.eachMapping(m => {
lastColumns[m.source] = m.lastGeneratedColumn;
});
assert.equal(lastColumns["b.js"], 9);
assert.equal(lastColumns["c.js"], Infinity);

map.destroy();
};