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
8 changes: 8 additions & 0 deletions lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
return index;
}

// The source may already be fully resolved, for example when it came from
// `consumer.sources`, so accept it as-is before giving up.
if (this._absoluteSources.has(aSource)) {
const index = this._absoluteSources.indexOf(aSource);
this._sourceLookupCache.set(aSource, index);
return index;
}

// To avoid this cache growing forever, we do not cache lookup misses.
return -1;
}
Expand Down
27 changes: 27 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,33 @@ exports[
consumer.destroy();
};

exports[
"test resolved sources are accepted by sourceContentFor and generatedPositionFor"
] = async function (assert) {
const map = {
version: 3,
sources: ["one.js"],
names: [],
mappings: "AAAA",
sourcesContent: ["var one = 1;"],
};
const consumer = await new SourceMapConsumer(map, "maps/app.map");

assert.equal(consumer.sources[0], "maps/one.js");
assert.ok(consumer.hasContentsOfAllSources());
assert.equal(consumer.sourceContentFor(consumer.sources[0]), "var one = 1;");
assert.equal(
consumer.generatedPositionFor({
source: consumer.sources[0],
line: 1,
column: 0,
}).line,
1
);

consumer.destroy();
};

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