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

Method emitArrayPattern

compiler_expr.go:3388–3415  ·  view source on GitHub ↗
(pattern *ast.ArrayPattern, emitAssign func(target, init compiledExpr), putOnStack bool)

Source from the content-addressed store, hash-verified

3386}
3387
3388func (c *compiler) emitArrayPattern(pattern *ast.ArrayPattern, emitAssign func(target, init compiledExpr), putOnStack bool) {
3389 c.emit(iterate)
3390 for _, elt := range pattern.Elements {
3391 switch elt := elt.(type) {
3392 case nil:
3393 c.emit(iterGetNextOrUndef{}, pop)
3394 case *ast.AssignExpression:
3395 c.emitAssign(elt.Left, c.compilePatternInitExpr(func() {
3396 c.emit(iterGetNextOrUndef{})
3397 }, elt.Right, elt.Idx0()), emitAssign)
3398 default:
3399 c.emitAssign(elt, c.compileEmitterExpr(func() {
3400 c.emit(iterGetNextOrUndef{})
3401 }, elt.Idx0()), emitAssign)
3402 }
3403 }
3404 if pattern.Rest != nil {
3405 c.emitAssign(pattern.Rest, c.compileEmitterExpr(func() {
3406 c.emit(newArrayFromIter)
3407 }, pattern.Rest.Idx0()), emitAssign)
3408 } else {
3409 c.emit(enumPopClose)
3410 }
3411
3412 if !putOnStack {
3413 c.emit(pop)
3414 }
3415}
3416
3417func (e *compiledObjectAssignmentPattern) emitSetter(valueExpr compiledExpr, putOnStack bool) {
3418 valueExpr.emitGetter(true)

Callers 2

emitPatternMethod · 0.95
emitSetterMethod · 0.80

Calls 5

emitMethod · 0.95
emitAssignMethod · 0.95
compileEmitterExprMethod · 0.95
Idx0Method · 0.65

Tested by

no test coverage detected