From 0d7cea69c253d22fc6ee2ccd7c437290fe9e043c Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 15 Feb 2023 01:35:02 -0800 Subject: [PATCH] workaround prisma's usage of `eval("__dirname")` --- src/js_printer.zig | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/js_printer.zig b/src/js_printer.zig index 4aa3b1c7c3..48e4c62600 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -1713,6 +1713,28 @@ pub fn NewPrinter( wrap = true; } + const is_unbound_eval = !e.is_direct_eval and p.isUnboundEvalIdentifier(e.target); + + if (is_unbound_eval) { + if (e.args.len == 1 and e.args.ptr[0].data == .e_string and is_bun_platform) { + // prisma: + // + // eval("__dirname") + // + // We don't have a __dirname variable defined in our ESM <> CJS compat mode + // (Perhaps we should change that for cases like this?) + // + // + if (e.args.ptr[0].data.e_string.eqlComptime("__dirname")) { + p.print("import.meta.dir"); + return; + } else if (e.args.ptr[0].data.e_string.eqlComptime("__filename")) { + p.print("import.meta.file"); + return; + } + } + } + if (wrap) { p.print("("); } @@ -1726,7 +1748,7 @@ pub fn NewPrinter( } // We don't ever want to accidentally generate a direct eval expression here p.call_target = e.target.data; - if (!e.is_direct_eval and p.isUnboundEvalIdentifier(e.target)) { + if (is_unbound_eval) { p.print("(0, "); p.printExpr(e.target, .postfix, ExprFlag.None()); p.print(")");