Throw error for multiple exports default (#3518)

Fixes https://phabricator.babeljs.io/T7242
This commit is contained in:
Kai Cataldo
2016-08-16 13:21:00 -04:00
committed by Henry Zhu
parent 308de41992
commit aa51dd4a3d
77 changed files with 420 additions and 89 deletions

View File

@@ -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) {