Skip to content

Commit

Permalink
JS: fix precedence of OptionalChaining expression
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Feb 16, 2024
1 parent 3381c44 commit 3b2a162
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,9 @@ func (p *Parser) parseExpressionSuffix(left IExpr, prec, precLeft OpPrec) IExpr
case OptChainToken:
if OpCall < prec {
return left
} else if precLeft < OpCall {
p.fail("expression")
return nil
}
p.next()
if p.tt == OpenParenToken {
Expand Down
1 change: 1 addition & 0 deletions js/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ func TestParseError(t *testing.T) {
{"function*a(){ (yield) => yield }", "unexpected => in expression"},
{"function*a(){ (yield=5) => yield }", "unexpected = in expression"},
{"function*a(){ (...yield) => yield }", "unexpected => in expression"},
{"function*a(){ yield yield\n?.() }", "unexpected ?. in expression"},
{"x = await\n=> a++", "unexpected => in expression"},
{"x=async (await,", "unexpected , in expression"},
{"async function a() { class a extends await", "unexpected await in expression"},
Expand Down

0 comments on commit 3b2a162

Please sign in to comment.