Files
bun.sh/test/regression/issue
Claude Bot 0b48c8a6c0 Fix stack overflow with deeply nested if-else chains
Fixes #24548

When processing JavaScript files with deeply nested if-else chains
(2000+ levels), Bun would crash with a stack overflow during AST
traversal. This occurred because the `s_if` visitor in visitStmt.zig
used recursive calls to process else-if chains, creating a call stack
proportional to the nesting depth.

This was particularly problematic for code generated by compilers like
Gleam, which can generate long if-else-if chains for entity resolution
and similar tasks.

The fix converts the else-if chain processing from recursive to
iterative. When the else branch of an if statement is another if
statement (forming an else-if chain), we now process it iteratively
in a loop rather than through recursive calls. This bounds the stack
depth regardless of chain length.

Test plan:
- Added regression test with 2500-level deep if-else chain
- Verified the original reproduction case now works
- Both `bun run` and `bun build` handle deep nesting correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 03:52:03 +00:00
..
2025-08-06 06:44:46 -07:00
2025-01-28 17:23:57 -08:00
2025-06-03 13:23:12 -07:00
2025-06-03 23:41:37 -07:00
2025-01-17 22:08:07 -08:00
2024-06-14 01:50:36 -07:00
2025-03-03 21:38:05 -08:00
2025-05-26 21:18:22 -07:00
2025-07-03 01:06:22 -07:00
2025-07-23 22:31:42 -07:00
2025-10-20 14:07:31 -07:00
2025-11-05 22:04:14 -08:00
2025-11-05 22:04:14 -08:00
2025-07-20 23:02:10 -07:00