@@ -76,12 +76,21 @@ export class EvaluatorAsync {
7676
7777 const blockContext = cloneContext ( context ) ;
7878
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 ] ) ;
8385 }
8486
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+
8594 return await this . evalBlockAsync ( ast , blockContext ) ;
8695 }
8796
@@ -208,13 +217,24 @@ export class EvaluatorAsync {
208217 const forNode = node as ForNode ;
209218
210219 const array = await this . evalNodeAsync ( forNode . sourceArray , blockContext ) as unknown [ ] | string ;
220+ try {
211221
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 ) ;
217235 }
236+
237+
218238 if ( blockContext . breakCalled ) { blockContext . breakCalled = false ; }
219239 return ;
220240 }
0 commit comments