diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index 942b7cbd37..92d4f345c9 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/ConsoleObject.zig @@ -359,12 +359,17 @@ const TablePrinter = struct { // find or create the column for the property const column: *Column = brk: { const col_str = String.init(col_key); + for (columns.items[1..]) |*col| { if (col.name.eql(col_str)) { break :brk col; } } + // Need to ref this string because JSPropertyIterator + // uses `toString` instead of `toStringRef` for property names + col_str.ref(); + try columns.append(.{ .name = col_str }); break :brk &columns.items[columns.items.len - 1]; diff --git a/test/js/bun/console/console-table-repeat-50.ts b/test/js/bun/console/console-table-repeat-50.ts new file mode 100644 index 0000000000..13885032c0 --- /dev/null +++ b/test/js/bun/console/console-table-repeat-50.ts @@ -0,0 +1,3 @@ +for (let i = 0; i < 50; i++) { + console.table([{ n: 8 }]); +} diff --git a/test/js/bun/console/console-table.test.ts b/test/js/bun/console/console-table.test.ts index 0841aa9e0d..ca251c0024 100644 --- a/test/js/bun/console/console-table.test.ts +++ b/test/js/bun/console/console-table.test.ts @@ -214,3 +214,21 @@ test.skip("console.table character widths", () => { console.log(actualOutput); }); + +test("console.table repeat 50", () => { + const expected = `┌───┬───┐ +│ │ n │ +├───┼───┤ +│ 0 │ 8 │ +└───┴───┘ +`; + const { stdout, stderr } = spawnSync({ + cmd: [bunExe(), `${import.meta.dir}/console-table-repeat-50.ts`], + stdout: "pipe", + stderr: "pipe", + env: bunEnv, + }); + + expect(stdout.toString()).toBe(expected.repeat(50)); + expect(stderr.toString()).toBe(""); +});