mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
Fixes #25398 ### What does this PR do? Fixes a bug where object expressions with spread properties and nullish coalescing to empty objects (e.g., `k?.x ?? {}`) would produce invalid JavaScript output like `k?.x ?? ` (missing `{}`). ### Root Cause In `src/ast/SideEffects.zig`, the `simplifyUnusedExpr` function handles unused object expressions with spread properties. When simplifying property values: 1. The code creates a mutable copy `prop` from the original `prop_` 2. When a property value is simplified (e.g., `k?.x ?? {}` → `k?.x`), it updates `prop.value` 3. **Bug:** The code then wrote back `prop_` (the original) instead of `prop` (the modified copy) Because `simplifyUnusedExpr` mutates the AST in place when handling nullish coalescing (setting `bin.right` to empty), the original `prop_` now contained an expression with `bin.right` as an empty/missing expression, resulting in invalid output. ### How did you verify your code works? - Added regression test in `test/regression/issue/25398.test.ts` - Verified the original reproduction case passes - Verified existing CommonJS tests continue to pass - Verified test fails with system bun and passes with the fix
1.9 KiB
1.9 KiB