Skip to content

fix: scan consecutive test comments without recursion - #24

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
everton-dgn:fix/scan-consecutive-test-comments-iteratively
Nov 7, 2026
Merged

webpro merged 1 commit into
webpro-nl:mainfrom
everton-dgn:fix/scan-consecutive-test-comments-iteratively

Conversation

@everton-dgn

Copy link
Copy Markdown
Contributor

A long sequence of comment lines inside [[ ... ]] could exhaust the call stack before reaching the expression. Scan those comments in a loop while keeping ordinary newline tokens, token offsets and pending heredocs intact.

Add a 20,000-comment regression and preservation cases for CRLF, lexer windows, embedded hashes and heredocs. All 2,064 tests pass across the test files, along with build, typecheck, lint and formatting. The five focused tests also pass as compiled JavaScript on Node 20; the source tests ran on Node 24. Bash accepts and executes the same large input.

A long sequence of comment lines inside [[ ... ]] could exhaust the call stack before reaching the expression. Scan those comments in a loop while keeping ordinary newline tokens, token offsets and pending heredocs intact.

Add a 20,000-comment regression and preservation cases for CRLF, lexer windows, embedded hashes and heredocs. All 2,064 tests pass across the test files, along with build, typecheck, lint and formatting. The five focused tests also pass as compiled JavaScript on Node 20; the source tests ran on Node 24. Bash accepts and executes the same large input.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Éverton! This is a legitimate robustness fix. Inside [[ ]] the lexer skips newlines in readNext, so every comment line added a frame, and main throws RangeError: Maximum call stack size exceeded from parse() somewhere between four and eight thousand consecutive comment lines inside one test command, while the same run of comments in normal mode parses fine. Bash accepts comments there, and the README promises a partial AST rather than an exception for excessive input, so this needs fixing even though no real script looks like that.

The loop is equivalent to the recursion where it matters: comments still stop at the newline, so normal mode keeps emitting the newline token and consuming pending heredocs there, test mode keeps skipping newlines, and EOF and CRLF behave as before; your tests cover each of those. Since readNext is the hottest function in the lexer, I benchmarked the branch against main on the README fixtures in isolated runs: throughput is unchanged within run-to-run spread. It merges cleanly with main and the full suite passes on the merged tree.

@webpro
webpro merged commit 4e2d58e into webpro-nl:main Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants