Use the correct source when skipping trivia #29555
Merged
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.
A custom
SourceMapSource
can optionally provide its ownskipTrivia
function. If this is not provided then the compiler will use the default
function designed for TypeScript source files.
Previously, when calling this default function we were passing the current
sourceMapSource
rather than the specifiedsource
whose trivia needsto be skipped. This resulted in the
pos
being incorrectly calculated forexternal source files that need mapping.
Side note:
There are actually two possible constructors available for creating
SourceMapSource
objects. One of them defaults to an identity functionfor the
skipTrivia
function if it is not provided (seehttps://github.com/Microsoft/TypeScript/blob/49689894d747714d6b2b8461b9033020efec9625/src/compiler/utilities.ts#L6972-L6976)
and the other one leaves the
skipTrivia
fieldundefined
(seehttps://github.com/Microsoft/TypeScript/blob/5fc8f1dd801dbacfe7e2d624f80b7a6a3868d180/src/services/services.ts#L776-L797)
Unfortunately, it appears that the second of these two constructors is the
one available when importing the "typescript" module in node.js code.
Fixes #