Ensure that the wildcard interop is used with re-export + default. (#8316)
This commit is contained in:
parent
62ee1adc85
commit
935533cff3
@ -246,12 +246,18 @@ function getModuleMetadata(
|
||||
});
|
||||
|
||||
for (const metadata of sourceData.values()) {
|
||||
if (metadata.importsNamespace.size > 0) {
|
||||
metadata.interop = "namespace";
|
||||
continue;
|
||||
}
|
||||
let needsDefault = false;
|
||||
let needsNamed = false;
|
||||
|
||||
if (metadata.importsNamespace.size > 0) {
|
||||
needsDefault = true;
|
||||
needsNamed = true;
|
||||
}
|
||||
|
||||
if (metadata.reexportAll) {
|
||||
needsNamed = true;
|
||||
}
|
||||
|
||||
for (const importName of metadata.imports.values()) {
|
||||
if (importName === "default") needsDefault = true;
|
||||
else needsNamed = true;
|
||||
|
||||
6
packages/babel-plugin-transform-modules-commonjs/test/fixtures/interop/export-all/input.js
vendored
Normal file
6
packages/babel-plugin-transform-modules-commonjs/test/fixtures/interop/export-all/input.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
// The fact that this exports both a normal default, and all of the names via
|
||||
// re-export is an edge case that is important not to miss. See
|
||||
// https://github.com/babel/babel/issues/8306 as an example.
|
||||
import _default from 'react';
|
||||
export default _default;
|
||||
export * from 'react';
|
||||
25
packages/babel-plugin-transform-modules-commonjs/test/fixtures/interop/export-all/output.js
vendored
Normal file
25
packages/babel-plugin-transform-modules-commonjs/test/fixtures/interop/export-all/output.js
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _exportNames = {};
|
||||
exports.default = void 0;
|
||||
|
||||
var _react = babelHelpers.interopRequireWildcard(require("react"));
|
||||
|
||||
Object.keys(_react).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _react[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
// The fact that this exports both a normal default, and all of the names via
|
||||
// re-export is an edge case that is important not to miss. See
|
||||
// https://github.com/babel/babel/issues/8306 as an example.
|
||||
var _default2 = _react.default;
|
||||
exports.default = _default2;
|
||||
Loading…
x
Reference in New Issue
Block a user