Using the Typescript compiler API, I can do code transformations in my own scripts. But seeing how Typescript doesn't have a plugin/extension architecture, I can't find a way to integrate this into my build pipeline.
With Babel, you can integrate custom code transformation easily by packaging your code in a plugin and loading that plugin using the .babelrc
file.
So I'm asking if Typescript is providing anything like the Babel plugin system where you can write your visitor-pattern-based transformations and plug it straight into the default compiler?
Yes it has. This is the official documentation I recommend you to start with:
First one explain how to use the compiler, transverse in particular this example https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#user-content-creating-and-printing-a-typescript-ast
The other link introduce to the Language Service to create plugins (more oriented to text editors / IDEs)
If tose are too hard to grasp perhaps this si of help too: https://github.com/cancerberoSgx/typescript-plugins-of-mine (collection of small examples & utlities & tutorials on ts plugins, compiLer API, utilities and links to get started),
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