Repository navigation
Fix SourceMapGenerator.fromSourceMap() on index source maps - #132
Merged
Merged
Conversation
- It checked `sourceRoot !== null` before making each source relative to the sourceRoot. IndexedSourceMapConsumer has no sourceRoot, so the check passed for undefined and util.relative() threw "Cannot read properties of undefined (reading 'replace')". The rest of the generator checks `!= null`, and so does this now. - It copied each source's content with sourceContentFor(source), which on an IndexedSourceMapConsumer throws for a source without content unless asked to return null. It only asks about the consumer's own sources, so it now passes `true` and gets null for those. Both are from #126.
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
…e path SourceNode.fromStringWithSourceMap() joins its third argument, a relative path, to the source of every mapping. A mapping without an original position has a null source, and util.join() threw "Cannot read properties of null (reading 'match')" on it. Regular source maps with such mappings already threw. Index maps didn't, because their unmapped segments had the source "."; with that fixed in the previous commit, they started throwing too. The path is now only joined to a source that isn't null. The changeset no longer says that SourceMapGenerator.fromSourceMap() works on these maps: on index maps it still throws for another reason until #132 lands. Found by a Codex review.
An index map without sources, such as one with no sections, didn't throw.
These test files use the legacy node:assert. On Node 26 its deepEqual() lets a null in the expected array match any value, so expected entries like ['A', null] didn't check the null.
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
…e path SourceNode.fromStringWithSourceMap() joins its third argument, a relative path, to the source of every mapping. A mapping without an original position has a null source, and util.join() threw "Cannot read properties of null (reading 'match')" on it. Regular source maps with such mappings already threw. Index maps didn't, because their unmapped segments had the source "."; with that fixed in the previous commit, they started throwing too. The path is now only joined to a source that isn't null. The changeset no longer says that SourceMapGenerator.fromSourceMap() works on these maps: on index maps it still throws for another reason until #132 lands.
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
* Keep a null source for unmapped segments of index source maps IndexedSourceMapConsumer looked up every mapping's source in its section with ArraySet#at(mapping.source), even for a segment with only a generated column, whose source is null. at(null) returns undefined, because null >= 0, and util.computeSourceURL() turned that into ".". So eachMapping() gave those mappings the source ".", and SourceMapGenerator.fromSourceMap() threw on them: a source without an original line and column. * Accept code without an original position in SourceNode with a relative path SourceNode.fromStringWithSourceMap() joins its third argument, a relative path, to the source of every mapping. A mapping without an original position has a null source, and util.join() threw "Cannot read properties of null (reading 'match')" on it. Regular source maps with such mappings already threw. Index maps didn't, because their unmapped segments had the source "."; with that fixed in the previous commit, they started throwing too. The path is now only joined to a source that isn't null. The changeset no longer says that SourceMapGenerator.fromSourceMap() works on these maps: on index maps it still throws for another reason until #132 lands. * Check null entries in the new tests with deepStrictEqual These test files use the legacy node:assert. On Node 26 its deepEqual() lets a null in the expected array match any value, so expected entries like ['A', null] didn't check the null.
7rulnik
marked this pull request as ready for review
November 29, 2026 21:19
This was referenced Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the two bugs that #126 added todo tests for:
fromSourceMap()checkedsourceRoot !== nullbefore making each source relative to the sourceRoot.IndexedSourceMapConsumerhas nosourceRoot, so the check passed forundefined, andutil.relative()threwCannot read properties of undefined (reading 'replace'). That happened for every index map with sources. The rest of the generator checks!= null, and so does this now.sourceContentFor(source), which on anIndexedSourceMapConsumerthrows for a source without content unless asked to returnnull. It only asks about the consumer's own sources, so it now passestrueand getsnullfor those. For aBasicSourceMapConsumernothing changes: it already returnednullfor them.Tests: both todos from #126 now pass, and new tests cover a nested index map and the full index map below.
With #128 (names at index 0), #129 (unmapped segments) and #130 (
file) merged,fromSourceMap()now copies an index map exactly. A new test, added after mergingmaininto this branch, covers a map with unmapped segments, names at index 0, afileand a source without content. It asserts withdeepStrictEqual, and so do thenullchecks in the other tests here: on Node 26 the legacyassert.deepEqual()lets anullin the expected array match any value.applySourceMap()andSourceNode.fromStringWithSourceMap()have the same missing-content bug, fixed in #131.