Skip to content

Use the correct source when skipping trivia #29555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

petebacondarwin
Copy link
Contributor

A custom SourceMapSource can optionally provide its own skipTrivia
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 specified source whose trivia needs
to be skipped. This resulted in the pos being incorrectly calculated for
external 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 function
for the skipTrivia function if it is not provided (see
https://github.com/Microsoft/TypeScript/blob/49689894d747714d6b2b8461b9033020efec9625/src/compiler/utilities.ts#L6972-L6976)
and the other one leaves the skipTrivia field undefined (see
https://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 #

@msftclas
Copy link

msftclas commented Jan 24, 2019

CLA assistant check
All CLA requirements met.

@petebacondarwin petebacondarwin force-pushed the external-skip-trivia-fix branch from fb13da1 to ebd1662 Compare January 24, 2019 10:27
A custom `SourceMapSource` can optionally provide its own `skipTrivia`
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 specified `source` whose trivia needs
to be skipped. This resulted in the `pos` being incorrectly calculated for
external 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 function
for the `skipTrivia` function if it is not provided (see
https://github.com/Microsoft/TypeScript/blob/49689894d747714d6b2b8461b9033020efec9625/src/compiler/utilities.ts#L6972-L6976)
and the other one leaves the `skipTrivia` field `undefined` (see
https://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.
@petebacondarwin petebacondarwin force-pushed the external-skip-trivia-fix branch from ebd1662 to 331b9bc Compare January 24, 2019 10:28
@sheetalkamat sheetalkamat merged commit 61b95fe into microsoft:master Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants