13

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.

4
  • 1
    Might github.com/Microsoft/TypeScript/wiki/… be what you're after? Commented Oct 7, 2016 at 13:00
  • @JoeClay The problem is that there is apparently no way to modify the AST of the .ts file with the public API. I think this is what is discussed also here in #7580. Am I right? Commented Oct 13, 2016 at 14:49
  • Looks like it ): You might have to do some digging through the private API if you want to achieve this right now, by the looks of things. Commented Oct 13, 2016 at 15:50
  • In astexplorer.net you could see your AST (under menu 'acorn' choose 'typescript') Commented Nov 7, 2018 at 10:18

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.