Throw error for multiple exports default (#3518)
Fixes https://phabricator.babeljs.io/T7242
This commit is contained in:
@@ -170,6 +170,8 @@ export default function () {
|
||||
|
||||
let requires = Object.create(null);
|
||||
|
||||
let exportDefaultFound = false;
|
||||
|
||||
function addRequire(source, blockHoist) {
|
||||
let cached = requires[source];
|
||||
if (cached) return cached;
|
||||
@@ -238,6 +240,10 @@ export default function () {
|
||||
|
||||
path.remove();
|
||||
} else if (path.isExportDefaultDeclaration()) {
|
||||
if (exportDefaultFound) {
|
||||
throw path.buildCodeFrameError("Only one default export allowed per module.");
|
||||
}
|
||||
|
||||
let declaration = path.get("declaration");
|
||||
if (declaration.isFunctionDeclaration()) {
|
||||
let id = declaration.node.id;
|
||||
@@ -270,6 +276,7 @@ export default function () {
|
||||
// replaceWith above. See T7166 for more info.
|
||||
path.parentPath.requeue(path.get("expression.left"));
|
||||
}
|
||||
exportDefaultFound = true;
|
||||
} else if (path.isExportNamedDeclaration()) {
|
||||
let declaration = path.get("declaration");
|
||||
if (declaration.node) {
|
||||
|
||||
Reference in New Issue
Block a user