Skip to content

Commit 965b958

Browse files
committed
fix console: print custom properties on empty arrays
NodeJS prints custom properties on empty arrays. This commit adds the same support to bun. Fixes #22790
1 parent d7eebef commit 965b958

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/bun.js/ConsoleObject.zig

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,10 @@ pub const Formatter = struct {
19191919
if (ctx.i == 0) {
19201920
handleFirstProperty(ctx, globalThis, ctx.parent) catch return;
19211921
} else {
1922-
this.printComma(Writer, writer_, enable_ansi_colors) catch unreachable;
1922+
const len = ctx.parent.getLength(globalThis) catch 0;
1923+
if (len > 0) {
1924+
this.printComma(Writer, writer_, enable_ansi_colors) catch unreachable;
1925+
}
19231926
}
19241927

19251928
defer ctx.i += 1;
@@ -2381,8 +2384,28 @@ pub const Formatter = struct {
23812384
// }
23822385

23832386
if (len == 0) {
2384-
writer.writeAll("[]");
2385-
this.addForNewLine(2);
2387+
writer.writeAll("[");
2388+
this.addForNewLine(1);
2389+
if (!jsType.isArguments()) {
2390+
const Iterator = PropertyIterator(Writer, enable_ansi_colors);
2391+
var iter = Iterator{
2392+
.formatter = this,
2393+
.writer = writer_,
2394+
.always_newline = !this.single_line and (this.always_newline_scope or this.goodTimeForANewLine()),
2395+
.single_line = this.single_line,
2396+
.parent = value,
2397+
.i = 1,
2398+
};
2399+
try value.forEachPropertyNonIndexed(this.globalThis, &iter, Iterator.forEach);
2400+
if (this.failed) return;
2401+
2402+
const keys = try value.keys(this.globalThis);
2403+
const num_keys = try keys.getLength(this.globalThis);
2404+
if (num_keys > 0) {
2405+
writer.writeAll(" ");
2406+
}
2407+
}
2408+
writer.writeAll("]");
23862409
return;
23872410
}
23882411

0 commit comments

Comments
 (0)