-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): give precedence to local let declarations over parent …
…ones (#56752) Currently the logic that maps a name to a variable looks at the variables in their definition order. This means that `@let` declarations from parent views will always come before local ones, because the local ones are declared inline whereas the parent ones are hoisted to the top of the function. These changes resolve the issue by giving precedence to the local variables. Fixes #56737. PR Close #56752
- Loading branch information
1 parent
4d18c5b
commit 2a1291e
Showing
9 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
14 changes: 14 additions & 0 deletions
14
packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_let/shadowed_let.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
template: ` | ||
@let value = 'parent'; | ||
@if (true) { | ||
@let value = 'local'; | ||
The value comes from {{value}} | ||
} | ||
`, | ||
standalone: true, | ||
}) | ||
export class MyApp {} |
31 changes: 31 additions & 0 deletions
31
...ges/compiler-cli/test/compliance/test_cases/r3_view_compiler_let/shadowed_let_template.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function MyApp_Conditional_1_Template(rf, ctx) { | ||
if (rf & 1) { | ||
$r3$.ɵɵdeclareLet(0); | ||
$r3$.ɵɵtext(1); | ||
} | ||
if (rf & 2) { | ||
const $value_r1$ = "local"; | ||
$r3$.ɵɵadvance(); | ||
$r3$.ɵɵtextInterpolate1(" The value comes from ", $value_r1$, " "); | ||
} | ||
} | ||
|
||
… | ||
|
||
$r3$.ɵɵdefineComponent({ | ||
… | ||
decls: 2, | ||
vars: 1, | ||
template: function MyApp_Template(rf, ctx) { | ||
if (rf & 1) { | ||
$r3$.ɵɵdeclareLet(0); | ||
$r3$.ɵɵtemplate(1, MyApp_Conditional_1_Template, 2, 1); | ||
} | ||
if (rf & 2) { | ||
"parent"; | ||
$r3$.ɵɵadvance(); | ||
$r3$.ɵɵconditional(true ? 1 : -1); | ||
} | ||
}, | ||
… | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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