diff options
author | 2023-02-15 01:35:02 -0800 | |
---|---|---|
committer | 2023-02-15 01:35:02 -0800 | |
commit | 0d7cea69c253d22fc6ee2ccd7c437290fe9e043c (patch) | |
tree | c9842eeac8f1a914ab4d395bc503130780d3088e /src | |
parent | c83eaf09b9fa27c961c845c5eddc075384b244fc (diff) | |
download | bun-0d7cea69c253d22fc6ee2ccd7c437290fe9e043c.tar.gz bun-0d7cea69c253d22fc6ee2ccd7c437290fe9e043c.tar.zst bun-0d7cea69c253d22fc6ee2ccd7c437290fe9e043c.zip |
workaround prisma's usage of `eval("__dirname")`
Diffstat (limited to 'src')
-rw-r--r-- | src/js_printer.zig | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig index 4aa3b1c7c..48e4c6260 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(")"); |