* @param {ModuleRequestType} requestType Type of the module request. * @returns {Promise }
(requestType)
| 266 | * @returns {Promise<ModuleJobBase[]>} |
| 267 | */ |
| 268 | async #asyncLink(requestType) { |
| 269 | assert(this.loader.isForAsyncLoaderHookWorker); |
| 270 | this.module = await this.modulePromise; |
| 271 | assert(this.module instanceof ModuleWrap); |
| 272 | const moduleRequests = this.module.getModuleRequests(); |
| 273 | // Create an ArrayLike to avoid calling into userspace with `.then` |
| 274 | // when returned from the async function. |
| 275 | // Modules should be aligned with the moduleRequests array in order. |
| 276 | const modulePromises = Array(moduleRequests.length); |
| 277 | const evaluationDepJobs = []; |
| 278 | this.commonJsDeps = Array(moduleRequests.length); |
| 279 | for (let idx = 0; idx < moduleRequests.length; idx++) { |
| 280 | const request = moduleRequests[idx]; |
| 281 | // Explicitly keeping track of dependency jobs is needed in order |
| 282 | // to flatten out the dependency graph below in `asyncInstantiate()`, |
| 283 | // so that circular dependencies can't cause a deadlock by two of |
| 284 | // these `link` callbacks depending on each other. |
| 285 | // TODO(joyeecheung): split this into two iterators, one for resolving and one for loading so |
| 286 | // that hooks can pre-fetch sources off-thread. |
| 287 | const dependencyJobPromise = this.loader.getOrCreateModuleJob(this.url, request, requestType); |
| 288 | const modulePromise = PromisePrototypeThen(dependencyJobPromise, (job) => { |
| 289 | debug(`ModuleJob.asyncLink() ${this.url} -> ${request.specifier}`, job); |
| 290 | if (this.shouldRunModule(request.phase)) { |
| 291 | ArrayPrototypePush(evaluationDepJobs, job); |
| 292 | } |
| 293 | return job.modulePromise; |
| 294 | }); |
| 295 | modulePromises[idx] = modulePromise; |
| 296 | } |
| 297 | const modules = await SafePromiseAllReturnArrayLike(modulePromises); |
| 298 | for (let idx = 0; idx < moduleRequests.length; idx++) { |
| 299 | this.commonJsDeps[idx] = modules[idx].isCommonJS; |
| 300 | } |
| 301 | |
| 302 | this.module.link(modules); |
| 303 | return evaluationDepJobs; |
| 304 | } |
| 305 | |
| 306 | #instantiate() { |
| 307 | if (this.instantiated === undefined) { |
no test coverage detected