@@ -28,6 +28,7 @@ const {
2828 kErrored,
2929 kEvaluated,
3030 kEvaluating,
31+ kDeferPhase,
3132 kEvaluationPhase,
3233 kInstantiated,
3334 kUninstantiated,
@@ -164,7 +165,7 @@ class ModuleJobBase {
164165 debug ( `ModuleJobBase.syncLink() ${ this . url } -> ${ request . specifier } ` , job ) ;
165166 assert ( ! isPromise ( job ) ) ;
166167 assert ( job . module instanceof ModuleWrap ) ;
167- if ( request . phase === kEvaluationPhase ) {
168+ if ( this . shouldRunModule ( request . phase ) ) {
168169 ArrayPrototypePush ( evaluationDepJobs , job ) ;
169170 }
170171 modules [ idx ] = job . module ;
@@ -199,6 +200,13 @@ class ModuleJobBase {
199200 }
200201 }
201202 }
203+
204+ shouldLinkModule ( phase ) {
205+ return phase >= kDeferPhase ;
206+ }
207+ shouldRunModule ( phase ) {
208+ return phase === kEvaluationPhase ;
209+ }
202210}
203211
204212/* A ModuleJob tracks the loading of a single Module, and the ModuleJobs of
@@ -227,7 +235,7 @@ class ModuleJob extends ModuleJobBase {
227235 this . modulePromise = PromiseResolve ( moduleOrModulePromise ) ;
228236 }
229237
230- if ( this . phase === kEvaluationPhase ) {
238+ if ( this . shouldLinkModule ( this . phase ) ) {
231239 // Promise for the list of all dependencyJobs.
232240 this . linked = this . link ( requestType ) ;
233241 // This promise is awaited later anyway, so silence
@@ -279,7 +287,7 @@ class ModuleJob extends ModuleJobBase {
279287 const dependencyJobPromise = this . loader . getOrCreateModuleJob ( this . url , request , requestType ) ;
280288 const modulePromise = PromisePrototypeThen ( dependencyJobPromise , ( job ) => {
281289 debug ( `ModuleJob.asyncLink() ${ this . url } -> ${ request . specifier } ` , job ) ;
282- if ( request . phase === kEvaluationPhase ) {
290+ if ( this . shouldRunModule ( request . phase ) ) {
283291 ArrayPrototypePush ( evaluationDepJobs , job ) ;
284292 }
285293 return job . modulePromise ;
@@ -380,7 +388,7 @@ class ModuleJob extends ModuleJobBase {
380388 }
381389
382390 runSync ( parent ) {
383- assert ( this . phase === kEvaluationPhase ) ;
391+ assert ( this . shouldRunModule ( this . phase ) ) ;
384392 assert ( this . module instanceof ModuleWrap ) ;
385393 let status = this . module . getStatus ( ) ;
386394
@@ -427,7 +435,7 @@ class ModuleJob extends ModuleJobBase {
427435
428436 async run ( isEntryPoint = false ) {
429437 debug ( 'ModuleJob.run()' , this . module ) ;
430- assert ( this . phase === kEvaluationPhase ) ;
438+ assert ( this . shouldRunModule ( this . phase ) ) ;
431439 await this . #instantiate( ) ;
432440 if ( isEntryPoint ) {
433441 globalThis [ entry_point_module_private_symbol ] = this . module ;
@@ -475,7 +483,7 @@ class ModuleJobSync extends ModuleJobBase {
475483 assert ( this . module instanceof ModuleWrap ) ;
476484 this . linked = undefined ;
477485 this . type = importAttributes . type ;
478- if ( phase === kEvaluationPhase ) {
486+ if ( this . shouldLinkModule ( phase ) ) {
479487 this . linked = this . link ( requestType ) ;
480488 }
481489 }
@@ -494,7 +502,7 @@ class ModuleJobSync extends ModuleJobBase {
494502 }
495503
496504 async run ( ) {
497- assert ( this . phase === kEvaluationPhase ) ;
505+ assert ( this . shouldRunModule ( this . phase ) ) ;
498506 // This path is hit by a require'd module that is imported again.
499507 const status = this . module . getStatus ( ) ;
500508 debug ( 'ModuleJobSync.run()' , status , this . module ) ;
@@ -523,7 +531,7 @@ class ModuleJobSync extends ModuleJobBase {
523531
524532 runSync ( parent ) {
525533 debug ( 'ModuleJobSync.runSync()' , this . module ) ;
526- assert ( this . phase === kEvaluationPhase ) ;
534+ assert ( this . shouldRunModule ( this . phase ) ) ;
527535 // TODO(joyeecheung): add the error decoration logic from the async instantiate.
528536 this . module . instantiate ( ) ;
529537 // If --experimental-print-required-tla is true, proceeds to evaluation even
0 commit comments