Repository navigation
Conversation
ECMA-426 reads `sourcesContent` with GetOptionalListOfOptionalStrings: an entry that isn't a string or null is an optional error, read as null when the consumer doesn't throw (https://tc39.es/ecma426/#sec-GetOptionalListOfOptionalStrings). The consumer kept the value: sourceContentFor() returned it, hasContentsOfAllSources() counted it as content, and SourceMapGenerator.fromSourceMap() copied it to its output. The consumer copies the array only when it has such an entry, so for a valid map `sourcesContent` is still the caller's array. Undefined entries, which JSON can't produce, stay undefined.
Owner
Author
|
Closing: this would make other calls throw for maps that work today. In an index map, |
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
#134 and #138 read them as null, as the spec does, and were closed because other calls then throw for maps that work today. Two lock-in tests now pin the current results, and the calls that would throw: - a non-string sourcesContent entry is returned by sourceContentFor(), also on an index map, where null would make it throw; - a non-string file is kept, and applySourceMap() without a source file runs, where null would make it throw. Each fails with its closed PR's change and says that the fix needs a major release.
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
* Mark the conformance todos that need a major release Ten of the conformance todos can't be fixed without changing results for source maps that work today, or making some of them throw. They're now created with major(reason), which makes the test a todo whose reason starts with "needs a major release:" and says what the fix would change. The test runner prints it next to the test. The other four todos are fixed without breaking anyone in their own PRs. * Say which changes need a major release The header said a fix needs a major release when it changes results for source maps that work today. But the patch fixes change results for invalid maps that work today too. It now names the three reasons: results change for valid maps, maps that load today would throw, or leniency that tools rely on goes away. * Mark the file and sourcesContent todos as needing a major release Reading a `file` or a `sourcesContent` entry that isn't a string as null makes other calls throw for maps that work today: - applySourceMap() without a source file throws "Both were omitted" for a consumer whose `file` is null, where it ran with `file: 42`. - An index map's sourceContentFor() throws for a source whose content is null, unless asked to return null, where it returned the value. So both wait for a major release too, and only the two todos for negative positions are left for patch fixes. * Lock in non-string file and sourcesContent entries until the major #134 and #138 read them as null, as the spec does, and were closed because other calls then throw for maps that work today. Two lock-in tests now pin the current results, and the calls that would throw: - a non-string sourcesContent entry is returned by sourceContentFor(), also on an index map, where null would make it throw; - a non-string file is kept, and applySourceMap() without a source file runs, where null would make it throw. Each fails with its closed PR's change and says that the fix needs a major release.
This was referenced Nov 29, 2026
7rulnik
added a commit
that referenced
this pull request
Nov 29, 2026
* Read a sourcesContent entry that isn't a string as null ECMA-426 reads `sourcesContent` with GetOptionalListOfOptionalStrings: an entry that isn't a string or null is an optional error, read as null when the consumer doesn't throw (https://tc39.es/ecma426/#sec-GetOptionalListOfOptionalStrings). The consumer kept the value: sourceContentFor() returned it, hasContentsOfAllSources() counted it as content, and SourceMapGenerator.fromSourceMap() copied it to its output. #138 made the same change and was closed, because an index map's sourceContentFor() then threw for such a source. #142 fixed that, so this ships as a patch: - The consumer copies the array only when it has such an entry, so for a valid map `sourcesContent` is still the caller's array. It reads the array by index and calls none of its methods. Undefined entries, which JSON can't produce, stay undefined. - SourceMapConsumer.fromSourceMap(generator) reads a generator's content the same way, for content set with setSourceContent(). - The conformance todo passes, so its major() mark and the lock-in test that pinned the old result are gone. * Find a source by any name, and copy sourcesContent without its constructor - An index map with sources ['1'] and sourcesContent [1] returned 1 from sourceContentFor(1). With the entry read as null, the lookup goes on to check whether the map has the source, and that check only took strings, so it threw. It now checks any name, and only falls back to the original error when the check itself throws: for a source that isn't a string, with a sourceRoot, util.relative() throws a TypeError. - Array.prototype.slice.call() used the array's constructor through Symbol.species, so a caller's array with `constructor = null` made the consumer throw, and a species that returns a plain object broke hasContentsOfAllSources(). The copy is now a plain array, holes kept. The intro of conformance section 2 now says how the library reads each of `file`, `sources`, `sourcesContent` and `names`. * Look past index map sections whose lookup throws A section with a sourceRoot throws a TypeError when it looks up a source that isn't a string: util.relative() takes a string. With a sourcesContent entry like 1 read as null, the lookup now goes on past the section that has it, so sourceContentFor(1) could reach such a section and throw where it returned 1 before: - sections [{sources: ['1'], sourcesContent: [1]}, {sourceRoot: 'src', sources: ['other.js'], sourcesContent: [null]}]; - the same sections the other way round, without sourcesContent in the second: the membership check stopped at the first section's error. IndexedSourceMapConsumer#sourceContentFor() now skips a section whose lookup throws, and hasSource() treats a throwing lookup as "not this section". If no section has the source, it throws the first section's error, also with nullOnMissing, as it did before. Without such an error, it works as before, including the cheap nullOnMissing path. Compared with main on 19,602 lookups in index maps of two or three sections, some nested, with sourceRoots and string, null, number and missing content, and string, number, null, undefined, object and String queries: no new throws, the same error type and message wherever both throw, and no change for maps without a non-string entry and a string query. * Say that an invalid sourceRoot can make a section's lookup throw too A sourceRoot that util.relative() can't take, such as 0 or false, makes it throw for any source, not only for a source that isn't a string.
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 conformance todo "a
sourcesContententry that is not a string or null becomes null".ECMA-426 reads
sourcesContentwithGetOptionalListOfOptionalStrings: an entry that isn't a string ornullis an optional error, and is read asnullwhen the consumer doesn't throw (https://tc39.es/ecma426/#sec-GetOptionalListOfOptionalStrings).BasicSourceMapConsumerkept the value as it was:sourceContentFor()returned it.hasContentsOfAllSources()counted it as content.SourceMapGenerator.fromSourceMap()copied it to its output.Now such an entry is
null, sosourceContentFor()returnsnullfor it, the same as for a source without content. It doesn't throw, even withoutreturnNullOnMissing.Why it's not breaking: only maps with such an entry change, and those are invalid. The consumer copies the array only when it has one, so for a valid map
consumer.sourcesContentis still the caller's array; a test pins that.undefinedentries, which JSON can't produce, stayundefined. Index maps get the fix through their sections' consumers.Tests: the todo now passes. New tests cover
sourcesContent,sourceContentFor()withoutreturnNullOnMissing,hasContentsOfAllSources(), and keeping the caller's array.Benchmark: the constructor now checks each
sourcesContententry once.pnpm bench --cases parse --fixtures all(the case includes the constructor), againstmain:No change outside the noise.
This changes the conformance test right above the
fileone that #134 changes, and #136 changes the one below, so whichever lands later needs a small rebase.