@@ -76,12 +76,21 @@ export class EvaluatorAsync {
76
76
77
77
const blockContext = cloneContext ( context ) ;
78
78
79
- // set parameters into new scope, based incomming arguments
80
- for ( let i = 0 ; i < funcDef . params ?. length || 0 ; i ++ ) {
81
- const argValue = args ?. length > i ? args [ i ] : null ;
82
- blockContext . blockScope . set ( funcDef . params [ i ] , argValue ) ;
79
+ for ( let i = 0 ; i < args ?. length || 0 ; i ++ ) {
80
+ if ( i >= funcDef . params . length ) {
81
+ break ;
82
+ // throw new Error('Too many parameters provided');
83
+ }
84
+ blockContext . blockScope . set ( funcDef . params [ i ] , args [ i ] ) ;
83
85
}
84
86
87
+
88
+ // // set parameters into new scope, based incomming arguments
89
+ // for (let i = 0; i < funcDef.params?.length || 0; i++) {
90
+ // const argValue = args?.length > i ? args[i] : null;
91
+ // blockContext.blockScope.set(funcDef.params[i], argValue);
92
+ // }
93
+
85
94
return await this . evalBlockAsync ( ast , blockContext ) ;
86
95
}
87
96
@@ -208,13 +217,24 @@ export class EvaluatorAsync {
208
217
const forNode = node as ForNode ;
209
218
210
219
const array = await this . evalNodeAsync ( forNode . sourceArray , blockContext ) as unknown [ ] | string ;
220
+ try {
211
221
212
- for ( let item of array ) {
213
- blockContext . blockScope . set ( forNode . itemVarName , item ) ;
214
- await this . evalBlockAsync ( { name : blockContext . moduleName , type : 'for' , body : forNode . body } as AstBlock , blockContext ) ;
215
- if ( blockContext . continueCalled ) { blockContext . continueCalled = false ; }
216
- if ( blockContext . breakCalled ) { break ; }
222
+ for ( let i = 0 ; i < array . length ; i ++ ) {
223
+ const item = array [ i ] ;
224
+ console . log ( '**DEBUG:' , array . length , i ) ;
225
+
226
+ blockContext . blockScope . set ( forNode . itemVarName , item ) ;
227
+ await this . evalBlockAsync ( { name : blockContext . moduleName , type : 'for' , body : forNode . body } as AstBlock , blockContext ) ;
228
+ if ( blockContext . continueCalled ) { blockContext . continueCalled = false ; }
229
+ if ( blockContext . breakCalled ) { break ; }
230
+ }
231
+
232
+ console . log ( '**FOR finished.' ) ;
233
+ } catch ( err ) {
234
+ console . log ( '**FOR FAILED:' , err ?. message || err ) ;
217
235
}
236
+
237
+
218
238
if ( blockContext . breakCalled ) { blockContext . breakCalled = false ; }
219
239
return ;
220
240
}
0 commit comments