diff --git a/eval.go b/eval.go index 6eab0c9..f81748b 100644 --- a/eval.go +++ b/eval.go @@ -1278,8 +1278,7 @@ func (st *Runtime) evaluateArgs(fnType reflect.Type, args CallArgs, pipedArg *re } } - slot, i := 0, 0 - var term reflect.Value + slot := 0 // index in argument values (evaluated expressions combined with piped argument if applicable) if !args.HasPipeSlot && pipedArg != nil { in := fnType.In(slot) @@ -1290,8 +1289,11 @@ func (st *Runtime) evaluateArgs(fnType reflect.Type, args CallArgs, pipedArg *re slot++ } - for i < len(args.Exprs) { + i := 0 // index in parsed argument expression list + + for slot < numArgsRequired { in := fnType.In(slot) + var term reflect.Value if args.Exprs[i].Type() == NodeUnderscore { term = *pipedArg } else { @@ -1308,6 +1310,7 @@ func (st *Runtime) evaluateArgs(fnType reflect.Type, args CallArgs, pipedArg *re if isVariadic { in := fnType.In(numArgsRequired).Elem() for i < len(args.Exprs) { + var term reflect.Value if args.Exprs[i].Type() == NodeUnderscore { term = *pipedArg } else { diff --git a/eval_test.go b/eval_test.go index ec19d43..df77699 100644 --- a/eval_test.go +++ b/eval_test.go @@ -162,8 +162,13 @@ func TestEvalActionNode(t *testing.T) { "José Santos", "email@example.com", }) + data.Set("print", fmt.Sprint) + data.Set("printf", fmt.Sprintf) + RunJetTest(t, nil, nil, "actionNode", `hello {{"world"}}`, `hello world`) RunJetTest(t, data, nil, "actionNode_func", `hello {{lower: "WORLD"}}`, `hello world`) + RunJetTest(t, data, nil, "actionNode_func_variadic", `{{ print("hello world") }}`, `hello world`) + RunJetTest(t, data, nil, "actionNode_func_variadic2", `{{ printf("hello %s", "world") }}`, `hello world`) RunJetTest(t, data, nil, "actionNode_funcPipe", `hello {{lower: "WORLD" |upper}}`, `hello WORLD`) RunJetTest(t, data, nil, "actionNode_funcPipe_parens", `{{ "foo" | repeat(2) }}`, `foofoo`) RunJetTest(t, data, nil, "actionNode_funcPipe_parens2", `hello {{lower ( "WORLD" ) |upper}}`, `hello WORLD`)