'module.exports' 的 Babel 类型
Babel Type for 'module.exports'
我正在编写一个函数,该函数使用 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
}
},
我正在编写一个函数,该函数使用 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
}
},