(expr *ast.ObjectLiteral)
| 1499 | } |
| 1500 | |
| 1501 | func (self *_parser) reinterpretAsObjectBindingPattern(expr *ast.ObjectLiteral) ast.BindingTarget { |
| 1502 | var rest ast.Expression |
| 1503 | value := expr.Value |
| 1504 | for i, prop := range value { |
| 1505 | ok := false |
| 1506 | switch prop := prop.(type) { |
| 1507 | case *ast.PropertyKeyed: |
| 1508 | if prop.Kind == ast.PropertyKindValue { |
| 1509 | prop.Value = self.reinterpretAsBindingElement(prop.Value) |
| 1510 | ok = true |
| 1511 | } |
| 1512 | case *ast.PropertyShort: |
| 1513 | ok = true |
| 1514 | case *ast.SpreadElement: |
| 1515 | if i != len(expr.Value)-1 { |
| 1516 | self.error(prop.Idx0(), "Rest element must be last element") |
| 1517 | return &ast.BadExpression{From: expr.Idx0(), To: expr.Idx1()} |
| 1518 | } |
| 1519 | // TODO make sure there is no trailing comma |
| 1520 | rest = self.reinterpretAsBindingRestElement(prop.Expression) |
| 1521 | value = value[:i] |
| 1522 | ok = true |
| 1523 | } |
| 1524 | if !ok { |
| 1525 | self.error(prop.Idx0(), "Invalid destructuring binding target") |
| 1526 | return &ast.BadExpression{From: expr.Idx0(), To: expr.Idx1()} |
| 1527 | } |
| 1528 | } |
| 1529 | return &ast.ObjectPattern{ |
| 1530 | LeftBrace: expr.LeftBrace, |
| 1531 | RightBrace: expr.RightBrace, |
| 1532 | Properties: value, |
| 1533 | Rest: rest, |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | func (self *_parser) reinterpretAsObjectAssignmentPattern(l *ast.ObjectLiteral) ast.Expression { |
| 1538 | var rest ast.Expression |
no test coverage detected