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

Generating a typescript file #701

Open
yxshv opened this issue Dec 29, 2023 · 6 comments
Open

Generating a typescript file #701

yxshv opened this issue Dec 29, 2023 · 6 comments

Comments

@yxshv
Copy link

yxshv commented Dec 29, 2023

I generated the ast of a typescript react code using acorn and acorn-ts plugin...
But i am not sure how to generate a tsx code, and not sure if its possible with astring

@yxshv yxshv closed this as completed Dec 30, 2023
@ayoreis
Copy link

ayoreis commented Jan 30, 2024

Did you find anything?

@wooorm
Copy link

wooorm commented Jan 30, 2024

how do you get types in the estree AST anyway?

@yxshv
Copy link
Author

yxshv commented Jan 30, 2024

how do you get types in the estree AST anyway?

using acorn-ts

@wooorm
Copy link

wooorm commented Jan 30, 2024

why use a package name that doesn’t exist 🤷‍♂️ that’s called acorn-typescript.

It will help you to parse typescript script into typeScript AST

A TypeScript AST sounds like it’s not estree.

@yxshv
Copy link
Author

yxshv commented Jan 30, 2024

A TypeScript AST sounds like it’s not estree.

yeah thats why I closed this issue...

you will probably have to write your own generator, if you want to use it

@davidbonnet
Copy link
Owner

Thanks for raising that up @yxshv. Being able to generate TypeScript annotations is indeed a useful feature to add. Astring being ESTree-based, it should use an extension of it, such as the one produced by Eslint's TypeScript parser, which adds typeAnnotation properties to existing ESTree node types, and extra nodes for type references and declarations.

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

No branches or pull requests

4 participants