Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,11 @@ func (p *Parser) parseExpressionSuffix(left IExpr, prec, precLeft OpPrec) IExpr
return nil
}
p.next()
// the right-hand side is never a binding, even when the left-hand side is a binding pattern with an initializer in arrow function parameters
prevAssumeArrowFunc := p.assumeArrowFunc
p.assumeArrowFunc = false
left = &BinaryExpr{tt, left, p.parseExpression(OpAssign)}
p.assumeArrowFunc = prevAssumeArrowFunc && tt == EqToken
precLeft = OpAssign
case LtToken, LtEqToken, GtToken, GtEqToken, InToken, InstanceofToken:
if OpCompare < prec || !p.in && tt == InToken {
Expand Down
8 changes: 8 additions & 0 deletions js/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ func TestParse(t *testing.T) {
{"x = (a = 5) => {a++}", "Stmt(x=(Params(Binding(a = 5)) => Stmt({ Stmt(a++) })))"},
{"x = ({a = 5}) => {a++}", "Stmt(x=(Params(Binding({ Binding(a = 5) })) => Stmt({ Stmt(a++) })))"},
{`({a:b=1}={})=>b`, `Stmt(Params(Binding({ a: Binding(b = 1) } = {})) => Stmt({ Stmt(return b) }))`},
{"([a] = [5]) => a", "Stmt(Params(Binding([ Binding(a) ] = [5])) => Stmt({ Stmt(return a) }))"},
{"({a} = {a:5}) => a", "Stmt(Params(Binding({ Binding(a) } = {a: 5})) => Stmt({ Stmt(return a) }))"},
{"([[a] = [5]]) => a", "Stmt(Params(Binding([ Binding([ Binding(a) ] = [5]) ])) => Stmt({ Stmt(return a) }))"},
{"(a, [b] = [a]) => b", "Stmt(Params(Binding(a), Binding([ Binding(b) ] = [a])) => Stmt({ Stmt(return b) }))"},

// expression precedence
{"!!a", "Stmt(!(!a))"},
Expand Down Expand Up @@ -1004,6 +1008,10 @@ func TestParseScope(t *testing.T) {
{"({[a+b]:c}) => {}", "/c=3", "a=1,b=2/a=1,b=2"},
{"({a:b, c=d, ...e}=f) => 5", "/b=3,c=4,e=5", "d=1,f=2/d=1,f=2"},
{"([a, b=c, ...d]=e) => 5", "/a=3,b=4,d=5", "c=1,e=2/c=1,e=2"},
{"([a]=[b]) => a+b", "/a=2", "b=1/b=1"},
{"({a}={b}) => a+b", "/a=2", "b=1/b=1"},
{"({a}={a:b}) => a+b", "/a=2", "b=1/b=1"},
{"(a, [b]=[a, c]) => b", "/a=2,b=3", "c=1/c=1"},
{"(a) + ((b,c) => {var d; e = 5; return e})", "/b=3,c=4,d=5", "a=1,e=2/e=2"},
{"(a) + ((a,b) => {var c; d = 5; return d})", "/a=3,b=4,c=5", "a=1,d=2/d=2"},
{"{(a) + ((a,b) => {var c; d = 5; return d})}", "//a=3,b=4,c=5", "a=1,d=2/a=1,d=2/d=2"},
Expand Down