0

我正在编写一个babel.transform用于检测导出模块的函数,例如默认和命名导出。

对于默认导出和命名导出,我使用以下 babel 类型进行检测:

  • ExportDefaultDeclaration

  • ExportNamedDeclaration

但我想支持module.exports上面指定的任何一种类型都没有检测到的。

我试过DeclareModuleExports没有运气的类型。

任何人都知道我应该使用什么类型?

4

1 回答 1

1

对此没有 AST 类型。探索此类事物的好工具是 ASTExplorer。这是您的代码示例: http: //astexplorer.net/#/gist/46c661d47a6e789437d197ba8d7b1ca8/559ef96e774151f76e2b0e7ff36dc9685d574939

您必须检测对名为 的变量的任意访问module,然后查找名为 的属性exports。例如,在 Babel 插件中,您可能有一个访问者正在寻找

MemberExpression(path) {
  if (
   path.get("object").isIdentifier({name: "module"}) &&
   path.get("property").isIdentifier({name: "exports"})
  ) {
    // whatever
  }
},
于 2018-03-11T21:08:22.150 回答