aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js_printer.zig24
-rw-r--r--test/transpiler/runtime-transpiler.test.ts9
2 files changed, 29 insertions, 4 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig
index 57ef580b6..709672f29 100644
--- a/src/js_printer.zig
+++ b/src/js_printer.zig
@@ -3180,10 +3180,26 @@ fn NewPrinter(
hex_chars[cursor.c & 15],
});
},
- else => {
- p.print("\\u{");
- std.fmt.formatInt(cursor.c, 16, .lower, .{}, p) catch unreachable;
- p.print("}");
+
+ else => |c| {
+ const k = c - 0x10000;
+ const lo = @as(usize, @intCast(first_high_surrogate + ((k >> 10) & 0x3FF)));
+ const hi = @as(usize, @intCast(first_low_surrogate + (k & 0x3FF)));
+
+ p.print(&[_]u8{
+ '\\',
+ 'u',
+ hex_chars[lo >> 12],
+ hex_chars[(lo >> 8) & 15],
+ hex_chars[(lo >> 4) & 15],
+ hex_chars[lo & 15],
+ '\\',
+ 'u',
+ hex_chars[hi >> 12],
+ hex_chars[(hi >> 8) & 15],
+ hex_chars[(hi >> 4) & 15],
+ hex_chars[hi & 15],
+ });
},
}
},
diff --git a/test/transpiler/runtime-transpiler.test.ts b/test/transpiler/runtime-transpiler.test.ts
index 23e972be4..9aaca74fe 100644
--- a/test/transpiler/runtime-transpiler.test.ts
+++ b/test/transpiler/runtime-transpiler.test.ts
@@ -1,6 +1,15 @@
import { beforeEach, describe, expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";
+test("non-ascii regexp literals", () => {
+ var str = "🔴11 54 / 10,000";
+ expect(str.replace(/[🔵🔴,]+/g, "")).toBe("11 54 / 10000");
+});
+
+test("ascii regex with escapes", () => {
+ expect(/^[-#!$@£%^&*()_+|~=`{}\[\]:";'<>?,.\/ ]$/).toBeInstanceOf(RegExp);
+});
+
describe("// @bun", () => {
beforeEach(() => {
delete require.cache[require.resolve("./async-transpiler-entry")];