-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: remove erroneous
context.parentURL
property passed to load
hook
- Loading branch information
1 parent
ceaa299
commit 5e2ba51
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Flags: --expose-internals | ||
import '../common/index.mjs'; | ||
import mod from 'internal/modules/esm/loader'; | ||
import assert from 'assert'; | ||
|
||
const { ESMLoader } = mod; | ||
|
||
{ | ||
const esmLoader = new ESMLoader(); | ||
|
||
const originalSpecifier = 'foo/bar'; | ||
const importAssertions = { type: 'json' }; | ||
const parentURL = 'file:///entrypoint.js'; | ||
const resolvedURL = 'file:///foo/bar.js'; | ||
const suggestedFormat = 'test'; | ||
|
||
const customLoader1 = { | ||
resolve(specifier, context, defaultResolve) { | ||
assert.equal(specifier, originalSpecifier); | ||
assert.deepEqual(Object.keys(context), [ | ||
'conditions', | ||
'importAssertions', | ||
'parentURL', | ||
]); | ||
assert.ok(Array.isArray(context.conditions)); | ||
assert.equal(context.importAssertions, importAssertions); | ||
assert.equal(context.parentURL, parentURL); | ||
assert.equal(typeof defaultResolve, 'function'); | ||
|
||
// This doesn't matter. just to avoid errors | ||
return { | ||
format: suggestedFormat, | ||
url: resolvedURL, | ||
}; | ||
}, | ||
load(resolvedURL, context, defaultLoad) { | ||
assert.equal(resolvedURL, resolvedURL); | ||
assert.ok(new URL(resolvedURL)); | ||
assert.deepEqual(Object.keys(context), [ | ||
'format', | ||
'importAssertions', | ||
]); | ||
assert.equal(context.format, suggestedFormat); | ||
assert.equal(context.importAssertions, importAssertions); | ||
assert.equal(typeof defaultLoad, 'function'); | ||
|
||
// This doesn't matter. just to avoid errors | ||
return { | ||
format: 'module', | ||
source: '', | ||
}; | ||
}, | ||
}; | ||
|
||
esmLoader.addCustomLoaders(customLoader1); | ||
|
||
esmLoader.resolve( | ||
originalSpecifier, | ||
parentURL, | ||
importAssertions, | ||
); | ||
esmLoader.load( | ||
resolvedURL, | ||
{ | ||
format: suggestedFormat, | ||
importAssertions, | ||
}, | ||
function mockDefaultLoad() {}, | ||
); | ||
} |