Skip to content

compiler: fix endless loop on syntax errors in template placeholders - #498

Merged
jow- merged 1 commit into
masterfrom
fix/unterminated-placeholder
Oct 17, 2026
Merged

jow- merged 1 commit into
masterfrom
fix/unterminated-placeholder

Conversation

@jow-

@jow- jow- commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

When the expression within a template literal placeholder is cut short by a syntax error, e.g. ${ 1 2 }, or by the end of the source, the statement end marker of the placeholder expression has already advanced the source position beyond the last token of the expression when the instruction storing the result is emitted for that token.

Since source positions are encoded as unsigned deltas, the position going backwards turned into an enormous offset which uc_chunk_add() spent nearly forever and a lot of memory on, as the assertion guarding the invariant is compiled out in release builds.

Tolerate positions in front of the current one once a syntax error has occurred, the generated code is discarded anyway.

When the expression within a template literal placeholder is cut short
by a syntax error, e.g. `${ 1 2 }`, or by the end of the source, the
statement end marker of the placeholder expression has already advanced
the source position beyond the last token of the expression when the
instruction storing the result is emitted for that token.

Since source positions are encoded as unsigned deltas, the position
going backwards turned into an enormous offset which uc_chunk_add()
spent nearly forever and a lot of memory on, as the assertion guarding
the invariant is compiled out in release builds.

Tolerate positions in front of the current one once a syntax error has
occurred, the generated code is discarded anyway.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
@jow-
jow- merged commit cc32334 into master Oct 17, 2026
3 checks passed
@jow-
jow- deleted the fix/unterminated-placeholder branch October 17, 2026 10:08
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.

1 participant