Skip to content

Commit

Permalink
JS: fix parsing of 'export default expr' where expression can only be…
Browse files Browse the repository at this point in the history
… an assignment expression
  • Loading branch information
tdewolff committed Feb 14, 2024
1 parent 5d46320 commit 3381c44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,15 +828,17 @@ func (p *Parser) parseExportStmt() (exportStmt ExportStmt) {
exportStmt.Default = true
p.next()
if p.tt == FunctionToken {
// hoistable declaration
exportStmt.Decl = p.parseFuncDecl()
} else if p.tt == AsyncToken { // async function or async arrow function
async := p.data
p.next()
if p.tt == FunctionToken && !p.prevLT {
// hoistable declaration
exportStmt.Decl = p.parseAsyncFuncDecl()
} else {
// expression
exportStmt.Decl = p.parseAsyncExpression(OpExpr, async)
exportStmt.Decl = p.parseAsyncExpression(OpAssign, async)
}
} else if p.tt == ClassToken {
exportStmt.Decl = p.parseClassDecl()
Expand Down
1 change: 1 addition & 0 deletions js/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ func TestParseError(t *testing.T) {
{"export {} from", "expected String instead of EOF in export statement"},
{"export {} from", "expected String instead of EOF in export statement"},
{"export async", "expected function instead of EOF in export statement"},
{"export default async=>a,b", "unexpected , in expression"},
{"throw", "unexpected EOF in expression"},
{"throw\n", "unexpected newline in throw statement"},
{"#private", "expected in instead of EOF in relational expression"},
Expand Down

0 comments on commit 3381c44

Please sign in to comment.