From f2b344dfd143e2f062249bab232bc1b989499ad8 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Sun, 14 Sep 2025 17:40:35 +0000 Subject: [PATCH] feat: enable DCE for process.isBun when target is bun MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When bundling with --target=bun, process.isBun is now replaced with the literal value `true`, enabling dead code elimination for conditional code paths. This provides an easy way to write Bun-specific code that gets optimized away during bundling. Example: ```js if (process.isBun) { // This code is kept when --target=bun bunSpecificLogic(); } else { // This code is eliminated when --target=bun nodeSpecificLogic(); } ``` 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/options.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/options.zig b/src/options.zig index fff5c21501..91dd09cb53 100644 --- a/src/options.zig +++ b/src/options.zig @@ -1510,6 +1510,15 @@ pub fn definesFromTransformOptions( .value = .{ .e_undefined = .{} }, })); } + + // Set process.isBun to true for DCE when target is bun + if (!user_defines.contains("process.isBun")) { + _ = try environment_defines.getOrPutValue("process.isBun", .init(.{ + .valueless = false, + .original_name = "process.isBun", + .value = .{ .e_boolean = .{ .value = true } }, + })); + } } const resolved_defines = try defines.DefineData.fromInput(user_defines, drop, log, allocator);