Closed urish closed 6 years ago
I thought applying string processing on the files directly was faster? Or am I missing something?
It is certainly faster for applying the types (you don't have to parse the source code again, etc). But for the instrumentation, if you have a setup where you already use the TypeScript compiler (and it parses all your source files anyway), we can avoid double parsing by modifying the AST directly after the compiler reads the file but before it processes it.
Compiler transformers introduced in Microsoft/TypeScript#13764, and they seem to allow modifying the AST directly rather than updating the source code. This should improve performance, though, it seems like we will have to rewrite the instrumentor to support that.
Seems like both awesome-typescript-loader and ts-loader have support for custom transformers.
Here are a few example of what a custom transformer looks like (source):
https://github.com/longlho/ts-transform-system-import https://github.com/longlho/ts-transform-img https://github.com/longlho/ts-transform-react-intl https://github.com/longlho/ts-transform-css-modules-transform