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