Skip to content

Commit 010dd4c

Browse files
JakobJingleheimerbengl
authored andcommitted
esm: remove erroneous context.parentURL property passed to load hook
PR-URL: #41975 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 98167e8 commit 010dd4c

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

‎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
}=awaitthis.load(url,{
283283
format,
284284
importAssertions,
285-
parentURL,
286285
});
287286

288287
consttranslator=translators.get(finalFormat);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Flags: --expose-internals
2+
import{mustCall}from'../common/index.mjs';
3+
importesmLoaderModulefrom'internal/modules/esm/loader';
4+
importassertfrom'assert';
5+
6+
const{ ESMLoader }=esmLoaderModule;
7+
8+
/**
9+
* Verify custom hooks are called with appropriate arguments.
10+
*/
11+
{
12+
constesmLoader=newESMLoader();
13+
14+
constoriginalSpecifier='foo/bar';
15+
constimportAssertions=Object.assign(
16+
Object.create(null),
17+
{type: 'json'},
18+
);
19+
constparentURL='file:///entrypoint.js';
20+
constresolvedURL='file:///foo/bar.js';
21+
constsuggestedFormat='test';
22+
23+
functionresolve(specifier,context,defaultResolve){
24+
assert.strictEqual(specifier,originalSpecifier);
25+
// Ensure `context` has all and only the properties it's supposed to
26+
assert.deepStrictEqual(Object.keys(context),[
27+
'conditions',
28+
'importAssertions',
29+
'parentURL',
30+
]);
31+
assert.ok(Array.isArray(context.conditions));
32+
assert.deepStrictEqual(context.importAssertions,importAssertions);
33+
assert.strictEqual(context.parentURL,parentURL);
34+
assert.strictEqual(typeofdefaultResolve,'function');
35+
36+
return{
37+
format: suggestedFormat,
38+
url: resolvedURL,
39+
};
40+
}
41+
42+
functionload(resolvedURL,context,defaultLoad){
43+
assert.strictEqual(resolvedURL,resolvedURL);
44+
assert.ok(newURL(resolvedURL));
45+
// Ensure `context` has all and only the properties it's supposed to
46+
assert.deepStrictEqual(Object.keys(context),[
47+
'format',
48+
'importAssertions',
49+
]);
50+
assert.strictEqual(context.format,suggestedFormat);
51+
assert.deepStrictEqual(context.importAssertions,importAssertions);
52+
assert.strictEqual(typeofdefaultLoad,'function');
53+
54+
// This doesn't matter (just to avoid errors)
55+
return{
56+
format: 'module',
57+
source: '',
58+
};
59+
}
60+
61+
constcustomLoader={
62+
// Ensure ESMLoader actually calls the custom hooks
63+
resolve: mustCall(resolve),
64+
load: mustCall(load),
65+
};
66+
67+
esmLoader.addCustomLoaders(customLoader);
68+
69+
// Manually trigger hooks (since ESMLoader is not actually running)
70+
constjob=awaitesmLoader.getModuleJob(
71+
originalSpecifier,
72+
parentURL,
73+
importAssertions,
74+
);
75+
awaitjob.modulePromise;
76+
}

0 commit comments

Comments
 (0)