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:
cexbrayat
2026-06-02 12:11:49 +02:00
committed by Andrew Scott
parent a56f1cdf8f
commit 3d9ca2f173
2 changed files with 22 additions and 0 deletions
@@ -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 {