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 <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent be34388 commit 29bc735

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

β€Žlib/console.js

+1-3
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

+20-11
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)