@@ -68,12 +68,17 @@ func rangeVectorFunction(ctx types.Context, data []any, namingVec ast.Expression
6868 )
6969
7070 for i , item := range data {
71- // do not use separate contexts for each loop iteration, as the loop might build up a counter
72- loopCtx = loopCtx .WithVariable (loopVarName , item )
71+ vars := map [string ]any {
72+ loopVarName : item ,
73+ }
74+
7375 if loopIndexName != "" {
74- loopCtx = loopCtx . WithVariable ( loopIndexName , i )
76+ vars [ loopIndexName ] = i
7577 }
7678
79+ // do not use separate contexts for each loop iteration, as the loop might build up a counter
80+ loopCtx = loopCtx .WithVariables (vars )
81+
7782 loopCtx , result , err = eval .EvalExpression (loopCtx , expr )
7883 if err != nil {
7984 return nil , err
@@ -98,12 +103,17 @@ func rangeObjectFunction(ctx types.Context, data map[string]any, namingVec ast.E
98103 )
99104
100105 for key , value := range data {
101- // do not use separate contexts for each loop iteration, as the loop might build up a counter
102- loopCtx = loopCtx .WithVariable (loopVarName , value )
106+ vars := map [string ]any {
107+ loopVarName : value ,
108+ }
109+
103110 if loopIndexName != "" {
104- loopCtx = loopCtx . WithVariable ( loopIndexName , key )
111+ vars [ loopIndexName ] = key
105112 }
106113
114+ // do not use separate contexts for each loop iteration, as the loop might build up a counter
115+ loopCtx = loopCtx .WithVariables (vars )
116+
107117 loopCtx , result , err = eval .EvalExpression (loopCtx , expr )
108118 if err != nil {
109119 return nil , err
@@ -140,11 +150,16 @@ func mapVectorExpressionFunction(ctx types.Context, data []any, namingVec ast.Ex
140150 }
141151
142152 mapHandler := func (ctx types.Context , index any , value any ) (types.Context , any , error ) {
143- ctx = ctx .WithVariable (valueVarName , value )
153+ vars := map [string ]any {
154+ valueVarName : value ,
155+ }
156+
144157 if indexVarName != "" {
145- ctx = ctx . WithVariable ( indexVarName , index )
158+ vars [ indexVarName ] = index
146159 }
147160
161+ ctx = ctx .WithVariables (vars )
162+
148163 return eval .EvalExpression (ctx , expr )
149164 }
150165
@@ -197,11 +212,16 @@ func mapObjectExpressionFunction(ctx types.Context, data map[string]any, namingV
197212 }
198213
199214 mapHandler := func (ctx types.Context , key any , value any ) (types.Context , any , error ) {
200- ctx = ctx .WithVariable (valueVarName , value )
215+ vars := map [string ]any {
216+ valueVarName : value ,
217+ }
218+
201219 if keyVarName != "" {
202- ctx = ctx . WithVariable ( keyVarName , key )
220+ vars [ keyVarName ] = key
203221 }
204222
223+ ctx = ctx .WithVariables (vars )
224+
205225 return eval .EvalExpression (ctx , expr )
206226 }
207227
@@ -254,11 +274,16 @@ func filterVectorExpressionFunction(ctx types.Context, data []any, namingVec ast
254274 }
255275
256276 mapHandler := func (ctx types.Context , index any , value any ) (types.Context , any , error ) {
257- ctx = ctx .WithVariable (valueVarName , value )
277+ vars := map [string ]any {
278+ valueVarName : value ,
279+ }
280+
258281 if indexVarName != "" {
259- ctx = ctx . WithVariable ( indexVarName , index )
282+ vars [ indexVarName ] = index
260283 }
261284
285+ ctx = ctx .WithVariables (vars )
286+
262287 return eval .EvalExpression (ctx , expr )
263288 }
264289
@@ -317,11 +342,16 @@ func filterObjectExpressionFunction(ctx types.Context, data map[string]any, nami
317342 }
318343
319344 mapHandler := func (ctx types.Context , key any , value any ) (types.Context , any , error ) {
320- ctx = ctx .WithVariable (valueVarName , value )
345+ vars := map [string ]any {
346+ valueVarName : value ,
347+ }
348+
321349 if keyVarName != "" {
322- ctx = ctx . WithVariable ( keyVarName , key )
350+ vars [ keyVarName ] = key
323351 }
324352
353+ ctx = ctx .WithVariables (vars )
354+
325355 return eval .EvalExpression (ctx , expr )
326356 }
327357
0 commit comments