Skip to content

Commit 13b63c2

Browse files
committed
multiple pending imports of the same URL with differing assertions
1 parent 38b2f97 commit 13b63c2

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lib/internal/modules/esm/loader.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const {
1919
globalThis,
2020
} = primordials;
2121

22+
const {
23+
deepStrictEqual
24+
} = require('assert/strict')
2225
const {
2326
ERR_INVALID_ARG_TYPE,
2427
ERR_INVALID_ARG_VALUE,
@@ -209,7 +212,8 @@ class ESMLoader {
209212

210213
return module;
211214
};
212-
const job = new ModuleJob(this, url, evalInstance, false, false);
215+
const job = new ModuleJob(
216+
this, url, undefined, evalInstance, false, false);
213217
this.moduleMap.set(url, job);
214218
const { module } = await job.run();
215219

@@ -226,7 +230,14 @@ class ESMLoader {
226230
// CommonJS will set functions for lazy job evaluation.
227231
if (typeof job === 'function') this.moduleMap.set(url, job = job());
228232

229-
if (job !== undefined) return job;
233+
if (job !== undefined) {
234+
try {
235+
deepStrictEqual(importAssertions || {}, job.importAssertions || {});
236+
return job;
237+
} catch {
238+
job = undefined;
239+
}
240+
}
230241

231242
const moduleProvider = async (url, isMain) => {
232243
const { format: finalFormat, source } = await this.load(
@@ -250,6 +261,7 @@ class ESMLoader {
250261
job = new ModuleJob(
251262
this,
252263
url,
264+
importAssertions,
253265
moduleProvider,
254266
parentURL === undefined,
255267
inspectBrk

lib/internal/modules/esm/module_job.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ const isCommonJSGlobalLikeNotDefinedError = (errorMessage) =>
5252
class ModuleJob {
5353
// `loader` is the Loader instance used for loading dependencies.
5454
// `moduleProvider` is a function
55-
constructor(loader, url, moduleProvider, isMain, inspectBrk) {
55+
constructor(loader, url, importAssertions, moduleProvider, isMain,
56+
inspectBrk) {
5657
this.loader = loader;
58+
this.importAssertions = importAssertions;
5759
this.isMain = isMain;
5860
this.inspectBrk = inspectBrk;
5961

test/es-module/test-esm-loader-modulemap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const stubModuleUrl = new URL('file://tmp/test');
1717
const stubModule = createDynamicModule(['default'], stubModuleUrl);
1818
const loader = new ESMLoader();
1919
const moduleMap = new ModuleMap();
20-
const moduleJob = new ModuleJob(loader, stubModule.module,
20+
const moduleJob = new ModuleJob(loader, stubModule.module, undefined,
2121
() => new Promise(() => {}));
2222

2323
assert.throws(

0 commit comments

Comments
 (0)