Skip to content

Commit 3a818c9

Browse files
committed
util: skip compact grouping when breakLength is Infinity
1 parent a3ba562 commit 3a818c9

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();
@@ -2761,18 +2768,19 @@ assert.strictEqual(
27612768

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

2771+
const inlineArray = [
2772+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
2773+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
2774+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
2775+
"\u001b[32m'foobar'\u001b[39m", "\u001b[32m'baz'\u001b[39m",
2776+
"\u001b[32m'foobar'\u001b[39m",
2777+
];
27642778
expected = [
27652779
'{',
27662780
' a: {',
27672781
' b: { x: \u001b[33m5\u001b[39m, c: \u001b[36m[Object]\u001b[39m }',
27682782
' },',
2769-
' b: [',
2770-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
2771-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
2772-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
2773-
" \u001b[32m'foobar'\u001b[39m, \u001b[32m'baz'\u001b[39m,",
2774-
" \u001b[32m'foobar'\u001b[39m",
2775-
' ]',
2783+
` b: [ ${inlineArray.join(', ')} ]`,
27762784
'}',
27772785
].join('\n');
27782786

@@ -2781,25 +2789,8 @@ assert.strictEqual(
27812789
obj = Array.from({ length: 60 }).map((e, i) => i);
27822790
out = util.inspect(obj, { compact: 1, breakLength: Infinity, colors: true });
27832791

2784-
expected = [
2785-
'[',
2786-
' \u001b[33m0\u001b[39m, \u001b[33m1\u001b[39m, \u001b[33m2\u001b[39m, \u001b[33m3\u001b[39m,',
2787-
' \u001b[33m4\u001b[39m, \u001b[33m5\u001b[39m, \u001b[33m6\u001b[39m, \u001b[33m7\u001b[39m,',
2788-
' \u001b[33m8\u001b[39m, \u001b[33m9\u001b[39m, \u001b[33m10\u001b[39m, \u001b[33m11\u001b[39m,',
2789-
' \u001b[33m12\u001b[39m, \u001b[33m13\u001b[39m, \u001b[33m14\u001b[39m, \u001b[33m15\u001b[39m,',
2790-
' \u001b[33m16\u001b[39m, \u001b[33m17\u001b[39m, \u001b[33m18\u001b[39m, \u001b[33m19\u001b[39m,',
2791-
' \u001b[33m20\u001b[39m, \u001b[33m21\u001b[39m, \u001b[33m22\u001b[39m, \u001b[33m23\u001b[39m,',
2792-
' \u001b[33m24\u001b[39m, \u001b[33m25\u001b[39m, \u001b[33m26\u001b[39m, \u001b[33m27\u001b[39m,',
2793-
' \u001b[33m28\u001b[39m, \u001b[33m29\u001b[39m, \u001b[33m30\u001b[39m, \u001b[33m31\u001b[39m,',
2794-
' \u001b[33m32\u001b[39m, \u001b[33m33\u001b[39m, \u001b[33m34\u001b[39m, \u001b[33m35\u001b[39m,',
2795-
' \u001b[33m36\u001b[39m, \u001b[33m37\u001b[39m, \u001b[33m38\u001b[39m, \u001b[33m39\u001b[39m,',
2796-
' \u001b[33m40\u001b[39m, \u001b[33m41\u001b[39m, \u001b[33m42\u001b[39m, \u001b[33m43\u001b[39m,',
2797-
' \u001b[33m44\u001b[39m, \u001b[33m45\u001b[39m, \u001b[33m46\u001b[39m, \u001b[33m47\u001b[39m,',
2798-
' \u001b[33m48\u001b[39m, \u001b[33m49\u001b[39m, \u001b[33m50\u001b[39m, \u001b[33m51\u001b[39m,',
2799-
' \u001b[33m52\u001b[39m, \u001b[33m53\u001b[39m, \u001b[33m54\u001b[39m, \u001b[33m55\u001b[39m,',
2800-
' \u001b[33m56\u001b[39m, \u001b[33m57\u001b[39m, \u001b[33m58\u001b[39m, \u001b[33m59\u001b[39m',
2801-
']',
2802-
].join('\n');
2792+
const inlineNumbers = Array.from({ length: 60 }, (_, i) => `\u001b[33m${i}\u001b[39m`);
2793+
expected = `[ ${inlineNumbers.join(', ')} ]`;
28032794

28042795
assert.strictEqual(out, expected);
28052796

0 commit comments

Comments
 (0)