(meh ExprHelper, target ast.Expr, args []ast.Expr)
| 2595 | var optMapMacro = NewReceiverMacro("optMap", 2, optMapExpander) |
| 2596 | |
| 2597 | func optMapExpander(meh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) { |
| 2598 | varIdent := args[0] |
| 2599 | varName := "" |
| 2600 | switch varIdent.Kind() { |
| 2601 | case ast.IdentKind: |
| 2602 | varName = varIdent.AsIdent() |
| 2603 | default: |
| 2604 | return nil, meh.NewError(varIdent.ID(), "optMap() variable name must be a simple identifier") |
| 2605 | } |
| 2606 | mapExpr := args[1] |
| 2607 | return meh.NewCall( |
| 2608 | operators.Conditional, |
| 2609 | meh.NewMemberCall("hasValue", target), |
| 2610 | meh.NewCall("optional.of", |
| 2611 | meh.NewComprehension( |
| 2612 | meh.NewList(), |
| 2613 | "#unused", |
| 2614 | varName, |
| 2615 | meh.NewMemberCall("value", meh.Copy(target)), |
| 2616 | meh.NewLiteral(types.False), |
| 2617 | meh.NewIdent(varName), |
| 2618 | mapExpr, |
| 2619 | ), |
| 2620 | ), |
| 2621 | meh.NewCall("optional.none"), |
| 2622 | ), nil |
| 2623 | } |
| 2624 | |
| 2625 | func newBenchmarkCategoryParser(tb testing.TB) *Parser { |
| 2626 | tb.Helper() |
nothing calls this directly
no test coverage detected