|
4 | 4 | require('internal/modules/cjs/loader'); |
5 | 5 |
|
6 | 6 | const { |
7 | | - Array, |
8 | | - ArrayIsArray, |
9 | 7 | FunctionPrototypeCall, |
10 | 8 | ObjectSetPrototypeOf, |
11 | 9 | PromisePrototypeThen, |
12 | | - SafePromiseAllReturnArrayLike, |
13 | 10 | SafeWeakMap, |
14 | 11 | } = primordials; |
15 | 12 |
|
@@ -246,51 +243,18 @@ class DefaultModuleLoader { |
246 | 243 | * |
247 | 244 | * This method must NOT be renamed: it functions as a dynamic import on a |
248 | 245 | * loader module. |
249 | | - * @param {string | string[]} specifiers Path(s) to the module. |
| 246 | + * @param {string} specifier The first parameter of an `import()` expression. |
250 | 247 | * @param {string} parentURL Path of the parent importing the module. |
251 | 248 | * @param {Record<string, string>} importAssertions Validations for the |
252 | 249 | * module import. |
253 | 250 | * @returns {Promise<ExportedHooks | KeyedExports[]>} |
254 | 251 | * A collection of module export(s) or a list of collections of module |
255 | 252 | * export(s). |
256 | 253 | */ |
257 | | - async import(specifiers, parentURL, importAssertions) { |
258 | | - // For loaders, `import` is passed multiple things to process, it returns a |
259 | | - // list pairing the url and exports collected. This is especially useful for |
260 | | - // error messaging, to identity from where an export came. But, in most |
261 | | - // cases, only a single url is being "imported" (ex `import()`), so there is |
262 | | - // only 1 possible url from which the exports were collected and it is |
263 | | - // already known to the caller. Nesting that in a list would only ever |
264 | | - // create redundant work for the caller, so it is later popped off the |
265 | | - // internal list. |
266 | | - const wasArr = ArrayIsArray(specifiers); |
267 | | - if (!wasArr) { specifiers = [specifiers]; } |
268 | | - |
269 | | - const count = specifiers.length; |
270 | | - const jobs = new Array(count); |
271 | | - |
272 | | - for (let i = 0; i < count; i++) { |
273 | | - jobs[i] = PromisePrototypeThen( |
274 | | - this |
275 | | - .getModuleJob(specifiers[i], parentURL, importAssertions) |
276 | | - .run(), |
277 | | - ({ module }) => module.getNamespace(), |
278 | | - ); |
279 | | - } |
280 | | - |
281 | | - const namespaces = await SafePromiseAllReturnArrayLike(jobs); |
282 | | - |
283 | | - if (!wasArr) { return namespaces[0]; } // We can skip the pairing below |
284 | | - |
285 | | - for (let i = 0; i < count; i++) { |
286 | | - namespaces[i] = { |
287 | | - __proto__: null, |
288 | | - url: specifiers[i], |
289 | | - exports: namespaces[i], |
290 | | - }; |
291 | | - } |
292 | | - |
293 | | - return namespaces; |
| 254 | + async import(specifier, parentURL, importAssertions) { |
| 255 | + const moduleJob = this.getModuleJob(specifier, parentURL, importAssertions); |
| 256 | + const { module } = await moduleJob.run(); |
| 257 | + return module.getNamespace(); |
294 | 258 | } |
295 | 259 |
|
296 | 260 | /** |
|
0 commit comments