From cdb0ea5c9d615b1ffdca82eb68d5de638f77b713 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Sun, 15 May 2022 03:51:49 +0900 Subject: [PATCH] console: remove a leading space between braces This commit removes a leading space 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 a28a561f179f03c..ea94704aa2e361f 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}` + + ` ${braces[1]}` + ); } } } diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index fe69409a63a9804..04f8566ea054d65 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)] }',