astring icon indicating copy to clipboard operation
astring copied to clipboard

Support TSESTree input and TypeScript output

Open bjornharrtell opened this issue 1 year ago • 4 comments

Motivation

My own motivation is that I have a translation from a typed language (Java) to ESTree and generate JavaScript from that with astring, but would like to preseve some of the type information and target TypeScript instead.

Apparently eslint has made exensions to ESTree called TSESTree but AFAICT they only use it to transform TypeScript into AST not the other way round.

Expected behavior

A flag to output TypeScript.

bjornharrtell avatar May 09 '24 18:05 bjornharrtell

Hi @bjornharrtell, TypeScript support would indeed be interesting. Could you provide more insights regarding the TSESTree spec?

davidbonnet avatar Jun 13 '24 16:06 davidbonnet

I'm unable to find a formal spec extension to estree. The basis of the extensions seems to live at https://github.com/typescript-eslint/typescript-eslint/blob/8f08ee54d1389666b3f582853a8b6809d34d70f8/packages/ast-spec/src/ast-node-types.ts#L94-L171, which enumerates all the added node types.

At https://typescript-eslint.io/play you can supply TypeScript code and generate TSESTree, but not the other way round. I asked about a year ago and it was clarified that implementation to do TSESTree to TypeScript doesn't exist (yet), see https://github.com/typescript-eslint/typescript-eslint/discussions/7228.

bjornharrtell avatar Jun 20 '24 20:06 bjornharrtell

I see now that the code is very spec like fx. https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/src/special/TSTypeParameter/spec.ts

bjornharrtell avatar Jun 20 '24 20:06 bjornharrtell

see also https://github.com/TyrealHu/acorn-typescript btw

wooorm avatar Jun 21 '24 08:06 wooorm