@@ -112,7 +112,7 @@ const EVAL_RESULT_VARIABLE = 'Object.<anonymous>';
112112
113113type RunScriptEvalResult = { [ EVAL_RESULT_VARIABLE ] : ModuleWrapper } ;
114114
115- const runtimeSupportsVmModules = typeof SourceTextModule === 'function' ;
115+ const runtimeSupportsVmModules = typeof SyntheticModule === 'function' ;
116116
117117/* eslint-disable-next-line no-redeclare */
118118class Runtime {
@@ -351,39 +351,15 @@ class Runtime {
351351 const module = new SourceTextModule ( transformedFile . code , {
352352 context,
353353 identifier : modulePath ,
354- importModuleDynamically : (
355- specifier : string ,
356- referencingModule : VMModule ,
357- ) => {
358- const resolved = this . _resolveModule (
359- referencingModule . identifier ,
360- specifier ,
361- ) ;
362- if (
363- this . _resolver . isCoreModule ( resolved ) ||
364- this . unstable_shouldLoadAsEsm ( resolved )
365- ) {
366- return this . loadEsmModule ( resolved ) ;
367- }
368-
369- return this . loadCjsAsEsm (
370- referencingModule . identifier ,
371- resolved ,
372- context ,
373- ) ;
374- } ,
354+ importModuleDynamically : this . linkModules . bind ( this ) ,
375355 initializeImportMeta ( meta : ImportMeta ) {
376356 meta . url = pathToFileURL ( modulePath ) . href ;
377357 } ,
378358 } ) ;
379359
380360 this . _esmoduleRegistry . set ( cacheKey , module ) ;
381361
382- await module . link ( ( specifier : string , referencingModule : VMModule ) =>
383- this . loadEsmModule (
384- this . _resolveModule ( referencingModule . identifier , specifier ) ,
385- ) ,
386- ) ;
362+ await module . link ( this . linkModules . bind ( this ) ) ;
387363
388364 await module . evaluate ( ) ;
389365 }
@@ -395,6 +371,25 @@ class Runtime {
395371 return module ;
396372 }
397373
374+ private async linkModules ( specifier : string , referencingModule : VMModule ) {
375+ const resolved = this . _resolveModule (
376+ referencingModule . identifier ,
377+ specifier ,
378+ ) ;
379+ if (
380+ this . _resolver . isCoreModule ( resolved ) ||
381+ this . unstable_shouldLoadAsEsm ( resolved )
382+ ) {
383+ return this . loadEsmModule ( resolved ) ;
384+ }
385+
386+ return this . loadCjsAsEsm (
387+ referencingModule . identifier ,
388+ resolved ,
389+ referencingModule . context ,
390+ ) ;
391+ }
392+
398393 async unstable_importModule (
399394 from : Config . Path ,
400395 moduleName ?: string ,
0 commit comments