astring icon indicating copy to clipboard operation
astring copied to clipboard

Generating a typescript file

Open yxshv opened this issue 1 year ago • 7 comments

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 avatar Dec 29 '23 19:12 yxshv

Did you find anything?

ayoreis avatar Jan 30 '24 10:01 ayoreis

how do you get types in the estree AST anyway?

wooorm avatar Jan 30 '24 10:01 wooorm

how do you get types in the estree AST anyway?

using acorn-ts

yxshv avatar Jan 30 '24 12:01 yxshv

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.

wooorm avatar Jan 30 '24 12:01 wooorm

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

yxshv avatar Jan 30 '24 12:01 yxshv

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.

davidbonnet avatar Feb 04 '24 15:02 davidbonnet