* Synchronously link the module and its dependencies. * @param {ModuleRequestType} requestType Type of the module request. * @returns {ModuleJobBase[]}
(requestType)
| 146 | * @returns {ModuleJobBase[]} |
| 147 | */ |
| 148 | syncLink(requestType) { |
| 149 | // Store itself into the cache first before linking in case there are circular |
| 150 | // references in the linking. Track whether we're overwriting an existing entry |
| 151 | // so we know whether to remove the temporary entry in the finally block. |
| 152 | const hadPreviousEntry = this.loader.loadCache.get(this.url, this.type) !== undefined; |
| 153 | this.loader.loadCache.set(this.url, this.type, this); |
| 154 | const moduleRequests = this.module.getModuleRequests(); |
| 155 | // Modules should be aligned with the moduleRequests array in order. |
| 156 | const modules = Array(moduleRequests.length); |
| 157 | const evaluationDepJobs = []; |
| 158 | this.commonJsDeps = Array(moduleRequests.length); |
| 159 | try { |
| 160 | for (let idx = 0; idx < moduleRequests.length; idx++) { |
| 161 | const request = moduleRequests[idx]; |
| 162 | // TODO(joyeecheung): split this into two iterators, one for resolving and one for loading so |
| 163 | // that hooks can pre-fetch sources off-thread. |
| 164 | const job = this.loader.getOrCreateModuleJob(this.url, request, requestType); |
| 165 | debug(`ModuleJobBase.syncLink() ${this.url} -> ${request.specifier}`, job); |
| 166 | assert(!isPromise(job)); |
| 167 | assert(job.module instanceof ModuleWrap); |
| 168 | if (this.shouldRunModule(request.phase)) { |
| 169 | ArrayPrototypePush(evaluationDepJobs, job); |
| 170 | } |
| 171 | modules[idx] = job.module; |
| 172 | this.commonJsDeps[idx] = job.module.isCommonJS; |
| 173 | } |
| 174 | this.module.link(modules); |
| 175 | } finally { |
| 176 | if (!hadPreviousEntry) { |
| 177 | // Remove the temporary entry. On failure this ensures subsequent attempts |
| 178 | // don't return a broken job. On success the caller |
| 179 | // (#getOrCreateModuleJobAfterResolve) will re-insert under the correct key. |
| 180 | this.loader.loadCache.delete(this.url, this.type); |
| 181 | } |
| 182 | // If there was a previous entry (ensurePhase() path), leave this in cache - |
| 183 | // it is the upgraded job and the caller will not re-insert. |
| 184 | } |
| 185 | |
| 186 | return evaluationDepJobs; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Ensure that this ModuleJob is moving towards the required phase |