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
26 changes: 19 additions & 7 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,14 +939,26 @@ class IndexedSourceMapConsumer extends SourceMapConsumer {
}

allGeneratedPositionsFor(aArgs) {
const index = this._findSectionIndex(util.getArg(aArgs, "source"));
const section = index >= 0 ? this._sections[index] : null;
const nextSection =
index >= 0 && index + 1 < this._sections.length
? this._sections[index + 1]
: null;
const source = util.getArg(aArgs, "source");
let positions = [];

// The same original source can appear in more than one section, so
// collect the positions from every section that contains it.
for (let i = 0; i < this._sections.length; i++) {
if (this._sections[i].consumer._findSourceIndex(source) !== -1) {
positions = positions.concat(
this._sectionGeneratedPositionsFor(i, aArgs)
);
}
}

if (!section) return [];
return positions;
}

_sectionGeneratedPositionsFor(index, aArgs) {
const section = this._sections[index];
const nextSection =
index + 1 < this._sections.length ? this._sections[index + 1] : null;

return section.consumer
.allGeneratedPositionsFor(aArgs)
Expand Down
50 changes: 50 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,56 @@ exports["test allGeneratedPositionsFor for index map"] = async function (
map.destroy();
};

exports[
"test allGeneratedPositionsFor for index map with a source in several sections"
] = async function (assert) {
const map = await new SourceMapConsumer({
version: 3,
file: "min.js",
sections: [
{
offset: { line: 0, column: 0 },
map: {
version: 3,
sources: ["shared.js"],
names: [],
mappings: "AAAA",
},
},
{
offset: { line: 2, column: 4 },
map: {
version: 3,
sources: ["shared.js"],
names: [],
mappings: "AAAA",
},
},
],
});

const mappings = map.allGeneratedPositionsFor({
line: 1,
column: 0,
source: "shared.js",
});

assert.deepEqual(mappings, [
{
line: 1,
column: 0,
lastColumn: null,
},
{
line: 3,
column: 4,
lastColumn: null,
},
]);

map.destroy();
};

exports["test computeColumnSpans"] = async function (assert) {
let map = new SourceMapGenerator({
file: "generated.js",
Expand Down