I'm trying to work with Typescript Compiler API to create a tool for merging typescript files. I'd like to know is there a way to:
I have read documentation on Compiler API, but it seems to cover only read-only uses-cases of working with AST, while I'm more interesting in modifying source files.
Thanks for any help in advance.
Here a simple example using transformations to walk and transform the AST and Printer to print the transformed AST back to another source file:
this is very simple one:
https://typescript-api-playground.glitch.me/#example=Simple%20Transformation
This is another a little bit complex than first one:
https://typescript-api-playground.glitch.me/#example=Transformation%202
And a last one : https://typescript-api-playground.glitch.me/#example=Transformation%203
You can modify and run the code again and create a URL with an example too share here in case you get stuck .
Also an easier approach to compiler API could be ts-simple-ast project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With