Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/internal/main/eval_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
const {
prepareMainThreadExecution
} = require('internal/bootstrap/pre_execution');
const {
pathToFileURL,
} = require('internal/url');

const { getOptionValue } = require('internal/options');

Expand All @@ -24,7 +27,7 @@ readStdin((code) => {

const print = getOptionValue('--print');
if (getOptionValue('--input-type') === 'module')
evalModule(code, print);
evalModule(code, print, pathToFileURL(`${process.cwd()}/[stdin]`).href);
else
evalScript('[stdin]',
code,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ESMLoader {
/**
* The index for assigning unique URLs to anonymous module evaluation
*/
evalIndex = 0;
#evalIndex = 0;

/**
* Registry of loaded modules, akin to `require.cache`
Expand Down Expand Up @@ -202,7 +202,7 @@ class ESMLoader {

async eval(
source,
url = pathToFileURL(`${process.cwd()}/[eval${++this.evalIndex}]`).href
url = pathToFileURL(`${process.cwd()}/[eval${++this.#evalIndex}]`).href
) {
const evalInstance = (url) => {
const { ModuleWrap, callbackMap } = internalBinding('module_wrap');
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ function tryGetCwd() {
}
}

function evalModule(source, print) {
function evalModule(source, print, url = undefined) {
if (print) {
throw new ERR_EVAL_ESM_CANNOT_PRINT();
}
const { loadESM } = require('internal/process/esm_loader');
const { handleMainPromise } = require('internal/modules/run_main');
return handleMainPromise(loadESM((loader) => loader.eval(source)));
return handleMainPromise(loadESM((loader) => loader.eval(source, url)));
}

function evalScript(name, body, breakFirstLine, print) {
Expand Down