Commit 331b9bc
committed
Use the correct source when skipping trivia
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.1 parent 2f6c65e commit 331b9bc
3 files changed
Lines changed: 37 additions & 2 deletions
File tree
- src
- compiler
- testRunner/unittests
- tests/baselines/reference/customTransforms
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4372 | 4372 | | |
4373 | 4373 | | |
4374 | 4374 | | |
4375 | | - | |
| 4375 | + | |
4376 | 4376 | | |
4377 | 4377 | | |
4378 | | - | |
| 4378 | + | |
4379 | 4379 | | |
4380 | 4380 | | |
4381 | 4381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
132 | 161 | | |
133 | 162 | | |
Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments