Ensure that the wildcard interop is used with re-export + default. (#8316)

This commit is contained in:
Logan Smyth 2018-07-14 12:49:31 -07:00 committed by GitHub
parent 62ee1adc85
commit 935533cff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 4 deletions

View File

@ -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;

View 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';

View 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;