diff options
-rw-r--r-- | src/import_record.zig | 2 | ||||
-rw-r--r-- | src/js_printer.zig | 33 |
2 files changed, 28 insertions, 7 deletions
diff --git a/src/import_record.zig b/src/import_record.zig index 3ec2f82eb..9894048d7 100644 --- a/src/import_record.zig +++ b/src/import_record.zig @@ -149,6 +149,8 @@ pub const ImportRecord = struct { react_refresh, jsx_import, jsx_classic, + bun, + bun_test, }; pub const PrintMode = enum { diff --git a/src/js_printer.zig b/src/js_printer.zig index e4a641389..89bb82a1e 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -637,17 +637,25 @@ pub fn NewPrinter( } fn printBunJestImportStatement(p: *Printer, import: S.Import) void { - p.print("const "); + printInternalBunImport(p, import, "globalThis.Bun.jest(import.meta.path)"); + } + + fn printGlobalBunImportStatement(p: *Printer, import: S.Import) void { + printInternalBunImport(p, import, "globalThis.Bun"); + } + + fn printInternalBunImport(p: *Printer, import: S.Import, comptime statement: anytype) void { + p.print("var "); if (import.star_name_loc != null) { p.printSymbol(import.namespace_ref); p.printSpace(); p.print("="); p.printSpaceBeforeIdentifier(); - p.print("Bun.jest(import.meta.path)"); + p.print(statement); p.printSemicolonAfterStatement(); p.printIndent(); - p.print("const "); + p.print("var "); } if (import.items.len > 0) { @@ -687,7 +695,7 @@ pub fn NewPrinter( } if (import.star_name_loc == null) { - p.print("} = Bun.jest(import.meta.path)"); + p.print("} = " ++ statement); } else { p.print("} ="); p.printSpaceBeforeIdentifier(); @@ -3578,9 +3586,20 @@ pub fn NewPrinter( p.printIndent(); p.printSpaceBeforeIdentifier(); - if (record.path.isBun() and strings.eqlComptime(record.path.text, "test")) { - p.printBunJestImportStatement(s.*); - return; + if (comptime is_bun_platform) { + if (record.tag != .none) { + switch (record.tag) { + .bun_test => { + p.printBunJestImportStatement(s.*); + return; + }, + .bun => { + p.printGlobalBunImportStatement(s.*); + return; + }, + else => {}, + } + } } if (is_inside_bundle) { |