Skip to content

Commit 31d4ef9

Browse files
committed
esm: fix support for URL instances in import.meta.resolve
PR-URL: #54690 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8433032 commit 31d4ef9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class ModuleLoader {
512512
* @returns {{ format: string, url: URL['href'] }}
513513
*/
514514
resolve(originalSpecifier, parentURL, importAttributes) {
515+
originalSpecifier = `${originalSpecifier}`;
515516
if (this.#customizations) {
516517
return this.#customizations.resolve(originalSpecifier, parentURL, importAttributes);
517518
}
@@ -530,6 +531,7 @@ class ModuleLoader {
530531
* `import.meta.resolve` which must happen synchronously.
531532
*/
532533
resolveSync(originalSpecifier, parentURL, importAttributes) {
534+
originalSpecifier = `${originalSpecifier}`;
533535
if (this.#customizations) {
534536
return this.#customizations.resolveSync(originalSpecifier, parentURL, importAttributes);
535537
}

test/es-module/test-esm-import-meta-resolve.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Flags: --experimental-import-meta-resolve
2-
import '../common/index.mjs';
2+
import { spawnPromisified } from '../common/index.mjs';
33
import assert from 'assert';
44
import { spawn } from 'child_process';
55
import { execPath } from 'process';
@@ -90,3 +90,20 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res
9090
cp.stdin.end('import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"');
9191
assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/);
9292
}
93+
94+
{
95+
const result = await spawnPromisified(execPath, [
96+
'--no-warnings',
97+
'--input-type=module',
98+
'--import', 'data:text/javascript,import{register}from"node:module";register("data:text/javascript,")',
99+
'--eval',
100+
'console.log(import.meta.resolve(new URL("http://example.com")))',
101+
]);
102+
103+
assert.deepStrictEqual(result, {
104+
code: 0,
105+
signal: null,
106+
stderr: '',
107+
stdout: 'http://example.com/\n',
108+
});
109+
}

0 commit comments

Comments
 (0)