mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(compiler-cli): bind switch exhaustive check expressions
Ensure switch exhaustive check parameters are visited during template binding so local template symbols are resolved correctly.
This allows:
```html
@let state = this.state();
@switch (state.mode) {
@case ('show') { {{ state.menu }}; }
@case ('hide') {}
@default never(state);
}
```
(cherry picked from commit e8430032e1)
This commit is contained in:
@@ -1487,6 +1487,27 @@ class TestComponent {
|
||||
|
||||
expect(messages).toEqual([]);
|
||||
});
|
||||
|
||||
it('should narrow a let declaration with the same name as a component property', () => {
|
||||
const messages = diagnose(
|
||||
`
|
||||
@let state = this.state();
|
||||
@switch (state.mode) {
|
||||
@case ('show') { {{ state.menu }}; }
|
||||
@case ('hide') {}
|
||||
@default never(state);
|
||||
}
|
||||
`,
|
||||
`
|
||||
import {InputSignal} from '@angular/core';
|
||||
export class TestComponent {
|
||||
state: InputSignal<{ mode: 'hide' } | { mode: 'show'; menu: number }>;
|
||||
}
|
||||
`,
|
||||
);
|
||||
|
||||
expect(messages).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/angular/angular/issues/43970
|
||||
|
||||
@@ -90,6 +90,7 @@ export class CombinedRecursiveAstVisitor extends RecursiveAstVisitor implements
|
||||
visitSwitchBlock(block: t.SwitchBlock): void {
|
||||
this.visit(block.expression);
|
||||
this.visitAllTemplateNodes(block.groups);
|
||||
block.exhaustiveCheck?.visit(this);
|
||||
}
|
||||
|
||||
visitSwitchBlockCase(block: t.SwitchBlockCase): void {
|
||||
|
||||
Reference in New Issue
Block a user