Correctly update module.exports.default of typeof helper (#12858)
This commit is contained in:
@@ -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
|
||||
`);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
11
packages/babel-plugin-transform-runtime/test/regression.js
Normal file
11
packages/babel-plugin-transform-runtime/test/regression.js
Normal file
@@ -0,0 +1,11 @@
|
||||
it("module.exports.default is correctly updated", () => {
|
||||
const typeofHelper = require("@babel/runtime/helpers/typeof");
|
||||
|
||||
expect(typeof typeofHelper).toBe("function");
|
||||
expect(typeof typeofHelper.default).toBe("function");
|
||||
|
||||
typeofHelper();
|
||||
|
||||
expect(typeof typeofHelper).toBe("function");
|
||||
expect(typeof typeofHelper.default).toBe("function");
|
||||
});
|
||||
Reference in New Issue
Block a user