【问题标题】:How to create an instanceof AST node using typescript compiler API如何使用 typescript 编译器 API 创建 AST 节点的实例
【发布时间】:2018-11-14 16:45:22
【问题描述】:

我想用 typescript 编译器 API 表示 typescript 代码“MyObj instanceOf MyClass”。

我尝试使用createBinary API 如下:

ts.createBinary(leftExpression,ts.SyntaxKind.InstanceOfKeyword, rightExpression);

如何创建rightExpression

【问题讨论】:

    标签: typescript typescript-compiler-api


    【解决方案1】:

    左右表达式是标识符,所以可以使用createIdentifier方法:

    const binaryExpression = ts.createBinary(ts.createIdentifier("MyObj"),
        ts.SyntaxKind.InstanceOfKeyword,
        ts.createIdentifier("MyClass"));
    

    【讨论】:

      猜你喜欢
      • 2018-01-24
      • 2012-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-24
      • 1970-01-01
      • 2021-12-20
      • 2019-09-18
      相关资源
      最近更新 更多