properly handle export default shorthand, also consider export default foo; and export { foo as default } to be equivalent
This commit is contained in:
parent
f9c8d7d1fd
commit
8e1b6df970
@ -63,7 +63,10 @@ var exportsVisitor = traverse.explode({
|
||||
}
|
||||
|
||||
if (!t.isExportDefaultDeclaration(node)) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
var onlyDefault = node.specifiers && t.isExportDefaultSpecifier(node.specifiers[0]) && node.specifiers.length === 1;
|
||||
if (!onlyDefault) {
|
||||
formatter.hasNonDefaultExports = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.source) {
|
||||
@ -95,7 +98,7 @@ export default class DefaultFormatter {
|
||||
}
|
||||
|
||||
doDefaultExportInterop(node) {
|
||||
return t.isExportDefaultDeclaration(node) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
|
||||
}
|
||||
|
||||
bumpImportOccurences(node) {
|
||||
|
||||
@ -61,6 +61,17 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
}, true));
|
||||
}
|
||||
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
nodes.push(util.template("exports-default-assign", {
|
||||
VALUE: specifier.local
|
||||
}, true));
|
||||
return;
|
||||
} else {
|
||||
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
if (this.doDefaultExportInterop(node)) {
|
||||
var declar = node.declaration;
|
||||
|
||||
@ -21,7 +21,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
var uid = scope.generateUidIdentifier(specifier.exported.name);
|
||||
nodes.push(
|
||||
t.importDeclaration([t.importSpecifier(uid, specifier.exported)], node.source),
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)])
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, t.identifier("default"))])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _foo = require("bar").foo;
|
||||
|
||||
exports.foo = _foo;
|
||||
module.exports = _foo;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
import { foo as _foo } from "bar";
|
||||
export { _foo as foo };
|
||||
export { _foo as default };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user