Skip to content

Commit 4a5a944

Browse files
addaleaxjasnell
authored andcommitted
util: use [Array] for deeply nested arrays
Prefer `[Array]` over `[Object]` because the latter is confusing. PR-URL: #12046 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent cd4ddfd commit 4a5a944

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/util.js

+2
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ const expected1 = 'Proxy [ {}, {} ]';
4848
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
4949
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
5050
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
51-
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], {} ],' +
51+
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' +
5252
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' +
53-
', Proxy [ Proxy [Object], {} ] ] ]';
54-
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Object], Proxy [Object]' +
55-
' ],\n Proxy [ Proxy [Object], Proxy [Object] ] ],\n' +
56-
' Proxy [ Proxy [ Proxy [Object], Proxy [Object] ],\n' +
57-
' Proxy [ Proxy [Object], Proxy [Object] ] ] ]';
53+
', Proxy [ Proxy [Array], {} ] ] ]';
54+
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' +
55+
' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
56+
' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' +
57+
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
5858
assert.strictEqual(util.inspect(proxy1, opts), expected1);
5959
assert.strictEqual(util.inspect(proxy2, opts), expected2);
6060
assert.strictEqual(util.inspect(proxy3, opts), expected3);

test/parallel/test-util-inspect.js

+2
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)