U Avalos
U Avalos

Reputation: 6798

Generate javascript from typescript AST?

I'm using the built-in parser to generate the AST from source code:

const ts = require('typescript')
//...
const ast = ts.createSourceFile(filename, fs.readFileSync(filename).toString(), ts.ScriptTarget.ES6, true)

Given an arbitrary node in the tree, how do I generate the typescript from the node?

Upvotes: 0

Views: 971

Answers (1)

basarat
basarat

Reputation: 275867

an arbitrary node in the tree, how do I generate the typescript from the node

You cannot in the current version of the compiler. The only node that supports generation is SourceFile.

There is talk to make the emitter more split (transformer based like the Babel emitter).

Upvotes: 1

Related Questions