fix(compiler): narrow the type of the aliased if block expression#51952
Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
Closed
fix(compiler): narrow the type of the aliased if block expression#51952crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto wants to merge 1 commit intoangular:mainfrom
Conversation
Contributor
Member
Author
Contributor
|
My question was more for the TCB? It looks like the TCB will always create the alias and use that one inside if. @if (expr; as alias) {
{{expr}}
{{alias}}
}would it generate this one? var _t1 = ((this).expr);
if (_t1) {
"" + ((this).expr); // this.expr will be catched ?
"" + _t1;
}IMO, the correct one would be sth like: var _t1 = ((this).expr);
if (_t1 && ((this).expr)) {
"" + ((this).expr);
"" + _t1;
} |
Member
Author
|
Yes it would, but it's not worth the additional effort to deduplicate it since this is only used during type checking so we don't care about the size of the code. |
dylhunn
approved these changes
Oct 3, 2023
Contributor
dylhunn
left a comment
There was a problem hiding this comment.
Looks straightforward. Thanks for fixing this!
Currently the TCB for aliased `if` blocks looks something like this:
```
// Markup: `@if (expr; as alias) { {{alias}} }
if (block.condition) {
var alias = block.condition;
"" + alias;
}
```
The problem with this approach is that the type of `alias` won't be narrowed. This is something that `NgIf` currently supports.
These changes resolve the issue by emitting the variable outside the `if` block and using the variable reference instead:
```
// Markup: `@if (expr; as alias) { {{alias}} }
var alias = block.condition;
if (alias) {
"" + alias;
}
```
33c36cc to
69ae684
Compare
Member
|
This PR was merged into the repository by commit 02edb43. |
|
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. |
ChellappanRajan
pushed a commit
to ChellappanRajan/angular
that referenced
this pull request
Jan 23, 2024
…gular#51952) Currently the TCB for aliased `if` blocks looks something like this: ``` // Markup: `@if (expr; as alias) { {{alias}} } if (block.condition) { var alias = block.condition; "" + alias; } ``` The problem with this approach is that the type of `alias` won't be narrowed. This is something that `NgIf` currently supports. These changes resolve the issue by emitting the variable outside the `if` block and using the variable reference instead: ``` // Markup: `@if (expr; as alias) { {{alias}} } var alias = block.condition; if (alias) { "" + alias; } ``` PR Close angular#51952
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.





Currently the TCB for aliased
ifblocks looks something like this:The problem with this approach is that the type of
aliaswon't be narrowed. This is something thatNgIfcurrently supports.These changes resolve the issue by emitting the variable outside the
ifblock and using the variable reference instead: