Skip to content

Commit

Permalink
fix formatting of Set in Bun.inspect() (#16013)
Browse files Browse the repository at this point in the history
  • Loading branch information
laesse authored Dec 30, 2024
1 parent 76bfcea commit e96dded
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/bun.js/ConsoleObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2728,10 +2728,6 @@ pub const Formatter = struct {
this.quote_strings = true;
defer this.quote_strings = prev_quote_strings;

if (!this.single_line) {
this.writeIndent(Writer, writer_) catch {};
}

const set_name = if (value.jsType() == .WeakSet) "WeakSet" else "Set";

if (length == 0) {
Expand Down Expand Up @@ -2762,7 +2758,7 @@ pub const Formatter = struct {
},
}
}
if (this.single_line) {
if (!this.single_line) {
this.writeIndent(Writer, writer_) catch {};
}
writer.writeAll("}");
Expand Down
12 changes: 12 additions & 0 deletions test/regression/issue/16007.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { it, expect } from "bun:test";

it("Set is propperly formatted in Bun.inspect()", () => {
const set = new Set(["foo", "bar"]);
const formatted = Bun.inspect({ set });
expect(formatted).toBe(`{
set: Set(2) {
"foo",
"bar",
},
}`);
});

0 comments on commit e96dded

Please sign in to comment.