Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(compiler): recover invalid parenthesized expressions #61815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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