From 3381c44c56c03890f434f45d0ecca109ffe6a24b Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Wed, 14 Feb 2024 12:28:00 -0300 Subject: [PATCH] JS: fix parsing of 'export default expr' where expression can only be an assignment expression --- js/parse.go | 4 +++- js/parse_test.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/js/parse.go b/js/parse.go index 0e24e9e..ea6475b 100644 --- a/js/parse.go +++ b/js/parse.go @@ -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() diff --git a/js/parse_test.go b/js/parse_test.go index 171866e..0bf6d42 100644 --- a/js/parse_test.go +++ b/js/parse_test.go @@ -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"},