我正在编写一个babel.transform
用于检测导出模块的函数,例如默认和命名导出。
对于默认导出和命名导出,我使用以下 babel 类型进行检测:
ExportDefaultDeclaration
ExportNamedDeclaration
但我想支持module.exports
上面指定的任何一种类型都没有检测到的。
我试过DeclareModuleExports
没有运气的类型。
任何人都知道我应该使用什么类型?
我正在编写一个babel.transform
用于检测导出模块的函数,例如默认和命名导出。
对于默认导出和命名导出,我使用以下 babel 类型进行检测:
ExportDefaultDeclaration
ExportNamedDeclaration
但我想支持module.exports
上面指定的任何一种类型都没有检测到的。
我试过DeclareModuleExports
没有运气的类型。
任何人都知道我应该使用什么类型?
对此没有 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
}
},