Skip to content

Commit

Permalink
JS: fix panic when 'for(let ' has bad syntax, see #108
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 27, 2023
1 parent f30b39f commit 3fbdbe2
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 @@ -328,7 +328,9 @@ func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) {
tt := p.tt
p.next()
varDecl := p.parseVarDecl(tt, true)
if p.tt != SemicolonToken && (1 < len(varDecl.List) || varDecl.List[0].Default != nil) {
if p.err != nil {
return
} else if p.tt != SemicolonToken && (1 < len(varDecl.List) || varDecl.List[0].Default != nil) {
p.fail("for statement")
return
} else if p.tt == SemicolonToken && varDecl.List[0].Default == nil {
Expand Down
1 change: 1 addition & 0 deletions js/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ func TestParseError(t *testing.T) {
{"for(a;a;a", "expected ) instead of EOF in for statement"},
{"for(var [a],b;", "unexpected ; in for statement"},
{"for(var [a]=5,{b};", "expected = instead of ; in var statement"},
{`for(let{[(`, `unexpected EOF in expression`},
{"for await", "expected ( instead of EOF in for statement"},
{"function a(){for await", "expected ( instead of await in for statement"},
{"async function a(){ for await(a;", "expected of instead of ; in for statement"},
Expand Down

0 comments on commit 3fbdbe2

Please sign in to comment.