我可以修改来自打字稿服务的定义打字稿文件 (d.ts) 中的 ts.forEachChild() 以将另一个对象作为其参数传递吗?
Can I modify ts.forEachChild() in definition typescript files (d.ts) from typescript services to pass another object as its parameter?
我想获取链接到单个对象的定义打字稿文件的语法树(从根节点连接的树),但我无法通过 ts.forEachChild()
传递另一个对象。我怎样才能做到这一点?
P.S。 - 基本上我想最后得到一个抽象语法树对象。
据我所知,打字稿解析器提供了一个为您生成 AST 对象的函数。您可以查找更多详细信息 here. If you would like to traverse that ast you can use a project like tspoon (shameless plug) to write a visitor. You may also view how tspoon uses createSourceFile.
var ast = ts.createSourceFile('foo.ts', sourceCode, ts.ScriptTarget.ES5, true);
//carefule, parseDiagnostics is an internal key and may break in the future.
if (ast['parseDiagnostics'].length > 0) {
return ast['parseDiagnostics'];
}
// code which uses the AST
我想获取链接到单个对象的定义打字稿文件的语法树(从根节点连接的树),但我无法通过 ts.forEachChild()
传递另一个对象。我怎样才能做到这一点?
P.S。 - 基本上我想最后得到一个抽象语法树对象。
据我所知,打字稿解析器提供了一个为您生成 AST 对象的函数。您可以查找更多详细信息 here. If you would like to traverse that ast you can use a project like tspoon (shameless plug) to write a visitor. You may also view how tspoon uses createSourceFile.
var ast = ts.createSourceFile('foo.ts', sourceCode, ts.ScriptTarget.ES5, true);
//carefule, parseDiagnostics is an internal key and may break in the future.
if (ast['parseDiagnostics'].length > 0) {
return ast['parseDiagnostics'];
}
// code which uses the AST