Files
bun.sh/test/regression
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
..