Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c150976

Browse filesBrowse files
aduh95targos
authored andcommitted
esm: initialize import.meta on eval
PR-URL: #47551 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 3154543 commit c150976
Copy full SHA for c150976

File tree

Expand file treeCollapse file tree

2 files changed

+39
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/esm/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class DefaultModuleLoader {
119119
const { setCallbackForWrap } = require('internal/modules/esm/utils');
120120
const module = new ModuleWrap(url, undefined, source, 0, 0);
121121
setCallbackForWrap(module, {
122+
initializeImportMeta: (meta, wrap) => this.importMetaInitialize(meta, { url }),
122123
importModuleDynamically: (specifier, { url }, importAssertions) => {
123124
return this.import(specifier, url, importAssertions);
124125
},
Collapse file

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

Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-meta-resolve.mjs
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Flags: --experimental-import-meta-resolve
22
import '../common/index.mjs';
33
import assert from 'assert';
4+
import { spawn } from 'child_process';
5+
import { execPath } from 'process';
46

57
const dirname = import.meta.url.slice(0, import.meta.url.lastIndexOf('/') + 1);
68
const fixtures = dirname.slice(0, dirname.lastIndexOf('/', dirname.length - 2) + 1) + 'fixtures/';
@@ -30,3 +32,39 @@ assert.strictEqual(
3032
);
3133
assert.strictEqual(import.meta.resolve('baz/', fixtures),
3234
fixtures + 'node_modules/baz/');
35+
36+
{
37+
const cp = spawn(execPath, [
38+
'--experimental-import-meta-resolve',
39+
'--input-type=module',
40+
'--eval', 'console.log(typeof import.meta.resolve)',
41+
]);
42+
assert.match((await cp.stdout.toArray()).toString(), /^function\r?\n$/);
43+
}
44+
45+
{
46+
const cp = spawn(execPath, [
47+
'--experimental-import-meta-resolve',
48+
'--input-type=module',
49+
]);
50+
cp.stdin.end('console.log(typeof import.meta.resolve)');
51+
assert.match((await cp.stdout.toArray()).toString(), /^function\r?\n$/);
52+
}
53+
54+
{
55+
const cp = spawn(execPath, [
56+
'--experimental-import-meta-resolve',
57+
'--input-type=module',
58+
'--eval', 'import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"',
59+
]);
60+
assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/);
61+
}
62+
63+
{
64+
const cp = spawn(execPath, [
65+
'--experimental-import-meta-resolve',
66+
'--input-type=module',
67+
]);
68+
cp.stdin.end('import "data:text/javascript,console.log(import.meta.resolve(%22node:os%22))"');
69+
assert.match((await cp.stdout.toArray()).toString(), /^node:os\r?\n$/);
70+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.