Skip to content

Commit 29bc735

Browse files
TrottMylesBorins
authored andcommitted
console: fix console.table() display edge case
If the properties are not specified in `console.table()`, then we should make a best effort to determine them rather than put all values into a "Values" column. PR-URL: #20323 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent be34388 commit 29bc735

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

lib/console.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,7 @@ Console.prototype.table = function(tabularData, properties) {
363363
tabularData = previewSetIterator(tabularData);
364364

365365
const setlike = setIter || isSet(tabularData);
366-
if (setlike ||
367-
(properties === undefined &&
368-
(isArray(tabularData) || isTypedArray(tabularData)))) {
366+
if (setlike) {
369367
const values = [];
370368
let length = 0;
371369
for (const v of tabularData) {

test/parallel/test-console-table.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ test([1, 2, 3], `
4141
`);
4242

4343
test([Symbol(), 5, [10]], `
44-
┌─────────┬──────────┐
45-
│ (index) │ Values │
46-
├─────────┼──────────┤
47-
│ 0 │ Symbol() │
48-
│ 1 │ 5 │
49-
│ 2 │ [ 10 ]
50-
└─────────┴──────────┘
44+
┌─────────┬────┬──────────┐
45+
│ (index) │ 0 │ Values │
46+
├─────────┼────┼──────────┤
47+
│ 0 │ Symbol() │
48+
│ 1 │ 5 │
49+
│ 2 │ 10 │
50+
└─────────┴────┴──────────┘
5151
`);
5252

5353
test([undefined, 5], `
@@ -182,10 +182,10 @@ test({ a: undefined }, ['x'], `
182182
`);
183183

184184
test([], `
185-
┌─────────┬────────
186-
│ (index) │ Values │
187-
├─────────┼────────
188-
└─────────┴────────
185+
┌─────────┐
186+
│ (index) │
187+
├─────────┤
188+
└─────────┘
189189
`);
190190

191191
test(new Map(), `
@@ -194,3 +194,12 @@ test(new Map(), `
194194
├───────────────────┼─────┼────────┤
195195
└───────────────────┴─────┴────────┘
196196
`);
197+
198+
test([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], `
199+
┌─────────┬─────┬─────┐
200+
│ (index) │ a │ b │
201+
├─────────┼─────┼─────┤
202+
│ 0 │ 1 │ 'Y' │
203+
│ 1 │ 'Z' │ 2 │
204+
└─────────┴─────┴─────┘
205+
`);

0 commit comments

Comments
 (0)