Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Babel plugin for Typescript?

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?

like image 821
Dave Avatar asked Oct 30 '22 01:10

Dave


1 Answers

Yes it has. This is the official documentation I recommend you to start with:

  • https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API
  • https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin

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),

like image 100
cancerbero Avatar answered Nov 09 '22 07:11

cancerbero