fix(compiler-cli): check event side of two-way bindings#59002
Closed
crisbeto wants to merge 3 commits intoangular:mainfrom
Closed
fix(compiler-cli): check event side of two-way bindings#59002crisbeto wants to merge 3 commits intoangular:mainfrom
crisbeto wants to merge 3 commits intoangular:mainfrom
Conversation
ea73ddb to
713a598
Compare
The `isSplitTwoWayBinding` function was a bit misleading, because it has side effects. Renames the function make it a bit more explicit.
In the past two-way bindings used to be interpreted as `foo = $event` at the parser level. In angular#54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something like `someOutput.subscribe($event => expr);` which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side. These changes re-add type checking for the output side by generating the following TCB instead: ``` someOutput.subscribe($event => { var _t1 = unwrapSignalValue(this.someField); _t1 = $event; }); ```
Moves the fix for type checking the event side of two-way bindings behind a compiler flag so that we can roll it out in v20.
713a598 to
ba9fbe0
Compare
crisbeto
commented
Dec 5, 2024
| const strictTemplates = !!this.options.strictTemplates; | ||
|
|
||
| const useInlineTypeConstructors = this.programDriver.supportsInlineOperations; | ||
| const checkTwoWayBoundEvents = this.options['_checkTwoWayBoundEvents'] ?? false; |
Member
Author
There was a problem hiding this comment.
Note that this is off by default so we can land it in g3. I'll flip it to true internally once I fix all the breakages and in v20 externally.
alxhub
approved these changes
Dec 5, 2024
Member
|
This PR was merged into the repository by commit 6fd8a20. The changes were merged into the following branches: main |
alxhub
pushed a commit
that referenced
this pull request
Dec 6, 2024
In the past two-way bindings used to be interpreted as `foo = $event` at the parser level. In #54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something like `someOutput.subscribe($event => expr);` which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side. These changes re-add type checking for the output side by generating the following TCB instead: ``` someOutput.subscribe($event => { var _t1 = unwrapSignalValue(this.someField); _t1 = $event; }); ``` PR Close #59002
alxhub
pushed a commit
that referenced
this pull request
Dec 6, 2024
Moves the fix for type checking the event side of two-way bindings behind a compiler flag so that we can roll it out in v20. PR Close #59002
crisbeto
added a commit
to crisbeto/angular
that referenced
this pull request
Dec 6, 2024
…way bindings Follow-up to angular#59002. If a two-way binding is non-null asserted, only the property side was getting the assertion since the `$event` is synthetic. In practice this means that there's no way to non-null assert a two-way binding. These changes fix the issue by checking if the handler is asserted and applying it to the `$event` assignment.
crisbeto
added a commit
to crisbeto/angular
that referenced
this pull request
Dec 10, 2024
…s when narrowed After angular#59002, we started producing code like the following for the event side of two-way bindings: ``` someOutput.subscribe($event => { var _t1 = unwrapSignalValue(this.someField); _t1 = $event; }); ``` The problem with this approach is that if `someField` is narrowed, the type of `_t1` will be narrowed as well which will make `$event` unassignable. This came up when trying to roll out the changes from the previous PR internally. These changes rework the approach by generating a function call instead. Now the TCB looks as follows: ``` someOutput.subscribe($event => { assignTwoWayBinding(this.someField, $event); }); ```
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
The `isSplitTwoWayBinding` function was a bit misleading, because it has side effects. Renames the function make it a bit more explicit. PR Close angular#59002
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
In the past two-way bindings used to be interpreted as `foo = $event` at the parser level. In angular#54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something like `someOutput.subscribe($event => expr);` which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side. These changes re-add type checking for the output side by generating the following TCB instead: ``` someOutput.subscribe($event => { var _t1 = unwrapSignalValue(this.someField); _t1 = $event; }); ``` PR Close angular#59002
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
…#59002) Moves the fix for type checking the event side of two-way bindings behind a compiler flag so that we can roll it out in v20. PR Close angular#59002
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the past two-way bindings used to be interpreted as
foo = $eventat the parser level. In #54065 it was changed to preserve the actual expression, because it was problematic for supporting two-way binding to signals. This unintentionally ended up causing the TCB to two-way bindings to look something likesomeOutput.subscribe($event => expr);which does nothing. It largely hasn't been a problem, because the input side of two-way bindings was still being checked, except for the case where the input side of the two-way binding has a wider type than the output side.These changes re-add type checking for the output side by generating the following TCB instead: