feat: enable DCE for process.isBun when target is bun

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 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-09-14 17:40:35 +00:00
parent 6bafe2602e
commit f2b344dfd1

View File

@@ -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);