diff --git a/src/jsc/ConsoleObject.rs b/src/jsc/ConsoleObject.rs index bcdbb3b13db4..eb073a77489e 100644 --- a/src/jsc/ConsoleObject.rs +++ b/src/jsc/ConsoleObject.rs @@ -2089,6 +2089,7 @@ pub mod formatter { | Tag::Error | Tag::Class | Tag::Event + | Tag::JSX ) } } diff --git a/src/runtime/test_runner/pretty_format.rs b/src/runtime/test_runner/pretty_format.rs index bbe480d4fe0f..21d4f9630a74 100644 --- a/src/runtime/test_runner/pretty_format.rs +++ b/src/runtime/test_runner/pretty_format.rs @@ -514,7 +514,7 @@ impl Tag { #[inline] pub const fn can_have_circular_references(self) -> bool { - matches!(self, Tag::Array | Tag::Object | Tag::Map | Tag::Set) + matches!(self, Tag::Array | Tag::Object | Tag::Map | Tag::Set | Tag::JSX) } } diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 32a70af30183..ce1e6249bfed 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "bun:test"; -import { normalizeBunSnapshot, tmpdirSync } from "harness"; +import { bunEnv, bunExe, normalizeBunSnapshot, tmpdirSync } from "harness"; import { join } from "path"; import util from "util"; it("prototype", () => { @@ -316,6 +316,34 @@ it("jsx with fragment", () => { expect(input).toBe(output); }); +it("jsx with circular references does not stack overflow", async () => { + await using proc = Bun.spawn({ + cmd: [ + bunExe(), + "-e", + ` + const sym = Symbol.for("react.element"); + const a = { $$typeof: sym, type: "div", key: null, props: {} }; + a.key = a; + console.log(Bun.inspect(a)); + const b = { $$typeof: sym, type: "div", key: null, props: {} }; + b.props.children = b; + console.log(Bun.inspect(b)); + const c = { $$typeof: sym, type: "div", key: null, props: {} }; + c.props.foo = c; + console.log(Bun.inspect(c)); + `, + ], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stderr).toBe(""); + expect(stdout).toBe("
\n" + "
\n [Circular]\n
\n" + "
\n"); + expect(exitCode).toBe(0); +}); + it("inspect", () => { expect(Bun.inspect(new TypeError("what")).includes("TypeError: what")).toBe(true); expect(Bun.inspect("hi")).toBe('"hi"');