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
2 changes: 1 addition & 1 deletion lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class BasicSourceMapConsumer extends SourceMapConsumer {
* @returns BasicSourceMapConsumer
*/
static fromSourceMap(aSourceMap, aSourceMapURL) {
return new BasicSourceMapConsumer(aSourceMap.toString());
return new BasicSourceMapConsumer(aSourceMap.toString(), aSourceMapURL);
}

get sources() {
Expand Down
28 changes: 28 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2192,3 +2192,31 @@ 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 SourceMapConsumer.fromSourceMap with a source map URL"] =
async function (assert) {
const smg = new SourceMapGenerator({ file: "out.js" });
smg.addMapping({
original: { line: 1, column: 0 },
generated: { line: 1, column: 0 },
source: "src/a.js",
});
smg.setSourceContent("src/a.js", "a content");

const smc = await SourceMapConsumer.fromSourceMap(
smg,
"http://example.com/maps/out.js.map"
);
assert.equal(smc.sources.length, 1);
assert.equal(smc.sources[0], "http://example.com/maps/src/a.js");
assert.equal(
smc.originalPositionFor({ line: 1, column: 0 }).source,
"http://example.com/maps/src/a.js"
);
assert.equal(
smc.sourceContentFor("http://example.com/maps/src/a.js"),
"a content"
);

smc.destroy();
};