make export default anoynmous class/function statements - fixes #2205

This commit is contained in:
Sebastian McKenzie
2015-09-01 05:34:11 +01:00
parent 5161c4839c
commit f33c96c276
2 changed files with 15 additions and 4 deletions

View File

@@ -121,7 +121,15 @@ export function YieldExpression(node, parent) {
}
export function ClassExpression(node, parent) {
return t.isExpressionStatement(parent);
// (class {});
if (t.isExpressionStatement(parent)) {
return true;
}
// export default (class () {});
if (t.isExportDeclaration(parent)) {
return true;
}
}
export function UnaryLike(node, parent) {
@@ -129,11 +137,16 @@ export function UnaryLike(node, parent) {
}
export function FunctionExpression(node, parent) {
// function () {};
// (function () {});
if (t.isExpressionStatement(parent)) {
return true;
}
// export default (function () {});
if (t.isExportDeclaration(parent)) {
return true;
}
// (function test() {}).name;
if (t.isMemberExpression(parent) && parent.object === node) {
return true;

View File

@@ -673,10 +673,8 @@ pp.parseExport = function (node) {
let needsSemi = false;
if (this.eat(tt._function)) {
expr = this.parseFunction(expr, true, false, false, true);
if (!expr.id) expr.type = "FunctionExpression";
} else if (this.match(tt._class)) {
expr = this.parseClass(expr, true, true);
if (!expr.id) expr.type = "ClassExpression";
} else {
needsSemi = true;
expr = this.parseMaybeAssign();