Skip to content

Commit

Permalink
multiple pending imports of the same URL with differing assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Oct 13, 2021
1 parent 38b2f97 commit 13b63c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const {
globalThis,
} = primordials;

const {
deepStrictEqual
} = require('assert/strict')
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
Expand Down Expand Up @@ -209,7 +212,8 @@ class ESMLoader {

return module;
};
const job = new ModuleJob(this, url, evalInstance, false, false);
const job = new ModuleJob(
this, url, undefined, evalInstance, false, false);
this.moduleMap.set(url, job);
const { module } = await job.run();

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

if (job !== undefined) return job;
if (job !== undefined) {
try {
deepStrictEqual(importAssertions || {}, job.importAssertions || {});
return job;
} catch {
job = undefined;
}
}

const moduleProvider = async (url, isMain) => {
const { format: finalFormat, source } = await this.load(
Expand All @@ -250,6 +261,7 @@ class ESMLoader {
job = new ModuleJob(
this,
url,
importAssertions,
moduleProvider,
parentURL === undefined,
inspectBrk
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ const isCommonJSGlobalLikeNotDefinedError = (errorMessage) =>
class ModuleJob {
// `loader` is the Loader instance used for loading dependencies.
// `moduleProvider` is a function
constructor(loader, url, moduleProvider, isMain, inspectBrk) {
constructor(loader, url, importAssertions, moduleProvider, isMain,
inspectBrk) {
this.loader = loader;
this.importAssertions = importAssertions;
this.isMain = isMain;
this.inspectBrk = inspectBrk;

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-modulemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const stubModuleUrl = new URL('file://tmp/test');
const stubModule = createDynamicModule(['default'], stubModuleUrl);
const loader = new ESMLoader();
const moduleMap = new ModuleMap();
const moduleJob = new ModuleJob(loader, stubModule.module,
const moduleJob = new ModuleJob(loader, stubModule.module, undefined,
() => new Promise(() => {}));

assert.throws(
Expand Down

0 comments on commit 13b63c2

Please sign in to comment.