Parser
SourceCode ~~ scanner ~~> Token Stream ~~ parser ~~> ASTProgramによる使用例
Program ->
CompilerHost.getSourceFile ->
(global function parser.ts).createSourceFile ->
Parser.parseSourceFileサンプルの使用法
import * as ts from "ntypescript";
function printAllChildren(node: ts.Node, depth = 0) {
console.log(new Array(depth + 1).join('----'), ts.formatSyntaxKind(node.kind), node.pos, node.end);
depth++;
node.getChildren().forEach(c=> printAllChildren(c, depth));
}
var sourceCode = `
var foo = 123;
`.trim();
var sourceFile = ts.createSourceFile('foo.ts', sourceCode, ts.ScriptTarget.ES5, true);
printAllChildren(sourceFile);最終更新