Skip to content

Simplify assignment AST nodes - #61682

Closed
crisbeto wants to merge 3 commits into
angular:mainfrom
crisbeto:binary-assignments
Closed

crisbeto wants to merge 3 commits into
angular:mainfrom
crisbeto:binary-assignments

Conversation

@crisbeto

@crisbeto crisbeto commented May 26, 2025 •

Copy link
Copy Markdown
Member

Includes a few changes aimed at aligning how we represent assignments in our expression and output AST to how TypeScript does it. This both simplifies the code and makes it easier to ship other operators like ??= in the future. Summary:

refactor(compiler): produce binary expressions instead of dedicated write ones

Currently our expression parser produces two different expressions for writes: PropertyWrite (e.g. foo.bar = 123) or KeyedWrite (e.g. foo[0] = 123). This is inconsistent with other ASTs, like TypeScript's, where writes are represented as binary expressions with a = operator and it makes it difficult to implement more write operators like ??=, because we'd essentially have to duplicate them.

These changes switch the expression parser over to produce binary expressions instead.

refactor(compiler): account for new assignment AST

Reworks the places that were depending on PropertyWrite and KeyedWrite to account for the new AST structure.

refactor(compiler): replace output AST write nodes

Similarly to the previous change to the expression AST, these changes replace the WriteVarExpr, WriteKeyExpr and WritePropExpr from the output AST with a binary expression. This is closer aligned to TypeScript and makes it easier to translate code between the two.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label May 26, 2025
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 26, 2025
@ngbot ngbot Bot added this to the Backlog milestone May 26, 2025
@crisbeto
crisbeto force-pushed the binary-assignments branch from 6a0173d to b8b4b4c Compare May 26, 2025 12:23
@crisbeto

Copy link
Copy Markdown
Member Author

Passing TGP

@crisbeto
crisbeto requested a review from devversion May 26, 2025 15:41
@crisbeto crisbeto added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 26, 2025
@crisbeto
crisbeto marked this pull request as ready for review May 26, 2025 15:41
@crisbeto

Copy link
Copy Markdown
Member Author

Caretaker note: cl/763441006 will have to be patched in together with these changes.

@crisbeto crisbeto added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label May 26, 2025

@devversion devversion 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.

Nice cleanup

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: rc This PR is targeted for the next release-candidate target: minor This PR is targeted for the next minor release and removed 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 target: rc This PR is targeted for the next release-candidate labels May 28, 2025
@crisbeto
crisbeto force-pushed the binary-assignments branch 3 times, most recently from 7d5f5ef to 339a682 Compare May 31, 2025 05:13
crisbeto added 3 commits June 2, 2025 15:59
…rite ones

Currently our expression parser produces two different expressions for writes: `PropertyWrite` (e.g. `foo.bar = 123`) or `KeyedWrite` (e.g. `foo[0] = 123`). This is inconsistent with other ASTs, like TypeScript's, where writes are represented as binary expressions with a `=` operator and it makes it difficult to implement more write operators like `??=`, because we'd essentially have to duplicate them.

These changes switch the expression parser over to produce binary expressions instead.
Reworks the places that were depending on `PropertyWrite` and `KeyedWrite` to account for the new AST structure.
Similarly to the previous change to the expression AST, these changes replace the `WriteVarExpr`, `WriteKeyExpr` and `WritePropExpr` from the output AST with a binary expression. This is closer aligned to TypeScript and makes it easier to translate code between the two.
@crisbeto
crisbeto force-pushed the binary-assignments branch from 339a682 to dc23d22 Compare June 2, 2025 13:59
@kirjs

kirjs commented Jun 3, 2025

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit b1f3d2e.

The changes were merged into the following branches: main

@kirjs kirjs closed this in 08ee693 Jun 3, 2025
kirjs pushed a commit that referenced this pull request Jun 3, 2025
Reworks the places that were depending on `PropertyWrite` and `KeyedWrite` to account for the new AST structure.

PR Close #61682
kirjs pushed a commit that referenced this pull request Jun 3, 2025
Similarly to the previous change to the expression AST, these changes replace the `WriteVarExpr`, `WriteKeyExpr` and `WritePropExpr` from the output AST with a binary expression. This is closer aligned to TypeScript and makes it easier to translate code between the two.

PR Close #61682
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 4, 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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants