Skip to content

Commit

Permalink
esm: remove erroneous context.parentURL property passed to load hook
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobJingleheimer committed Feb 14, 2022
1 parent ceaa299 commit 32f8ed1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/internal/modules/esm/loader.js
Expand Up @@ -282,7 +282,6 @@ class ESMLoader {
} = await this.load(url, {
format,
importAssertions,
parentURL,
});

const translator = translators.get(finalFormat);
Expand Down
72 changes: 72 additions & 0 deletions test/es-module/test-esm-loader-hooks.mjs
@@ -0,0 +1,72 @@
// Flags: --expose-internals
import '../common/index.mjs';
import ESMLoader from '../../lib/internal/modules/esm/loader.js';
import assert from 'assert';

(function testHookArgs() {
const esmLoader = new ESMLoader();

const originalSpecifier = 'foo/bar';
const importAssertions = { type: 'json' };
const parentURL = 'entrypoint.js';
const resolvedURL = 'foo/bar.js';
const suggestedFormat = 'test';

const customLoader1 = {
resolve(specifier, context, defaultResolve) {
assert.strictEqual(specifier, originalSpecifier);
assert.strictEqual(Object.keys(context), [
'conditions',
'importAssertions',
'parentURL',
]);
assert.strictEqual(typeof context.conditions, 'array');
assert.strictEqual(typeof context.importAssertions, 'array');
assert.strictEqual(context.parentURL, parentURL);
assert.strictEqual(typeof defaultResolve, 'function');

// This doesn't matter. just to avoid errors
return {
format: suggestedFormat,
url: resolvedURL,
};
},
load(resolvedURL, context, defaultLoad) {
assert.strictEqual(resolvedURL, resolvedURL);
assert(new URL(resolvedURL));
assert.strictEqual(Object.keys(context), [
'format',
'importAssertions',
]);
assert.strictEqual(context.format, suggestedFormat);
assert.strictEqual(typeof context.importAssertions, importAssertions);
assert.strictEqual(typeof defaultLoad, 'function');

// This doesn't matter. just to avoid errors
return {
format: 'module',
source: '',
};
},
};

esmLoader.addCustomLoaders(customLoader1);

esmLoader.resolve(
originalSpecifier,
{
conditions: [],
importAssertions,
parentURL,
},
function mockDefaultResolve() {},
);
esmLoader.load(
resolvedURL,
{
format: suggestedFormat,
importAssertions,
},
function mockDefaultLoad() {},
);
})();

0 comments on commit 32f8ed1

Please sign in to comment.