(pattern *ast.ObjectPattern, emitAssign func(target, init compiledExpr), putOnStack bool)
| 3343 | } |
| 3344 | |
| 3345 | func (c *compiler) emitObjectPattern(pattern *ast.ObjectPattern, emitAssign func(target, init compiledExpr), putOnStack bool) { |
| 3346 | if pattern.Rest != nil { |
| 3347 | c.emit(createDestructSrc) |
| 3348 | } else { |
| 3349 | c.emit(checkObjectCoercible) |
| 3350 | } |
| 3351 | for _, prop := range pattern.Properties { |
| 3352 | switch prop := prop.(type) { |
| 3353 | case *ast.PropertyShort: |
| 3354 | c.emit(dup) |
| 3355 | emitAssign(c.compileIdentifierExpression(&prop.Name), c.compilePatternInitExpr(func() { |
| 3356 | c.emit(getProp(prop.Name.Name)) |
| 3357 | }, prop.Initializer, prop.Idx0())) |
| 3358 | case *ast.PropertyKeyed: |
| 3359 | c.emit(dup) |
| 3360 | c.compileExpression(prop.Key).emitGetter(true) |
| 3361 | c.emit(_toPropertyKey{}) |
| 3362 | var target ast.Expression |
| 3363 | var initializer ast.Expression |
| 3364 | if e, ok := prop.Value.(*ast.AssignExpression); ok { |
| 3365 | target = e.Left |
| 3366 | initializer = e.Right |
| 3367 | } else { |
| 3368 | target = prop.Value |
| 3369 | } |
| 3370 | c.emitAssign(target, c.compilePatternInitExpr(func() { |
| 3371 | c.emit(getKey) |
| 3372 | }, initializer, prop.Idx0()), emitAssign) |
| 3373 | default: |
| 3374 | c.throwSyntaxErrorf(int(prop.Idx0()-1), "Unsupported AssignmentProperty type: %T", prop) |
| 3375 | } |
| 3376 | } |
| 3377 | if pattern.Rest != nil { |
| 3378 | emitAssign(c.compileExpression(pattern.Rest), c.compileEmitterExpr(func() { |
| 3379 | c.emit(copyRest) |
| 3380 | }, pattern.Rest.Idx0())) |
| 3381 | c.emit(pop) |
| 3382 | } |
| 3383 | if !putOnStack { |
| 3384 | c.emit(pop) |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | func (c *compiler) emitArrayPattern(pattern *ast.ArrayPattern, emitAssign func(target, init compiledExpr), putOnStack bool) { |
| 3389 | c.emit(iterate) |
no test coverage detected