Skip to content

Commit

Permalink
JS: fix AST after statement
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 30, 2023
1 parent edb8bf7 commit dead295
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions js/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 *")
Expand Down
5 changes: 3 additions & 2 deletions js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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--
Expand Down

0 comments on commit dead295

Please sign in to comment.