LeDDGroup / typescript-transform-paths

Transforms module resolution paths using TypeScript path mapping and/or custom paths
MIT License
478 stars 25 forks source link

getStatementTags | Avoid unnecessary TS debugger statement invocations #180

Closed shlomo-artlist closed 7 months ago

shlomo-artlist commented 1 year ago

TL;DR Allow running tsc in debug mode when using typescript-transform-paths plugin.

Full Explanation: Sometimes it makes sense to run tsc in debug mode. For example in my case, we run tsc + start server in watch mode e.g. tsc-watch --compiler ttypescript/bin/tsc --onSuccess 'npm start'. And if we run this in a debug session like on VSCode's debug terminal, it means we run both tsc and our sever in debug mode.

The problem is that when typescript throws errors on internal assertions it's also putting a "debugger;" statement right before it throws an error. Screenshot 2023-08-27 at 16 33 41

There's a block of code in this package (typescript-transform-paths) that wraps such TS errors in a try/catch. That causes our servers to get stuck (repeatedly) on a breakpoint when debugging in watch mode.

So, I've identified the root cause of these cases, and used an if condition to prevent the TS call altogether, instead of the try/catch. I left the try/catch though just to be on safe side, cause there might be some other cases which I've missed.

What is the case that raises the TS error? If a NodeObject is in position -1 you can't call getFullText on it. Screenshot 2023-08-27 at 16 38 36 Screenshot 2023-08-27 at 16 41 56