You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a ts-patch transformer to transform some code before it's executed.
The problem is the tool I'm trying to call (like much of npm nowadays...) expects an async call.
So I start adding await before the call, and moving up in my code transforming functions to async as I go.
And I hit a wall when I get down to the level of ts-patch / the transformer itself... It expects sync functions, and won't do await / deal with any kind of async function.
Is there any way to get this to work? Some kind of solution I'm not considering?
Hello @arthurwolf
The problem is that typescript compiler api is completely synchronous at that moment, that means that transformers can't return a Promise<ts.Node>, only ts.Node
If you need some data that is asynchronous - you should wait for this data before typescript compilation process will be called
Activity
artem1458 commentedon Jan 13, 2025
Hello @arthurwolf
The problem is that typescript compiler api is completely synchronous at that moment, that means that transformers can't return a
Promise<ts.Node>, onlyts.NodeIf you need some data that is asynchronous - you should wait for this data before typescript compilation process will be called
You can also check PluginCompiler.ts and ProgramStorage.ts maybe it will help
Also you can share more detailed example of what you're trying to achieve, and maybe I can help find a solution