Skip to content

Commit

Permalink
Parse default-exported parenthesized classes/functions correctly
Browse files Browse the repository at this point in the history
Closes #379
  • Loading branch information
marijnh committed Feb 5, 2016
1 parent 4593dc8 commit 0453696
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ pp.parseExport = function(node) {
return this.finishNode(node, "ExportAllDeclaration")
}
if (this.eat(tt._default)) { // export default ...
let parens = this.type == tt.parenL
let expr = this.parseMaybeAssign()
let needsSemi = true
if (expr.type == "FunctionExpression" ||
expr.type == "ClassExpression") {
if (!parens && (expr.type == "FunctionExpression" ||
expr.type == "ClassExpression")) {
needsSemi = false
if (expr.id) {
expr.type = expr.type == "FunctionExpression"
Expand Down
18 changes: 18 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -4237,6 +4237,24 @@ test("export default class A {}", {
}]
}, {ecmaVersion: 6, sourceType: "module", ranges: true});

test("export default (class{});", {
"type": "Program",
"body": [
{
"type": "ExportDefaultDeclaration",
"declaration": {
"type": "ClassExpression",
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"body": []
}
}
}
]
}, {ecmaVersion: 6, sourceType: "module"})

testFail("export *", "Unexpected token (1:8)", {ecmaVersion: 6, sourceType: "module"});

test("export * from \"crypto\"", {
Expand Down

0 comments on commit 0453696

Please sign in to comment.