Repository navigation
Keep a null source for unmapped segments of index source maps - #129
Merged
Merged
Conversation
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.
7rulnik
force-pushed
the
fix/index-map-unmapped-source
branch
from
November 29, 2026 20:29
a830143 to
6e8dff9
Compare
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, and util.join() throws on a null source. A mapping with a negative original line or column now has a null source, so such maps, which loaded before, started throwing "Cannot read properties of null (reading 'match')" here. The path is now only joined to a source that isn't null. #129 makes the same change for unmapped segments. New consumer tests check these maps without accepting a throw: eachMapping(), originalPositionFor() and allGeneratedPositionsFor() for a negative line and a negative column, the line and column counting for the next segment, and SourceNode with a relative path.
…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.
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
force-pushed
the
fix/index-map-unmapped-source
branch
from
November 29, 2026 21:00
874bfd9 to
d41ed8f
Compare
7rulnik
marked this pull request as ready for review
November 29, 2026 21:12
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
* Fix SourceMapGenerator.fromSourceMap() on index source maps - 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. * Say which index maps fromSourceMap() threw on An index map without sources, such as one with no sections, didn't throw. * 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. * Test fromSourceMap() on an indexed map with unmapped code, names and a file With #128, #129 and #130 merged, fromSourceMap() copies such a map exactly: the unmapped segments stay unmapped, the names at index 0 stay, the source without content gets null, and the file is kept.
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
… or column (#137) * Drop the original position of a mapping with a negative original line or column ECMA-426 makes a negative original line or column an optional error, and keeps the mapping without its original position when the consumer doesn't throw (https://tc39.es/ecma426/#sec-DecodeMappingsField). The consumer kept the position: originalPositionFor() returned line 0 or a negative column, and SourceMapGenerator.fromSourceMap() threw "Invalid mapping" on it. As in the spec, the mapping keeps its name, and the decoded line and column still count for the next segment. Only invalid source maps have a negative original line or 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, and util.join() throws on a null source. A mapping with a negative original line or column now has a null source, so such maps, which loaded before, started throwing "Cannot read properties of null (reading 'match')" here. The path is now only joined to a source that isn't null. #129 makes the same change for unmapped segments. New consumer tests check these maps without accepting a throw: eachMapping(), originalPositionFor() and allGeneratedPositionsFor() for a negative line and a negative column, the line and column counting for the next segment, and SourceNode with a relative path.
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 a bug that #127 added a todo test for.
IndexedSourceMapConsumer#_parseMappingslooked up every mapping's source in its section withArraySet#at(mapping.source), even for a segment with only a generated column, whose source isnull.at(null)returnsundefined, becausenull >= 0, andutil.computeSourceURL()turned that into".". So:eachMapping()gave those mappings the source".", withnulloriginal line and column.SourceMapGenerator.fromSourceMap()threworiginal.line and original.column are not numberson them. That happens before thesourceRootbug from Add todo tests for two SourceMapGenerator.fromSourceMap bugs #126, so a bundle with unmapped code fails here first."."entry.Now a mapping without a source keeps a
nullsource and adds nothing to the set.SourceNodewith a relative path.SourceNode.fromStringWithSourceMap(code, consumer, relativePath)joins the path to every mapping's source, andutil.join()throws onnull:Cannot read properties of null (reading 'match'). Regular source maps with unmapped code already threw there. Index maps didn't, only because of the"."source, so this fix alone would have made them start throwing. The path is now only joined to a source that isn'tnull, which fixes both. #137 makes the same change, line for line.Tests: the todo from #127 now passes, and it also covers a nested index map. A new
SourceNodetest covers a relative path with a regular and an index map; it asserts withdeepStrictEqual, since on Node 26 the legacyassert.deepEqual()lets anullin the expected array match any value. Once this and thefromSourceMap()fix are both in, I'll add afromSourceMap()test with unmapped segments to whichever lands second.No benchmark: the per-mapping loop of index maps now skips the lookup for unmapped segments and is otherwise unchanged.