Commit fba2006
committed
use built-in source map support in node v20
The @cspotcode/source-map-support module does not function properly on
Node 20, resulting in incorrect stack traces. Fortunately, the built-in
source map support in Node is now quite reliable. This does have the
following (somewhat subtle) changes to error output:
- When a call site is in a method defined within a constructor function,
it picks up the function name *as well as* the type name and method
name. So, in tests where a method is called and throws within the a
function constructor, we see `Foo.Foo.bar` instead of `Foo.bar`.
- Call sites displays show filenames instead of file URLs.
- The call site display puts the `^` character under the `throw` rather
than the construction point of the error object. This is closer to how
normal un-transpiled JavaScript behaves, and thus somewhat
preferrable, but isn't possible when all we have to go on is the Error
stack property, so it is a change.
I haven't been able to figure out why exactly, but the call sites appear
to be somewhat different in the repl/eval contexts as a result of this
change. It almost seems like the @cspotcode/source-map-support was
applying source maps to the vm-evaluated scripts, but I don't see how
that could be, and in fact, there's a comment in the code stating that
that *isn't* the case. But the line number showing up in an Error.stack
property is `1` prior to this change (matching the location in the TS
source) and is `2` afterwards (matching the location in the compiled
JS).
An argument could be made that specific line numbers are a bit
meaningless in a REPL anyway, and the best approach is to just make
those tests accept either result. One possible approach to provide
built-in source map support for the repl would be to refactor the
`appendCompileAndEvalInput` to diff and append the *input* TS, and
compile within the `runInContext` method. If the transpiled code was
prepended with `process.setSourceMapsEnabled(true);`, then Error stacks
and call sites would be properly source mapped by Node internally.1 parent 04d9419 commit fba2006
File tree
4 files changed
+47
-51
lines changed- src
- test
4 files changed
+47
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
| 694 | + | |
694 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
695 | 701 | | |
696 | 702 | | |
697 | 703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
52 | 56 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 57 | + | |
60 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
98 | | - | |
| 101 | + | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 185 | + | |
191 | 186 | | |
192 | 187 | | |
193 | 188 | | |
| |||
198 | 193 | | |
199 | 194 | | |
200 | 195 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 196 | + | |
207 | 197 | | |
208 | 198 | | |
209 | 199 | | |
| |||
214 | 204 | | |
215 | 205 | | |
216 | 206 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 207 | + | |
222 | 208 | | |
223 | 209 | | |
224 | 210 | | |
| |||
309 | 295 | | |
310 | 296 | | |
311 | 297 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
318 | 301 | | |
319 | 302 | | |
320 | 303 | | |
321 | 304 | | |
322 | 305 | | |
323 | 306 | | |
324 | 307 | | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
331 | 311 | | |
332 | 312 | | |
333 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
16 | 32 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 33 | + | |
0 commit comments