From b12f55dd3920f6ea1be0edd8b64ce5012fb461aa Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 31 Oct 2026 17:36:54 +0500 Subject: [PATCH] lib: end --eval crypto wrapper code with a newline Assisted-by: Claude Code Signed-off-by: lazerg --- lib/internal/main/eval_string.js | 2 +- test/parallel/test-cli-eval.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/eval_string.js b/lib/internal/main/eval_string.js index 998c3fb4ada5..b76f0390067e 100644 --- a/lib/internal/main/eval_string.js +++ b/lib/internal/main/eval_string.js @@ -70,7 +70,7 @@ if (inputType === 'module') { evalFunction('[eval]', shouldDefineCrypto ? ( - print ? `let crypto=require("node:crypto");{${code}}` : `(crypto=>{{${code}}})(require('node:crypto'))` + print ? `let crypto=require("node:crypto");{${code}\n}` : `(crypto=>{{${code}\n}})(require('node:crypto'))` ) : code, getOptionValue('--inspect-brk'), print, diff --git a/test/parallel/test-cli-eval.js b/test/parallel/test-cli-eval.js index 5b090279621f..660d308a8fb2 100644 --- a/test/parallel/test-cli-eval.js +++ b/test/parallel/test-cli-eval.js @@ -329,6 +329,14 @@ if (common.hasCrypto) { common.mustSucceed((stdout) => { assert.match(stdout, /[0-9a-f]{32}/i); })); + child.execFile(process.execPath, ['-e', 'console.log(typeof crypto.randomBytes) // comment'], + common.mustSucceed((stdout) => { + assert.strictEqual(stdout, 'function\n'); + })); + child.execFile(process.execPath, ['-p', 'typeof crypto.randomBytes // comment'], + common.mustSucceed((stdout) => { + assert.strictEqual(stdout, 'function\n'); + })); } // Assert that overriding crypto works. child.exec(