mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
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>