(mef cel.MacroExprFactory, target ast.Expr, args []ast.Expr)
| 365 | } |
| 366 | |
| 367 | func transformMapEntry(mef cel.MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *cel.Error) { |
| 368 | iterVar1, iterVar2, err := extractIterVars(mef, args[0], args[1]) |
| 369 | if err != nil { |
| 370 | return nil, err |
| 371 | } |
| 372 | |
| 373 | var transform ast.Expr |
| 374 | var filter ast.Expr |
| 375 | if len(args) == 4 { |
| 376 | filter = args[2] |
| 377 | transform = args[3] |
| 378 | } else { |
| 379 | filter = nil |
| 380 | transform = args[2] |
| 381 | } |
| 382 | |
| 383 | // accumulator = cel.@mapInsert(accumulator, transform) |
| 384 | step := mef.NewCall(mapInsert, mef.NewAccuIdent(), transform) |
| 385 | if filter != nil { |
| 386 | // accumulator = (filter) ? cel.@mapInsert(accumulator, transform) : accumulator |
| 387 | step = mef.NewCall(operators.Conditional, filter, step, mef.NewAccuIdent()) |
| 388 | } |
| 389 | return mef.NewComprehensionTwoVar( |
| 390 | target, |
| 391 | iterVar1, |
| 392 | iterVar2, |
| 393 | mef.AccuIdentName(), |
| 394 | /*accuInit=*/ mef.NewMap(), |
| 395 | /*condition=*/ mef.NewLiteral(types.True), |
| 396 | step, |
| 397 | /*result=*/ mef.NewAccuIdent(), |
| 398 | ), nil |
| 399 | } |
| 400 | |
| 401 | func extractIterVars(mef cel.MacroExprFactory, arg0, arg1 ast.Expr) (string, string, *cel.Error) { |
| 402 | iterVar1, err := extractIterVar(mef, arg0) |
nothing calls this directly
no test coverage detected