fix formatting of Set in Bun.inspect() (#16013)

This commit is contained in:
Lars Volkheimer
2024-12-30 22:44:40 +01:00
committed by GitHub
parent 76bfceae81
commit e96dded366
2 changed files with 13 additions and 5 deletions

View File

@@ -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) {
@@ -2762,7 +2758,7 @@ pub const Formatter = struct {
},
}
}
if (this.single_line) {
if (!this.single_line) {
this.writeIndent(Writer, writer_) catch {};
}
writer.writeAll("}");

View File

@@ -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",
},
}`);
});