aboutsummaryrefslogtreecommitdiff
path: root/src/js_printer.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_printer.zig')
-rw-r--r--src/js_printer.zig50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig
index 343911baf..08064c6e3 100644
--- a/src/js_printer.zig
+++ b/src/js_printer.zig
@@ -2085,17 +2085,7 @@ pub fn NewPrinter(
p.print("`");
},
.e_reg_exp => |e| {
- const n = p.writer.written;
-
- // Avoid forming a single-line comment
- if (n > 0 and p.writer.prevChar() == '/') {
- p.print(" ");
- }
-
- p.print(e.value);
-
- // Need a space before the next identifier to avoid it turning into flags
- p.prev_reg_exp_end = p.writer.written;
+ p.printRegExpLiteral(e);
},
.e_big_int => |e| {
p.printSpaceBeforeIdentifier();
@@ -2492,6 +2482,44 @@ pub fn NewPrinter(
}
}
+ pub fn printRegExpLiteral(p: *Printer, e: *const E.RegExp) void {
+ const n = p.writer.written;
+
+ // Avoid forming a single-line comment
+ if (n > 0 and p.writer.prevChar() == '/') {
+ p.print(" ");
+ }
+
+ if (comptime is_bun_platform) {
+ if (e.value.len > 2 and e.usesLookBehindAssertion()) {
+ p.print("(new globalThis.Bun.OnigurumaRegExp(");
+ const pattern = e.pattern();
+ const flags = e.flags();
+ std.debug.assert(pattern.len > 0);
+ var buf = bun.default_allocator.alloc(u16, strings.elementLengthUTF8IntoUTF16([]const u8, pattern)) catch unreachable;
+ defer bun.default_allocator.free(buf);
+ const buf_len = std.unicode.utf8ToUtf16Le(buf, pattern) catch unreachable;
+ std.debug.assert(buf_len == buf.len);
+ const q = p.bestQuoteCharForString(buf, true);
+ p.print(q);
+ p.printQuotedUTF16(buf, q);
+ p.print(q);
+ if (flags.len > 0) {
+ p.print(", ");
+ p.printQuotedUTF8(flags, true);
+ }
+ p.print("))");
+ } else {
+ p.print(e.value);
+ }
+ } else {
+ p.print(e.value);
+ }
+
+ // Need a space before the next identifier to avoid it turning into flags
+ p.prev_reg_exp_end = p.writer.written;
+ }
+
pub fn printProperty(p: *Printer, item: G.Property) void {
if (comptime !is_json) {
if (item.kind == .spread) {