Correctly update module.exports.default of typeof helper (#12858)

This commit is contained in:
Nicolò Ribaudo
2021-02-23 02:59:03 +01:00
committed by GitHub
parent feb78c7735
commit c4320a6019
13 changed files with 106 additions and 20 deletions

View File

@@ -287,15 +287,14 @@ function buildRuntimeRewritePlugin(runtimeName, helperName) {
function addDefaultCJSExport({ template }) {
return {
visitor: {
Program: {
AssignmentExpression: {
exit(path) {
path.pushContainer(
"body",
template.statements.ast`
module.exports.default = module.exports;
module.exports.__esModule = true;
`
);
if (path.get("left").matchesPattern("module.exports")) {
path.insertAfter(template.expression.ast`
module.exports.default = module.exports,
module.exports.__esModule = true
`);
}
},
},
},