Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 2, 2025

When the expression parser consumes tokens inside a parenthesized expression, it looks for valid tokens until it hits and invalid one or a closing paren. If it finds an invalid token, it reports an error and tries to recover until it finds a closing paren. The problem is that in such cases, it would produce the ParenthesizedExpression and continue parsing from from the closing paren which would then produce more errors that add noise to the output and result in an incorrect representation of the user's code. E.g. foo((event.target as HTMLElement).value) would be recovered to foo((event.target)).value instead of foo((event.target).value).

These changes resolve the issue by skipping over the closing paren at the recovery point.

Fixes #61792.

When the expression parser consumes tokens inside a parenthesized expression, it looks for valid tokens until it hits and invalid one or a closing paren. If it finds an invalid token, it reports and error and tries to recover until it finds a closing paren. The problem is that in such cases, it would produce the `ParenthesizedExpression` and continue parsing **from** from the closing paren which would then produce more errors that add noise to the output and result in an incorrect representation of the user's code. E.g. `foo((event.target as HTMLElement).value)` would be recovered to `foo((event.target)).value` instead of `foo((event.target).value)`.

These changes resolve the issue by skipping over the closing paren at the recovery point.

Fixes angular#61792.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Jun 2, 2025
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Jun 2, 2025
@ngbot ngbot bot added this to the Backlog milestone Jun 2, 2025
@crisbeto crisbeto requested a review from AndrewKushnir June 2, 2025 08:19
@crisbeto crisbeto marked this pull request as ready for review June 2, 2025 08:19
@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 2, 2025
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jun 2, 2025
@kirjs
Copy link
Contributor

kirjs commented Jun 2, 2025

This PR was merged into the repository by commit fd5a049.

The changes were merged into the following branches: main, 20.0.x

@kirjs kirjs closed this in fd5a049 Jun 2, 2025
kirjs pushed a commit that referenced this pull request Jun 2, 2025
When the expression parser consumes tokens inside a parenthesized expression, it looks for valid tokens until it hits and invalid one or a closing paren. If it finds an invalid token, it reports and error and tries to recover until it finds a closing paren. The problem is that in such cases, it would produce the `ParenthesizedExpression` and continue parsing **from** from the closing paren which would then produce more errors that add noise to the output and result in an incorrect representation of the user's code. E.g. `foo((event.target as HTMLElement).value)` would be recovered to `foo((event.target)).value` instead of `foo((event.target).value)`.

These changes resolve the issue by skipping over the closing paren at the recovery point.

Fixes #61792.

PR Close #61815
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template parser incorrectly recovers from expression errors in some cases

3 participants