我如何使用 TypeScript 1.4 API 来编写一个 .ts 文件?
使用 TypeScript 1.4 API,我想从零生成一个 TypeScript 文件。我该怎么做?看起来可以使用 createNode 方法来创建树,但是我怎样才能让它渲染呢?
我目前拥有的:https://github.com/ctaggart/TsAst/blob/emit/app.ts
///<reference path='../TypeScript/built/local/typescript.d.ts' />
import ts = require('typescript');
export function main() {
var m = <ts.ModuleDeclaration>ts.createNode(ts.SyntaxKind.ModuleDeclaration);
var nm = <ts.Identifier>ts.createNode(ts.SyntaxKind.Identifier);
nm.text = "Blah"
m.name = nm;
var sf = <ts.SourceFile>ts.createNode(ts.SyntaxKind.SourceFile);
sf.statements = <ts.NodeArray<ts.ModuleElement>>[m];
console.log("file: "+sf.text); // sf.text is undefined :(
}
main();