From 0b65872e983b3b84220d74d74119973ae7704adb Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 10 Jan 2023 21:47:00 +0100 Subject: [PATCH 1/4] esm: mark `importAssertions` as required We already always specify a value, and failing to do so would likely be a bug. --- lib/internal/modules/esm/loader.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 04982ca94a9221..a4197e723ce50a 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -295,21 +295,15 @@ class ESMLoader { * @param {string} originalSpecifier The specified URL path of the module to * be resolved. * @param {string} [parentURL] The URL path of the module's parent. - * @param {ImportAssertions} [importAssertions] Assertions from the import + * @param {ImportAssertions} importAssertions Assertions from the import * statement or expression. * @returns {Promise<{ format: string, url: URL['href'] }>} */ - async resolve( - originalSpecifier, - parentURL, - importAssertions = { __proto__: null }, - ) { + async resolve(originalSpecifier, parentURL, importAssertions) { if (this.#hooks) { return this.#hooks.resolve(originalSpecifier, parentURL, importAssertions); } - if (!this.#defaultResolve) { - this.#defaultResolve = require('internal/modules/esm/resolve').defaultResolve; - } + this.#defaultResolve ??= require('internal/modules/esm/resolve').defaultResolve; const context = { __proto__: null, conditions: this.#defaultConditions, @@ -332,9 +326,7 @@ class ESMLoader { if (this.#hooks) { loadResult = await this.#hooks.load(url, context); } else { - if (!this.#defaultLoad) { - this.#defaultLoad = require('internal/modules/esm/load').defaultLoad; - } + this.#defaultLoad ??= require('internal/modules/esm/load').defaultLoad; loadResult = await this.#defaultLoad(url, context); } From 4c144331fe085cb0485c46267b902d62eeaf76b0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 10 Jan 2023 23:26:57 +0100 Subject: [PATCH 2/4] Apply suggestions from code review --- lib/internal/modules/esm/loader.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index a4197e723ce50a..8abeffd70008eb 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -303,7 +303,9 @@ class ESMLoader { if (this.#hooks) { return this.#hooks.resolve(originalSpecifier, parentURL, importAssertions); } - this.#defaultResolve ??= require('internal/modules/esm/resolve').defaultResolve; + if (!this.#defaultResolve) { + this.#defaultResolve = require('internal/modules/esm/resolve'). defaultResolve; + } const context = { __proto__: null, conditions: this.#defaultConditions, @@ -326,7 +328,9 @@ class ESMLoader { if (this.#hooks) { loadResult = await this.#hooks.load(url, context); } else { - this.#defaultLoad ??= require('internal/modules/esm/load').defaultLoad; + if (!this.#defaultLoad) { + this.#defaultLoad = require('internal/modules/esm/load').defaultLoad; + } loadResult = await this.#defaultLoad(url, context); } From 8fc2ece8005e7e362ac021540bb5987cbdd81a92 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 10 Jan 2023 23:31:30 +0100 Subject: [PATCH 3/4] Update lib/internal/modules/esm/loader.js --- lib/internal/modules/esm/loader.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 8abeffd70008eb..b3d34336b93739 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -303,9 +303,9 @@ class ESMLoader { if (this.#hooks) { return this.#hooks.resolve(originalSpecifier, parentURL, importAssertions); } - if (!this.#defaultResolve) { - this.#defaultResolve = require('internal/modules/esm/resolve'). defaultResolve; - } + if (!this.#defaultResolve) { + this.#defaultResolve = require('internal/modules/esm/resolve'). defaultResolve; + } const context = { __proto__: null, conditions: this.#defaultConditions, From cd7f6e652d81ef6547358551629cbad7892e1aae Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 10 Jan 2023 23:31:51 +0100 Subject: [PATCH 4/4] Update lib/internal/modules/esm/loader.js --- lib/internal/modules/esm/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index b3d34336b93739..9834bce7a90b9c 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -304,7 +304,7 @@ class ESMLoader { return this.#hooks.resolve(originalSpecifier, parentURL, importAssertions); } if (!this.#defaultResolve) { - this.#defaultResolve = require('internal/modules/esm/resolve'). defaultResolve; + this.#defaultResolve = require('internal/modules/esm/resolve').defaultResolve; } const context = { __proto__: null,