@@ -1561,6 +1561,9 @@ type deferredErrors struct {
1561
1561
invalidExprDefaultValue logger.Range
1562
1562
invalidExprAfterQuestion logger.Range
1563
1563
arraySpreadFeature logger.Range
1564
+
1565
+ // These errors are for arrow functions
1566
+ invalidParens []logger.Range
1564
1567
}
1565
1568
1566
1569
func (from *deferredErrors) mergeInto(to *deferredErrors) {
@@ -1573,6 +1576,13 @@ func (from *deferredErrors) mergeInto(to *deferredErrors) {
1573
1576
if from.arraySpreadFeature.Len > 0 {
1574
1577
to.arraySpreadFeature = from.arraySpreadFeature
1575
1578
}
1579
+ if len(from.invalidParens) > 0 {
1580
+ if len(to.invalidParens) > 0 {
1581
+ to.invalidParens = append(to.invalidParens, from.invalidParens...)
1582
+ } else {
1583
+ to.invalidParens = from.invalidParens
1584
+ }
1585
+ }
1576
1586
}
1577
1587
1578
1588
func (p *parser) logExprErrors(errors *deferredErrors) {
@@ -1590,6 +1600,12 @@ func (p *parser) logExprErrors(errors *deferredErrors) {
1590
1600
}
1591
1601
}
1592
1602
1603
+ func (p *parser) logDeferredArrowArgErrors(errors *deferredErrors) {
1604
+ for _, paren := range errors.invalidParens {
1605
+ p.log.Add(logger.Error, &p.tracker, paren, "Invalid binding pattern")
1606
+ }
1607
+ }
1608
+
1593
1609
// The "await" and "yield" expressions are never allowed in argument lists but
1594
1610
// may or may not be allowed otherwise depending on the details of the enclosing
1595
1611
// function or module. This needs to be handled when parsing an arrow function
@@ -1619,13 +1635,11 @@ type deferredArrowArgErrors struct {
1619
1635
1620
1636
func (p *parser) logArrowArgErrors(errors *deferredArrowArgErrors) {
1621
1637
if errors.invalidExprAwait.Len > 0 {
1622
- r := errors.invalidExprAwait
1623
- p.log.Add(logger.Error, &p.tracker, r, "Cannot use an \"await\" expression here:")
1638
+ p.log.Add(logger.Error, &p.tracker, errors.invalidExprAwait, "Cannot use an \"await\" expression here:")
1624
1639
}
1625
1640
1626
1641
if errors.invalidExprYield.Len > 0 {
1627
- r := errors.invalidExprYield
1628
- p.log.Add(logger.Error, &p.tracker, r, "Cannot use a \"yield\" expression here:")
1642
+ p.log.Add(logger.Error, &p.tracker, errors.invalidExprYield, "Cannot use a \"yield\" expression here:")
1629
1643
}
1630
1644
}
1631
1645
@@ -2630,6 +2644,7 @@ func (p *parser) parseParenExpr(loc logger.Loc, level js_ast.L, opts parenExprOp
2630
2644
p.log.Add(logger.Error, &p.tracker, logger.Range{Loc: commaAfterSpread, Len: 1}, "Unexpected \",\" after rest pattern")
2631
2645
}
2632
2646
p.logArrowArgErrors(&arrowArgErrors)
2647
+ p.logDeferredArrowArgErrors(&errors)
2633
2648
2634
2649
// Now that we've decided we're an arrow function, report binding pattern
2635
2650
// conversion errors
@@ -2749,9 +2764,6 @@ func (p *parser) convertExprToBinding(expr js_ast.Expr, invalidLog invalidLog) (
2749
2764
if e.CommaAfterSpread.Start != 0 {
2750
2765
invalidLog.invalidTokens = append(invalidLog.invalidTokens, logger.Range{Loc: e.CommaAfterSpread, Len: 1})
2751
2766
}
2752
- if e.IsParenthesized {
2753
- invalidLog.invalidTokens = append(invalidLog.invalidTokens, p.source.RangeOfOperatorBefore(expr.Loc, "("))
2754
- }
2755
2767
p.markSyntaxFeature(compat.Destructuring, p.source.RangeOfOperatorAfter(expr.Loc, "["))
2756
2768
items := []js_ast.ArrayBinding{}
2757
2769
isSpread := false
@@ -2777,9 +2789,6 @@ func (p *parser) convertExprToBinding(expr js_ast.Expr, invalidLog invalidLog) (
2777
2789
if e.CommaAfterSpread.Start != 0 {
2778
2790
invalidLog.invalidTokens = append(invalidLog.invalidTokens, logger.Range{Loc: e.CommaAfterSpread, Len: 1})
2779
2791
}
2780
- if e.IsParenthesized {
2781
- invalidLog.invalidTokens = append(invalidLog.invalidTokens, p.source.RangeOfOperatorBefore(expr.Loc, "("))
2782
- }
2783
2792
p.markSyntaxFeature(compat.Destructuring, p.source.RangeOfOperatorAfter(expr.Loc, "{"))
2784
2793
properties := []js_ast.PropertyBinding{}
2785
2794
for _, item := range e.Properties {
@@ -2843,6 +2852,10 @@ func (p *parser) parsePrefix(level js_ast.L, errors *deferredErrors, flags exprF
2843
2852
return js_ast.Expr{Loc: loc, Data: js_ast.ESuperShared}
2844
2853
2845
2854
case js_lexer.TOpenParen:
2855
+ if errors != nil {
2856
+ errors.invalidParens = append(errors.invalidParens, p.lexer.Range())
2857
+ }
2858
+
2846
2859
p.lexer.Next()
2847
2860
2848
2861
// Arrow functions aren't allowed in the middle of expressions
@@ -3253,7 +3266,7 @@ func (p *parser) parsePrefix(level js_ast.L, errors *deferredErrors, flags exprF
3253
3266
if p.lexer.Token == js_lexer.TDotDotDot {
3254
3267
dotLoc := p.lexer.Loc()
3255
3268
p.lexer.Next()
3256
- value := p.parseExpr (js_ast.LComma)
3269
+ value := p.parseExprOrBindings (js_ast.LComma, &selfErrors )
3257
3270
properties = append(properties, js_ast.Property{
3258
3271
Kind: js_ast.PropertySpread,
3259
3272
Loc: dotLoc,
0 commit comments