Quick fix for default import that also uses names. (#6282)
This commit is contained in:
parent
9159323b1e
commit
72da5e1d02
@ -158,8 +158,6 @@ function getModuleMetadata(programPath: NodePath) {
|
|||||||
|
|
||||||
child.get("specifiers").forEach(spec => {
|
child.get("specifiers").forEach(spec => {
|
||||||
if (spec.isImportDefaultSpecifier()) {
|
if (spec.isImportDefaultSpecifier()) {
|
||||||
if (data.interop === "none") data.interop = "default";
|
|
||||||
|
|
||||||
const localName = spec.get("local").node.name;
|
const localName = spec.get("local").node.name;
|
||||||
|
|
||||||
data.imports.set(localName, "default");
|
data.imports.set(localName, "default");
|
||||||
@ -175,8 +173,6 @@ function getModuleMetadata(programPath: NodePath) {
|
|||||||
} else if (spec.isImportNamespaceSpecifier()) {
|
} else if (spec.isImportNamespaceSpecifier()) {
|
||||||
const localName = spec.get("local").node.name;
|
const localName = spec.get("local").node.name;
|
||||||
|
|
||||||
data.interop = "namespace";
|
|
||||||
|
|
||||||
data.importsNamespace.add(localName);
|
data.importsNamespace.add(localName);
|
||||||
const reexport = localData.get(localName);
|
const reexport = localData.get(localName);
|
||||||
if (reexport) {
|
if (reexport) {
|
||||||
@ -192,10 +188,6 @@ function getModuleMetadata(programPath: NodePath) {
|
|||||||
|
|
||||||
data.imports.set(localName, importName);
|
data.imports.set(localName, importName);
|
||||||
|
|
||||||
if (importName === "default" && data.interop === "none") {
|
|
||||||
data.interop = "default";
|
|
||||||
}
|
|
||||||
|
|
||||||
const reexport = localData.get(localName);
|
const reexport = localData.get(localName);
|
||||||
if (reexport) {
|
if (reexport) {
|
||||||
localData.delete(localName);
|
localData.delete(localName);
|
||||||
@ -224,10 +216,6 @@ function getModuleMetadata(programPath: NodePath) {
|
|||||||
const importName = spec.get("local").node.name;
|
const importName = spec.get("local").node.name;
|
||||||
const exportName = spec.get("exported").node.name;
|
const exportName = spec.get("exported").node.name;
|
||||||
|
|
||||||
if (importName === "default" && data.interop === "none") {
|
|
||||||
data.interop = "default";
|
|
||||||
}
|
|
||||||
|
|
||||||
data.reexports.set(exportName, importName);
|
data.reexports.set(exportName, importName);
|
||||||
|
|
||||||
if (exportName === "__esModule") {
|
if (exportName === "__esModule") {
|
||||||
@ -237,6 +225,30 @@ function getModuleMetadata(programPath: NodePath) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const metadata of sourceData.values()) {
|
||||||
|
if (metadata.importsNamespace.size > 0) {
|
||||||
|
metadata.interop = "namespace";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let needsDefault = false;
|
||||||
|
let needsNamed = false;
|
||||||
|
for (const importName of metadata.imports.values()) {
|
||||||
|
if (importName === "default") needsDefault = true;
|
||||||
|
else needsNamed = true;
|
||||||
|
}
|
||||||
|
for (const importName of metadata.reexports.values()) {
|
||||||
|
if (importName === "default") needsDefault = true;
|
||||||
|
else needsNamed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsDefault && needsNamed) {
|
||||||
|
// TODO(logan): Using the namespace interop here is unfortunate. Revisit.
|
||||||
|
metadata.interop = "namespace";
|
||||||
|
} else if (needsDefault) {
|
||||||
|
metadata.interop = "default";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
local: localData,
|
local: localData,
|
||||||
source: sourceData,
|
source: sourceData,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
});
|
});
|
||||||
exports.default = void 0;
|
exports.default = void 0;
|
||||||
|
|
||||||
var _react = babelHelpers.interopRequireDefault(require("react"));
|
var _react = babelHelpers.interopRequireWildcard(require("react"));
|
||||||
|
|
||||||
var RandomComponent =
|
var RandomComponent =
|
||||||
/*#__PURE__*/
|
/*#__PURE__*/
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
define(["foo"], function (_foo) {
|
define(["foo"], function (_foo) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
_foo = babelHelpers.interopRequireDefault(_foo);
|
_foo = babelHelpers.interopRequireWildcard(_foo);
|
||||||
_foo.default;
|
_foo.default;
|
||||||
_foo.baz;
|
_foo.baz;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _foo = babelHelpers.interopRequireDefault(require("foo"));
|
var _foo = babelHelpers.interopRequireWildcard(require("foo"));
|
||||||
|
|
||||||
_foo.default;
|
_foo.default;
|
||||||
_foo.baz;
|
_foo.baz;
|
||||||
|
|||||||
@ -13,6 +13,6 @@
|
|||||||
})(this, function (_foo) {
|
})(this, function (_foo) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
_foo = babelHelpers.interopRequireDefault(_foo);
|
_foo = babelHelpers.interopRequireWildcard(_foo);
|
||||||
_foo.baz;
|
_foo.baz;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user