From 7750afa29b7e3572820e999d674c8aec4dca095a Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 20 Oct 2025 21:18:47 -0700 Subject: [PATCH] Updates eqlComptime to resolve the rope if needed (#23883) ### What does this PR do? Fixes #23723 ### How did you verify your code works? Test case --- src/ast/E.zig | 29 ++++++++++++++++++++++++----- test/regression/issue/23723.test.js | 4 ++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/regression/issue/23723.test.js diff --git a/src/ast/E.zig b/src/ast/E.zig index 6f70e11813..449fda4c30 100644 --- a/src/ast/E.zig +++ b/src/ast/E.zig @@ -1100,11 +1100,30 @@ pub const String = struct { } pub fn eqlComptime(s: *const String, comptime value: []const u8) bool { - bun.assert(s.next == null); - return if (s.isUTF8()) - strings.eqlComptime(s.data, value) - else - strings.eqlComptimeUTF16(s.slice16(), value); + if (!s.isUTF8()) { + bun.assertf(s.next == null, "transpiler: utf-16 string is a rope", .{}); // utf-16 strings are not ropes + return strings.eqlComptimeUTF16(s.slice16(), value); + } + if (s.next == null) { + // latin-1 or utf-8, non-rope + return strings.eqlComptime(s.data, value); + } + + // latin-1 or utf-8, rope + return eql8Rope(s, value); + } + fn eql8Rope(s: *const String, value: []const u8) bool { + bun.assertf(s.next != null and s.isUTF8(), "transpiler: bad call to eql8Rope", .{}); + if (s.rope_len != value.len) return false; + var i: usize = 0; + var next: ?*const String = s; + while (next) |current| : (next = current.next) { + if (!strings.eqlLong(current.data, value[i..][0..current.data.len], false)) return false; + i += current.data.len; + } + bun.assertf(i == value.len, "transpiler: rope string length mismatch 1", .{}); + bun.assertf(i == s.rope_len, "transpiler: rope string length mismatch 2", .{}); + return true; } pub fn hasPrefixComptime(s: *const String, comptime value: anytype) bool { diff --git a/test/regression/issue/23723.test.js b/test/regression/issue/23723.test.js new file mode 100644 index 0000000000..22432a7310 --- /dev/null +++ b/test/regression/issue/23723.test.js @@ -0,0 +1,4 @@ +test("doesn't crash", () => { + expect(typeof Uint8Array !== undefined + "").toBe(true); + expect(typeof Uint8Array !== "undefine" + "d").toBe(true); +});