JS: fix when parenthesized expr has assignments for the same variable which only when interpreted as arguments for an arrow func should error
Taco de Wolff
1 year, 8 months ago
1446 | 1446 | p.await, p.yield = true, false |
1447 | 1447 | |
1448 | 1448 | if IsIdentifier(p.tt) || !p.yield && p.tt == YieldToken { |
1449 | ref, _ := p.scope.Declare(ArgumentDecl, p.data) | |
1449 | ref, _ := p.scope.Declare(ArgumentDecl, p.data) // cannot fail | |
1450 | 1450 | p.next() |
1451 | 1451 | arrowFunc.Params.List = []BindingElement{{Binding: ref}} |
1452 | 1452 | } else { |
2103 | 2103 | data := p.data |
2104 | 2104 | p.next() |
2105 | 2105 | if p.tt == EqToken || p.tt == CommaToken || p.tt == CloseParenToken || p.tt == CloseBraceToken || p.tt == CloseBracketToken { |
2106 | var ok bool | |
2106 | 2107 | var left IExpr |
2107 | left, _ = p.scope.Declare(ArgumentDecl, data) // cannot fail | |
2108 | p.assumeArrowFunc = false | |
2109 | left = p.parseExpressionSuffix(left, OpAssign, OpPrimary) | |
2110 | p.assumeArrowFunc = true | |
2111 | return left | |
2108 | left, ok = p.scope.Declare(ArgumentDecl, data) | |
2109 | if ok { | |
2110 | p.assumeArrowFunc = false | |
2111 | left = p.parseExpressionSuffix(left, OpAssign, OpPrimary) | |
2112 | p.assumeArrowFunc = true | |
2113 | return left | |
2114 | } | |
2112 | 2115 | } |
2113 | 2116 | p.assumeArrowFunc = false |
2114 | 2117 | if tt == AsyncToken { |
2147 | 2150 | p.next() |
2148 | 2151 | } |
2149 | 2152 | } else if p.isIdentifierReference(p.tt) { |
2150 | rest, _ = p.scope.Declare(ArgumentDecl, p.data) // cannot fail | |
2153 | var ok bool | |
2154 | rest, ok = p.scope.Declare(ArgumentDecl, p.data) | |
2155 | if !ok { | |
2156 | p.failMessage("identifier %s has already been declared", string(p.data)) | |
2157 | return nil | |
2158 | } | |
2151 | 2159 | p.next() |
2152 | 2160 | } else if p.tt == OpenBracketToken { |
2153 | 2161 | array := p.parseArrayLiteral() |
623 | 623 | {"x = ({...5}) =>", "unexpected => in expression"}, |
624 | 624 | {"x = ({5: 5}) =>", "unexpected => in expression"}, |
625 | 625 | {"x = ({[4+5]: 5}) =>", "unexpected => in expression"}, |
626 | {"x = (a, a) =>", "unexpected => in expression"}, | |
627 | {"x = (a, a, ...a) =>", "unexpected ... in expression"}, | |
628 | {"x = (a, ...a) =>", "identifier a has already been declared"}, | |
626 | 629 | |
627 | 630 | // expression precedence |
628 | 631 | {"x = a + yield b", "unexpected b in expression"}, |
951 | 954 | {"(a,b=a) => {}", "/a=1,b=2", "/"}, |
952 | 955 | {"(a=b,b)=>{}", "/a=2,b=3", "b=1/b=1"}, |
953 | 956 | {"a=>{var a}", "/a=1", "/"}, |
954 | {"(a,a)=>{}", "/a=1", "/"}, | |
955 | 957 | {"(a=b) => {var b}", "/a=2,b=3", "b=1/b=1"}, |
956 | 958 | {"({[a+b]:c}) => {}", "/c=3", "a=1,b=2/a=1,b=2"}, |
957 | 959 | {"({a:b, c=d, ...e}=f) => 5", "/b=3,c=4,e=5", "d=1,f=2/d=1,f=2"}, |