From dead29587cf4ae69df5d491563bf63cd5a4931c4 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Mon, 30 Oct 2023 12:05:49 -0300 Subject: [PATCH] JS: fix AST after statement --- js/ast_test.go | 2 ++ js/parse.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/js/ast_test.go b/js/ast_test.go index e8be59d..9454545 100644 --- a/js/ast_test.go +++ b/js/ast_test.go @@ -115,6 +115,8 @@ func TestJS(t *testing.T) { {"import o,{} from''", "import o, {} from '';"}, {"if(0)var s;else", "if (0) var s; else;"}, {"async\n()", "async();"}, + {"{};;", "{} ;"}, + {"{}\n;", "{} ;"}, } re := regexp.MustCompile("\n *") diff --git a/js/parse.go b/js/parse.go index 86c58a2..cd526bf 100644 --- a/js/parse.go +++ b/js/parse.go @@ -533,10 +533,11 @@ func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) { } stmt = &TryStmt{body, binding, catch, finally} case DebuggerToken: - p.next() stmt = &DebuggerStmt{} + p.next() case SemicolonToken, ErrorToken: stmt = &EmptyStmt{} + p.next() case CommentToken, CommentLineTerminatorToken: // bang comment stmt = &Comment{p.data} @@ -581,7 +582,7 @@ func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) { } } } - if p.tt == SemicolonToken { + if !p.prevLT && p.tt == SemicolonToken { p.next() } p.stmtLevel--