From f611faadfedd8dc2c3291da98e2c2c60fe3984bd Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 17 Sep 2024 09:46:35 +0200 Subject: [PATCH] fix(compiler-cli): extended diagnostics not validating ICUs (#57845) The visitor that all extended diagnostics are based on hadn't implemented the `visitIcu` method which meant that it wasn't detecting any code inside of them. Fixes #57838. PR Close #57845 --- .../compiler-cli/src/ngtsc/typecheck/extended/api/api.ts | 5 ++++- .../unused_let_declaration_spec.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts index 31149c33846ed..3c27bb3adcb45 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts @@ -228,7 +228,10 @@ class TemplateVisitor visitBoundText(text: TmplAstBoundText): void { this.visitAst(text.value); } - visitIcu(icu: TmplAstIcu): void {} + visitIcu(icu: TmplAstIcu): void { + Object.keys(icu.vars).forEach((key) => this.visit(icu.vars[key])); + Object.keys(icu.placeholders).forEach((key) => this.visit(icu.placeholders[key])); + } visitDeferredBlock(deferred: TmplAstDeferredBlock): void { deferred.visitAll(this); diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/test/checks/unused_let_declaration/unused_let_declaration_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/extended/test/checks/unused_let_declaration/unused_let_declaration_spec.ts index 3afced6bf38a9..209945e915ddc 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/extended/test/checks/unused_let_declaration/unused_let_declaration_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/test/checks/unused_let_declaration/unused_let_declaration_spec.ts @@ -108,5 +108,14 @@ runInEachFileSystem(() => { expect(diags.length).toBe(0); }); + + it('should not report a @let declaration that is only used in an ICU', () => { + const diags = diagnose(` + @let value = 1; +

{value, select, 1 {one} 2 {two} other {other}}

+ `); + + expect(diags.length).toBe(0); + }); }); });