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

Question: ts-creator & TypeScript transformer #27

Open
LukasMachetanz opened this issue May 5, 2020 · 2 comments
Open

Question: ts-creator & TypeScript transformer #27

LukasMachetanz opened this issue May 5, 2020 · 2 comments

Comments

@LukasMachetanz
Copy link

Hi.

Currently I am fiddling around writing my own custom typescript transformer. In this context I also discovered this package.

I am wondering how or if ts-creator could be used to e.g. insert a node into the ast.

I understand that I get the ast representation with the creator function of the package. But I do not understand how I can use the returned string directly to e.g. insert a node into the ast.

Currently I just use the package as an helper to see what the exact ast representation would be. But it would be really cool if this string could somehow be used directly.

Therefore I just wanted to ask if someone has an idea. I appreciate any help.

Thanks in advance,
Lukas

@Kingwl
Copy link
Member

Kingwl commented Aug 27, 2020

Hi. Sorry for the delay.

I'm not sure I 100% catch your point.

You cannot insert a node into the ast because the AST is immutable for the source code.

Maybe you can construct another source file(code) and rewrite them into the original file.

And BTW: You can use https://ts-ast-viewer.com/ to explorer the ast. There's more infos.

Thanks for your attention!

@distante
Copy link

distante commented Oct 5, 2021

It is possible to replace a node when writing a transformer @Kingwl: https://github.com/madou/typescript-transformer-handbook#replacing-a-node

Pd: I currently have the same question as @LukasMachetanz has when I found this issue.

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