MCPcopy Create free account
hub / github.com/dop251/goja / reinterpretAsObjectAssignmentPattern

Method reinterpretAsObjectAssignmentPattern

parser/expression.go:1537–1571  ·  view source on GitHub ↗
(l *ast.ObjectLiteral)

Source from the content-addressed store, hash-verified

1535}
1536
1537func (self *_parser) reinterpretAsObjectAssignmentPattern(l *ast.ObjectLiteral) ast.Expression {
1538 var rest ast.Expression
1539 value := l.Value
1540 for i, prop := range value {
1541 ok := false
1542 switch prop := prop.(type) {
1543 case *ast.PropertyKeyed:
1544 if prop.Kind == ast.PropertyKindValue {
1545 prop.Value = self.reinterpretAsAssignmentElement(prop.Value)
1546 ok = true
1547 }
1548 case *ast.PropertyShort:
1549 ok = true
1550 case *ast.SpreadElement:
1551 if i != len(l.Value)-1 {
1552 self.error(prop.Idx0(), "Rest element must be last element")
1553 return &ast.BadExpression{From: l.Idx0(), To: l.Idx1()}
1554 }
1555 // TODO make sure there is no trailing comma
1556 rest = prop.Expression
1557 value = value[:i]
1558 ok = true
1559 }
1560 if !ok {
1561 self.error(prop.Idx0(), "Invalid destructuring assignment target")
1562 return &ast.BadExpression{From: l.Idx0(), To: l.Idx1()}
1563 }
1564 }
1565 return &ast.ObjectPattern{
1566 LeftBrace: l.LeftBrace,
1567 RightBrace: l.RightBrace,
1568 Properties: value,
1569 Rest: rest,
1570 }
1571}
1572
1573func (self *_parser) reinterpretAsAssignmentElement(expr ast.Expression) ast.Expression {
1574 switch expr := expr.(type) {

Calls 4

errorMethod · 0.95
Idx0Method · 0.65
Idx1Method · 0.65

Tested by

no test coverage detected