Skip to content

Commit 2a0a7d5

Browse files
Han5991Han-sangwook
authored andcommitted
util: skip compact grouping when breakLength is Infinity
1 parent 94ef233 commit 2a0a7d5

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

lib/internal/util/inspect.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,8 @@ function reduceToSingleString(
26302630
const entries = output.length;
26312631
// Group array elements together if the array contains at least six
26322632
// separate entries.
2633-
if (extrasType === kArrayExtrasType && entries > 6) {
2633+
if (extrasType === kArrayExtrasType && entries > 6 &&
2634+
NumberIsFinite(ctx.breakLength)) {
26342635
output = groupArrayElements(ctx, output, value);
26352636
}
26362637
// `ctx.currentDepth` is set to the most inner depth of the currently

test/parallel/test-util-inspect.js

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ assert.strictEqual(util.inspect(-5e-324), '-5e-324');
608608
assert.strictEqual(util.inspect(tree, deepOptions).includes('\n'), false);
609609
}
610610

611+
// `breakLength: Infinity` should prevent grouping even when depth is finite.
612+
{
613+
const arr = Array.from({ length: 10 }, (_, i) => i);
614+
const out = util.inspect(arr, { breakLength: Infinity, depth: 2, compact: 3 });
615+
assert.strictEqual(out.includes('\n'), false);
616+
}
617+
611618
// Test for Array constructor in different context.
612619
{
613620
const map = new Map();
@@ -2992,18 +2999,19 @@ assert.strictEqual(
29922999

29933000
out = util.inspect(obj, { compact: 1, breakLength: Infinity, colors: true });
29943001

3002+
const inlineArray = [
3003+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
3004+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
3005+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
3006+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
3007+
"\u001b[32m'foobar'\u001b[39m",
3008+
];
29953009
expected = [
29963010
'{',
29973011
' a: {',
29983012
' b: { x: \u001b[33m5\u001b[39m, c: \u001b[36m[Object]\u001b[39m }',
29993013
' },',
3000-
' b: [',
3001-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
3002-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
3003-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
3004-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
3005-
" \u001b[32m'foobar'\u001b[39m",
3006-
' ]',
3014+
` b: [ ${inlineArray.join(', ')} ]`,
30073015
'}',
30083016
].join('\n');
30093017

@@ -3012,25 +3020,8 @@ assert.strictEqual(
30123020
obj = Array.from({ length: 60 }).map((e, i) => i);
30133021
out = util.inspect(obj, { compact: 1, breakLength: Infinity, colors: true });
30143022

3015-
expected = [
3016-
'[',
3017-
' \u001b[33m0\u001b[39m, \u001b[33m1\u001b[39m, \u001b[33m2\u001b[39m, \u001b[33m3\u001b[39m,',
3018-
' \u001b[33m4\u001b[39m, \u001b[33m5\u001b[39m, \u001b[33m6\u001b[39m, \u001b[33m7\u001b[39m,',
3019-
' \u001b[33m8\u001b[39m, \u001b[33m9\u001b[39m, \u001b[33m10\u001b[39m, \u001b[33m11\u001b[39m,',
3020-
' \u001b[33m12\u001b[39m, \u001b[33m13\u001b[39m, \u001b[33m14\u001b[39m, \u001b[33m15\u001b[39m,',
3021-
' \u001b[33m16\u001b[39m, \u001b[33m17\u001b[39m, \u001b[33m18\u001b[39m, \u001b[33m19\u001b[39m,',
3022-
' \u001b[33m20\u001b[39m, \u001b[33m21\u001b[39m, \u001b[33m22\u001b[39m, \u001b[33m23\u001b[39m,',
3023-
' \u001b[33m24\u001b[39m, \u001b[33m25\u001b[39m, \u001b[33m26\u001b[39m, \u001b[33m27\u001b[39m,',
3024-
' \u001b[33m28\u001b[39m, \u001b[33m29\u001b[39m, \u001b[33m30\u001b[39m, \u001b[33m31\u001b[39m,',
3025-
' \u001b[33m32\u001b[39m, \u001b[33m33\u001b[39m, \u001b[33m34\u001b[39m, \u001b[33m35\u001b[39m,',
3026-
' \u001b[33m36\u001b[39m, \u001b[33m37\u001b[39m, \u001b[33m38\u001b[39m, \u001b[33m39\u001b[39m,',
3027-
' \u001b[33m40\u001b[39m, \u001b[33m41\u001b[39m, \u001b[33m42\u001b[39m, \u001b[33m43\u001b[39m,',
3028-
' \u001b[33m44\u001b[39m, \u001b[33m45\u001b[39m, \u001b[33m46\u001b[39m, \u001b[33m47\u001b[39m,',
3029-
' \u001b[33m48\u001b[39m, \u001b[33m49\u001b[39m, \u001b[33m50\u001b[39m, \u001b[33m51\u001b[39m,',
3030-
' \u001b[33m52\u001b[39m, \u001b[33m53\u001b[39m, \u001b[33m54\u001b[39m, \u001b[33m55\u001b[39m,',
3031-
' \u001b[33m56\u001b[39m, \u001b[33m57\u001b[39m, \u001b[33m58\u001b[39m, \u001b[33m59\u001b[39m',
3032-
']',
3033-
].join('\n');
3023+
const inlineNumbers = Array.from({ length: 60 }, (_, i) => `\u001b[33m${i}\u001b[39m`);
3024+
expected = `[ ${inlineNumbers.join(', ')} ]`;
30343025

30353026
assert.strictEqual(out, expected);
30363027

0 commit comments

Comments
 (0)