11

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:

  1. Change AST after it was produced by parsing .ts file.
  2. Serialize changed AST back to .ts file

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.

2
  • You want to modify them in place? Commented May 7, 2017 at 10:20
  • This is not very important - in place or create another tree and write it. I prefer to work at AST level hovewer, but right now i'm researching a solution based on working with text, inserting it at the locations computed from AST. Commented May 8, 2017 at 16:38

1 Answer 1

6

Change AST after it was produced by parsing .ts file. Serialize changed AST back to .ts file

Both of these are emitter plugins, you need to add a custom transformer. The best docs are still in the PR https://github.com/Microsoft/TypeScript/pull/13940 🌹

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.