Skip to content

Bail ASI loop when inner expr() does not advance the cursor#30

Merged
dy merged 1 commit intody:mainfrom
davejcameron:dc.asi-bail-on-no-progress
May 6, 2026
Merged

Bail ASI loop when inner expr() does not advance the cursor#30
dy merged 1 commit intody:mainfrom
davejcameron:dc.asi-bail-on-no-progress

Conversation

@davejcameron
Copy link
Copy Markdown
Contributor

@davejcameron davejcameron commented May 6, 2026

A switch body with multi-statement case branches throws RangeError: Invalid array length while parsing:

parse(`switch (x) {
  case 1:
    a
    b
  case 2:
    c
}`)

Trace: infinite recursion through asi → expr → asi → expr … until the semicolon-list array overflows. The ASI loop continues whenever the inner expr() returns truthy, but a lookup handler is allowed to return a non-array sentinel to mean "matched but did not consume" — feature/switch.js's reserve('case') does this when case/default appears inside a switch body, so ASI re-enters at the same cursor position.

Bail when the recursive expr() returns truthy without advancing idx. Regression test in test/feature/control.js. Suite stays green (294/294).

@dy dy merged commit f40d235 into dy:main May 6, 2026
1 check passed
@davejcameron davejcameron deleted the dc.asi-bail-on-no-progress branch May 6, 2026 14:58
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