From 1bf292639ad5c9b9564f1819488c58b28560d13e Mon Sep 17 00:00:00 2001 From: laesse Date: Fri, 27 Dec 2024 10:44:17 +0100 Subject: [PATCH 1/2] fix formatting of Set in Bun.inspect() --- src/bun.js/ConsoleObject.zig | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/bun.js/ConsoleObject.zig b/src/bun.js/ConsoleObject.zig index b6f05770b60443..dc66a94ee4fcb5 100644 --- a/src/bun.js/ConsoleObject.zig +++ b/src/bun.js/ConsoleObject.zig @@ -2742,10 +2742,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) { @@ -2776,7 +2772,7 @@ pub const Formatter = struct { }, } } - if (this.single_line) { + if (!this.single_line) { this.writeIndent(Writer, writer_) catch {}; } writer.writeAll("}"); From 0fb0f39d760e8ff214febe99b687d86d77e82ab9 Mon Sep 17 00:00:00 2001 From: laesse Date: Fri, 27 Dec 2024 11:00:17 +0100 Subject: [PATCH 2/2] add test --- test/regression/issue/16007.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/regression/issue/16007.test.ts diff --git a/test/regression/issue/16007.test.ts b/test/regression/issue/16007.test.ts new file mode 100644 index 00000000000000..fa09d4fedc047a --- /dev/null +++ b/test/regression/issue/16007.test.ts @@ -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", + }, +}`); +});