Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide for writing AST transformers #218

Closed
mohsen1 opened this issue Jan 14, 2017 · 9 comments
Closed

Guide for writing AST transformers #218

mohsen1 opened this issue Jan 14, 2017 · 9 comments

Comments

@mohsen1
Copy link

mohsen1 commented Jan 14, 2017

Now that microsoft/TypeScript#5595 is done, I'm assuming there is new API in LS that allows writing TypeScript to TypeScrtipt syntax transformers. Right now I'm trying to figure out how to write an TS to TS transformer function

@basarat
Copy link
Owner

basarat commented Jan 15, 2017

No. There is no API like that on master yet. 🌹❤

@basarat basarat closed this as completed Jan 15, 2017
@mohsen1
Copy link
Author

mohsen1 commented Jan 15, 2017

Thanks for clearing that out! I thought microsoft/TypeScript#5595 means now it's possible to write AST transformers using TS API. Do you know the ticket that tracks that issue?

@basarat
Copy link
Owner

basarat commented Jan 16, 2017

For new syntax one needs additions to the parser + checker + emitter. The transformer only exist in the emitter.

Do you know the ticket that tracks that issue

Nope :( 🌹

@mohsen1
Copy link
Author

mohsen1 commented Jan 17, 2017

I think this is the issue: microsoft/TypeScript#10786

@basarat
Copy link
Owner

basarat commented Jan 17, 2017

@mohsen1 thanks. I've subscribed. But it is just pretty printing the AST, not rewriting it. You can get the AST today as well but then you have the write the complete emitter. That issues doesn't change that fact. You still can't plugin to the transformers 🌹

@mohsen1
Copy link
Author

mohsen1 commented Jan 17, 2017

If my transformer output standard typescript ast then I should be able to use existing emitter. No?

@basarat
Copy link
Owner

basarat commented Jan 17, 2017

Yes. there is an emitFile function in emitter.ts that is public last I checked 🌹

@basarat
Copy link
Owner

basarat commented Feb 12, 2017

Language service host to get custom transformer support : microsoft/TypeScript#13940 🌹

@cancerberoSgx
Copy link

Here there are three working examples of using transformation API among other things: https://typescript-api-playground.glitch.me/.

BTW you can modify the code and run it again, have intellisense, etc. ...like a TypeScript Compiler API Playground. I'm planning to put examples of different APis and libraries around TS compiler there hope it help newcomers - wouldn't be great to have similar tool to "describe" the API ? I've been inspired by monaco-editor playground which provided fast learning curve with its playground: https://microsoft.github.io/monaco-editor/playground.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants