Skip to content

Commit

Permalink
console: remove spaces for the output is empty
Browse files Browse the repository at this point in the history
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
  • Loading branch information
daeyeon committed May 14, 2022
1 parent 8253a30 commit 5723aaf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)] }',
Expand Down

0 comments on commit 5723aaf

Please sign in to comment.