GeezerVison is showing github.com — esm: fix support for `URL` instances in `import.meta.resolve` · nodejs/node@31d4ef9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -512,6 +512,7 @@ class ModuleLoader { | 512 | 512 | * @returns {{ format: string, url: URL['href'] }} | 513 | 513 | */ | 514 | 514 | resolve(originalSpecifier, parentURL, importAttributes) { | | 515 | + originalSpecifier = `${originalSpecifier}`; | 515 | 516 | if (this.#customizations) { | 516 | 517 | return this.#customizations.resolve(originalSpecifier, parentURL, importAttributes); | 517 | 518 | } | @@ -530,6 +531,7 @@ class ModuleLoader { | 530 | 531 | * `import.meta.resolve` which must happen synchronously. | 531 | 532 | */ | 532 | 533 | resolveSync(originalSpecifier, parentURL, importAttributes) { | | 534 | + originalSpecifier = `${originalSpecifier}`; | 533 | 535 | if (this.#customizations) { | 534 | 536 | return this.#customizations.resolveSync(originalSpecifier, parentURL, importAttributes); | 535 | 537 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-meta-resolve.mjs +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // Flags: --experimental-import-meta-resolve | 2 | | -import '../common/index.mjs'; | | 2 | +import { spawnPromisified } from '../common/index.mjs'; | 3 | 3 | import assert from 'assert'; | 4 | 4 | import { spawn } from 'child_process'; | 5 | 5 | import { execPath } from 'process'; | @@ -90,3 +90,20 @@ await assert.rejects(import('data:text/javascript,export default import.meta.res | 90 | 90 | cp.stdin.end('import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"'); | 91 | 91 | assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/); | 92 | 92 | } | | 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 | +} |
|