diff options
author | 2023-09-15 06:04:34 -0700 | |
---|---|---|
committer | 2023-09-15 06:04:34 -0700 | |
commit | 6cc5872765e55650bba59cf178dd83e83535dd0b (patch) | |
tree | 2765267144c99b1fcf384fff58daa867752388be | |
parent | 898962770eba7879455bec1462527a1123089929 (diff) | |
download | bun-6cc5872765e55650bba59cf178dd83e83535dd0b.tar.gz bun-6cc5872765e55650bba59cf178dd83e83535dd0b.tar.zst bun-6cc5872765e55650bba59cf178dd83e83535dd0b.zip |
Fixes #5461 (#5467)
* Fixes #5461
* Update runtime-transpiler.test.ts
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
-rw-r--r-- | src/js_printer.zig | 24 | ||||
-rw-r--r-- | test/transpiler/runtime-transpiler.test.ts | 9 |
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")]; |