Generate javascript from typescript AST?

946 Views Asked by At

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?

1

There are 1 best solutions below

3
basarat On BEST ANSWER

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).