@@ -93,8 +93,16 @@ export class Interpreter {
9393 this . _lastExecutionContext = blockContext . blockScope . getScope ( ) ;
9494
9595 const result = await evaluator
96- . registerModuleParser ( async ( modulePath ) => await this . moduleParser ( modulePath ) )
97- . registerBlockContextFactory ( ( moduleName ) => ( { moduleName, blockScope : new Scope ( scope ) } ) )
96+ . registerModuleParser ( async ( modulePath ) => await this . moduleParser ( modulePath ) )
97+ . registerBlockContextFactory ( ( moduleName , ast : AstBlock ) => {
98+ // this line will not be required when we have move package loaders to the evaluator
99+ const newContext = this . assignLegacyImportContext ( ast , scope ) ;
100+
101+ const moduleContext = { moduleName, blockScope : new Scope ( newContext ) }
102+ moduleContext . blockScope . set ( 'printExecutionContext' , ( ) => console . log ( moduleContext . blockScope . getScope ( ) ) ) ;
103+ moduleContext . blockScope . set ( 'getExecutionContext' , ( ) => moduleContext . blockScope . getScope ( ) ) ;
104+ return moduleContext ;
105+ } )
98106 . evalBlockAsync ( ast , blockContext ) ;
99107
100108 if ( ! entryFunctionName || ! entryFunctionName . length ) {
@@ -117,7 +125,7 @@ export class Interpreter {
117125 const ast = this . parse ( script , moduleName ) ;
118126
119127 context = ( context && typeof context === 'object' ) ? context : { } ;
120- context = await this . assignLegacyImportContext ( ast , context ) ;
128+ context = this . assignLegacyImportContext ( ast , context ) ;
121129
122130 const globalScope = {
123131 ...this . initialScope ,
@@ -128,7 +136,7 @@ export class Interpreter {
128136 }
129137
130138
131- private async assignLegacyImportContext ( ast : AstBlock , context : object ) : Promise < object > {
139+ private assignLegacyImportContext ( ast : AstBlock , context : object ) : Record < string , unknown > {
132140 const importNodes = ast . body . filter ( n => n . type === 'import' ) as ImportNode [ ] ;
133141
134142 const jsImport = importNodes
@@ -140,7 +148,7 @@ export class Interpreter {
140148 context = { ...context , ...libraries } ;
141149 }
142150
143- return context ;
151+ return context as Record < string , unknown > ;
144152 }
145153
146154 registerPackagesLoader ( loader : PackageLoader ) {
0 commit comments