Skip to content

Resolve a source that already matches one of consumer.sources - #541

Open
PerryLink wants to merge 1 commit into
mozilla:masterfrom
PerryLink:fix/resolved-source-lookup
Open

PerryLink wants to merge 1 commit into
mozilla:masterfrom
PerryLink:fix/resolved-source-lookup

Conversation

@PerryLink

Copy link
Copy Markdown

What

A SourceMapConsumer created with a relative aSourceMapURL cannot resolve the very sources it
reports in consumer.sources. _findSourceIndex joins the query against sourceRoot only, so a source
that the consumer itself already returns is "not found":

const consumer = await new SourceMapConsumer(map, 'maps/app.map')
consumer.sources[0]                       // "maps/one.js"
consumer.sourceContentFor('maps/one.js')
// throws: "maps/one.js" is not in the SourceMap
consumer.generatedPositionFor({ source: 'maps/one.js', line: 1, column: 0 })  // line: null
SourceMapGenerator.fromSourceMap(consumer)                                     // throws

README.md:452-454 promises sourceContentFor works for every entry of sources when
hasContentsOfAllSources() is true, which it is here.

The change

After both existing resolutions miss, accept an exact match against the already-resolved
consumer.sources entries (lib/source-map-consumer.js:272-278). Every lookup that worked before goes
through the same path as before; the fallback only runs where the API previously threw.

Verification

  • node test/run-tests.js test/test-source-map-consumer.js: 64/65 → 65/65, full suite 190/191 → 191/191;
  • a standalone repro (new SourceMapConsumer(map, "maps/app.map")) goes from three failures to passing;
  • an 8-case sourceRoot × sourceMapURL matrix passes, confirming the previously working combinations
    are untouched;
  • eslint and prettier --check clean; git apply --check on a pristine master.

The new test uses relative URL strings and async/await only, so it is platform-neutral.

No CLA/DCO in the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant