Repository navigation
Fix typings that don't match runtime, without breaking changes - #117
Merged
Merged
Conversation
SourceMapConsumer: - The constructor accepts a numeric version, null sourcesContent entries and a missing names array (new RawSourceMapInput), index maps (RawIndexMap, RawSection), JSON strings, and the sourceMapUrl argument. - Declare the static fromSourceMap. - allGeneratedPositionsFor takes an optional column and returns lastColumn. SourceMapGenerator: type the skipValidation and ignoreInvalidMapping options (SourceMapGeneratorOptions), also for fromSourceMap and SourceNode#toStringWithSourceMap. SourceNode: the constructor accepts nulls and chunk arrays, add and prepend accept nested arrays and SourceNodes and return the node, replaceRight accepts a RegExp or a replacer function, and children, line, column, source and name are declared. Return types that are wrong only in being non-nullable, or a string version, stay as they are: fixing them breaks callers. A comment on each says what happens at runtime. Part of #111 Refs #43 Refs #30 Refs #75
9 tasks
… callers A required lastColumn broke writing plain positions into the result array (push, concat, indexOf, unshift, splice, reassigning). Make it optional. Returning the node from add and prepend broke void-returning callbacks like (chunk: string): void => node.add(chunk). Keep void and note the runtime return value instead. The new SourceNode members (children, line, column, source, name) made a SourceNode typed by another copy of the package, such as an older source-map-js or source-map 0.6, unassignable to this one. Drop them.
7rulnik
marked this pull request as ready for review
November 19, 2026 12:02
This was referenced Nov 19, 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.
Part of #111. Fixes every mismatch between
source-map.d.tsandlib/that can be fixed without breaking anyone's build. Onlysource-map.d.tschanges.Fixed
SourceMapConsumer
RawSourceMapInput:versioncan be a number,sourcesContentcan havenullentries, andnamescan be left out (Sass does that). Sonew SourceMapConsumer(JSON.parse(map))with"version": 3compiles now, which is what Bug: RawSourceMap.version type should be number, not string #43 is about. It also covers the input half of Change sourcesContent type to allow null values #75.RawIndexMapandRawSection), JSON strings, and the secondsourceMapUrlargument.SourceMapConsumer.fromSourceMapis declared.allGeneratedPositionsFortakes an optionalcolumn, as the README documents, and its results includelastColumn?: number | null. It's optional so that callers can still put plain{ line, column }positions into the array.SourceMapGenerator
skipValidationandignoreInvalidMappingare typed (newSourceMapGeneratorOptions), for the constructor,fromSourceMapandSourceNode#toStringWithSourceMap.SourceNode
nulls and chunk arrays. The README's ownnew SourceNode(null, null, null, [a, b, c])didn't compile.addandprependaccept nested arrays andSourceNodes.replaceRightaccepts a RegExp (the README example uses/\s*$/) or a replacer function.Not fixed: needs a breaking change
Tracked in #118 for the next major. These are return types. Making them accurate breaks code that uses the values as they're typed now. Each one has a comment saying what happens at runtime.
originalPositionForreturnsnulls when there's no mapping (originalPositionFor has incorrect typing #30). For example, Vue'smapLinesin compiler-sfc checks onlysource == nulland then passes.linewhere anumberis required, so this fix would fail Vue's typecheck.generatedPositionForand theSourceNode#walkcallback returnnulls too.toJSON()returnsversionas a number andsourcesContentwithnulls: the output halves of Bug: RawSourceMap.version type should be number, not string #43 and Change sourcesContent type to allow null values #75. Entries ofSourceMapConsumer#sourcesContentcan benullas well.Testing
Checked outside the repo, nothing added to it:
allGeneratedPositionsForresult (push,concat,indexOf,unshift,splice), wrapadd/prependinvoid-returning callbacks, override methods with the old return types, or mix in aSourceNodeorSourceMapConsumertyped by another copy of the package (the old typings, which are also what source-map 0.6 ships).lib/with assertions, including the runtime behavior the new comments describe.@vue/compiler-sfc3.5.45 compile against both withskipLibCheck: false.pnpm format:checkpasses, the tests pass.