From 5723aaf3a3460120e6f20039836c033024036076 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Sun, 15 May 2022 03:51:49 +0900 Subject: [PATCH] console: remove spaces for the output is empty This commit removes extra spaces looking unnecessary if the `joinedOutput` of type `Array` is empty on `reduceToSingleString`. e.g) Proxy [ ] -> Proxy [] Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com --- lib/internal/util/inspect.js | 7 +++++-- test/parallel/test-util-inspect-proxy.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index a28a561f179f03..97ba51959d81cc 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -1939,9 +1939,12 @@ function reduceToSingleString( braces[0].length + base.length + 10; if (isBelowBreakLength(ctx, output, start, base)) { const joinedOutput = join(output, ', '); + const space = joinedOutput.length > 0 ? ' ' : ''; if (!joinedOutput.includes('\n')) { - return `${base ? `${base} ` : ''}${braces[0]} ${joinedOutput}` + - ` ${braces[1]}`; + return ( + `${base ? `${base} ` : ''}${braces[0]}${space}${joinedOutput}` + + `${space}${braces[1]}` + ); } } } diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index fe69409a63a980..45b8449aac2fac 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -70,7 +70,7 @@ assert.strictEqual(details[1], null); details = processUtil.getProxyDetails(r.proxy, false); assert.strictEqual(details, null); -assert.strictEqual(util.inspect(r.proxy), 'Proxy [ ]'); +assert.strictEqual(util.inspect(r.proxy), 'Proxy []'); assert.strictEqual( util.inspect(r, { showProxy: true }), '{ proxy: Proxy [ null, null ], revoke: [Function (anonymous)] }',