Skip to content

Commit 5e2ba51

Browse files
esm: remove erroneous context.parentURL property passed to load hook
1 parent ceaa299 commit 5e2ba51

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ class ESMLoader {
282282
} = await this.load(url, {
283283
format,
284284
importAssertions,
285-
parentURL,
286285
});
287286

288287
const translator = translators.get(finalFormat);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Flags: --expose-internals
2+
import '../common/index.mjs';
3+
import mod from 'internal/modules/esm/loader';
4+
import assert from 'assert';
5+
6+
const { ESMLoader } = mod;
7+
8+
{
9+
const esmLoader = new ESMLoader();
10+
11+
const originalSpecifier = 'foo/bar';
12+
const importAssertions = { type: 'json' };
13+
const parentURL = 'file:///entrypoint.js';
14+
const resolvedURL = 'file:///foo/bar.js';
15+
const suggestedFormat = 'test';
16+
17+
const customLoader1 = {
18+
resolve(specifier, context, defaultResolve) {
19+
assert.equal(specifier, originalSpecifier);
20+
assert.deepEqual(Object.keys(context), [
21+
'conditions',
22+
'importAssertions',
23+
'parentURL',
24+
]);
25+
assert.ok(Array.isArray(context.conditions));
26+
assert.equal(context.importAssertions, importAssertions);
27+
assert.equal(context.parentURL, parentURL);
28+
assert.equal(typeof defaultResolve, 'function');
29+
30+
// This doesn't matter. just to avoid errors
31+
return {
32+
format: suggestedFormat,
33+
url: resolvedURL,
34+
};
35+
},
36+
load(resolvedURL, context, defaultLoad) {
37+
assert.equal(resolvedURL, resolvedURL);
38+
assert.ok(new URL(resolvedURL));
39+
assert.deepEqual(Object.keys(context), [
40+
'format',
41+
'importAssertions',
42+
]);
43+
assert.equal(context.format, suggestedFormat);
44+
assert.equal(context.importAssertions, importAssertions);
45+
assert.equal(typeof defaultLoad, 'function');
46+
47+
// This doesn't matter. just to avoid errors
48+
return {
49+
format: 'module',
50+
source: '',
51+
};
52+
},
53+
};
54+
55+
esmLoader.addCustomLoaders(customLoader1);
56+
57+
esmLoader.resolve(
58+
originalSpecifier,
59+
parentURL,
60+
importAssertions,
61+
);
62+
esmLoader.load(
63+
resolvedURL,
64+
{
65+
format: suggestedFormat,
66+
importAssertions,
67+
},
68+
function mockDefaultLoad() {},
69+
);
70+
}

0 commit comments

Comments
 (0)