Skip to content

Commit 6cc5872

Browse files
Fixes #5461 (#5467)
* Fixes #5461 * Update runtime-transpiler.test.ts --------- Co-authored-by: Jarred Sumner <[email protected]>
1 parent 8989627 commit 6cc5872

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/js_printer.zig

+20-4
Original file line numberDiff line numberDiff line change
@@ -3180,10 +3180,26 @@ fn NewPrinter(
31803180
hex_chars[cursor.c & 15],
31813181
});
31823182
},
3183-
else => {
3184-
p.print("\\u{");
3185-
std.fmt.formatInt(cursor.c, 16, .lower, .{}, p) catch unreachable;
3186-
p.print("}");
3183+
3184+
else => |c| {
3185+
const k = c - 0x10000;
3186+
const lo = @as(usize, @intCast(first_high_surrogate + ((k >> 10) & 0x3FF)));
3187+
const hi = @as(usize, @intCast(first_low_surrogate + (k & 0x3FF)));
3188+
3189+
p.print(&[_]u8{
3190+
'\\',
3191+
'u',
3192+
hex_chars[lo >> 12],
3193+
hex_chars[(lo >> 8) & 15],
3194+
hex_chars[(lo >> 4) & 15],
3195+
hex_chars[lo & 15],
3196+
'\\',
3197+
'u',
3198+
hex_chars[hi >> 12],
3199+
hex_chars[(hi >> 8) & 15],
3200+
hex_chars[(hi >> 4) & 15],
3201+
hex_chars[hi & 15],
3202+
});
31873203
},
31883204
}
31893205
},

test/transpiler/runtime-transpiler.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { beforeEach, describe, expect, test } from "bun:test";
22
import { bunEnv, bunExe } from "harness";
33

4+
test("non-ascii regexp literals", () => {
5+
var str = "🔴11 54 / 10,000";
6+
expect(str.replace(/[🔵🔴,]+/g, "")).toBe("11 54 / 10000");
7+
});
8+
9+
test("ascii regex with escapes", () => {
10+
expect(/^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/).toBeInstanceOf(RegExp);
11+
});
12+
413
describe("// @bun", () => {
514
beforeEach(() => {
615
delete require.cache[require.resolve("./async-transpiler-entry")];

0 commit comments

Comments
 (0)