From ea968d54c5908703f04af581e375f8f1a8c99ff9 Mon Sep 17 00:00:00 2001 From: Voltrex Date: Sat, 6 Nov 2021 18:29:33 +0330 Subject: [PATCH] process: refactor execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Removed unreachable code of the `evalModule()` function as an early error is thrown when the `print` parameter is a truthy value. • Make use of the nullish coalescing operator. PR-URL: https://github.com/nodejs/node/pull/40664 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Minwoo Jung --- lib/internal/process/execution.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index f28baeb538a528..2bed5f3c762cf0 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -42,15 +42,9 @@ function evalModule(source, print) { if (print) { throw new ERR_EVAL_ESM_CANNOT_PRINT(); } - const { log } = require('internal/console/global'); const { loadESM } = require('internal/process/esm_loader'); const { handleMainPromise } = require('internal/modules/run_main'); - return handleMainPromise(loadESM(async (loader) => { - const { result } = await loader.eval(source); - if (print) { - log(result); - } - })); + return handleMainPromise(loadESM((loader) => loader.eval(source))); } function evalScript(name, body, breakFirstLine, print) { @@ -158,7 +152,7 @@ function createOnGlobalUncaughtException() { 'Exception', 'Exception', null, - er ? er : {}); + er ?? {}); } } catch {} // Ignore the exception. Diagnostic reporting is unavailable. }