TypeScript -> AST -> TypeScript

cape picture cape · Oct 7, 2016 · Viewed 7.5k times · Source

Is there a way to parse a TypeScript file to an AST, modify the AST, and parse it then back to TypeScript as the tools Esprima + Escodegen are able to?

Important is that I do NOT want to compile/transpile the TypeScript code first into JavaScript.

Answer

Andzej Maciusovic picture Andzej Maciusovic · Dec 23, 2017

Yes, with Typescript 2.x you can transform ast. Here is a good blog post about it http://blog.scottlogic.com/2017/05/02/typescript-compiler-api-revisited.html. In the official typescript wiki it is not well documented yet.