Skip to content

Commit 1ddf199

Browse files
committed
util: use [Array] for deeply nested arrays
Prefer `[Array]` over `[Object]` because the latter is confusing. Ref: #11651 PR-URL: #12046
1 parent ed12ea3 commit 1ddf199

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/util.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ function formatValue(ctx, value, recurseTimes) {
586586
if (recurseTimes < 0) {
587587
if (isRegExp(value)) {
588588
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
589+
} else if (Array.isArray(value)) {
590+
return ctx.stylize('[Array]', 'special');
589591
} else {
590592
return ctx.stylize('[Object]', 'special');
591593
}

test/parallel/test-util-inspect-proxy.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ const expected1 = 'Proxy [ {}, {} ]';
4747
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
4848
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
4949
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
50-
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], {} ],' +
50+
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' +
5151
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' +
52-
', Proxy [ Proxy [Object], {} ] ] ]';
53-
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], Proxy [Object]' +
54-
' ],\n Proxy [ Proxy [Object], Proxy [Object] ] ],\n' +
55-
' Proxy [ Proxy [ Proxy [Object], Proxy [Object] ],\n' +
56-
' Proxy [ Proxy [Object], Proxy [Object] ] ] ]';
52+
', Proxy [ Proxy [Array], {} ] ] ]';
53+
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' +
54+
' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
55+
' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' +
56+
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
5757
assert.strictEqual(util.inspect(proxy1, opts), expected1);
5858
assert.strictEqual(util.inspect(proxy2, opts), expected2);
5959
assert.strictEqual(util.inspect(proxy3, opts), expected3);

test/parallel/test-util-inspect.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ assert.strictEqual(util.inspect({'a': {'b': { 'c': 2}}}, false, 0),
7272
'{ a: [Object] }');
7373
assert.strictEqual(util.inspect({'a': {'b': { 'c': 2}}}, false, 1),
7474
'{ a: { b: [Object] } }');
75+
assert.strictEqual(util.inspect({'a': {'b': ['c']}}, false, 1),
76+
'{ a: { b: [Array] } }');
7577
assert.strictEqual(util.inspect(Object.create({},
7678
{visible: {value: 1, enumerable: true}, hidden: {value: 2}})),
7779
'{ visible: 1 }'

0 commit comments

Comments
 (0)