Skip to content

Commit b9f7c1f

Browse files
authored
perf(compiler-cli): optimize missing directive extended checks
Extended diagnostics for `missingStructuralDirective` and `missingControlFlowDirective` previously queried `getSymbolOfNode()` to determine whether any directives matched a template node. This caused the template type checker to lazily generate and traverse the full Type Check Block (TCB) AST and symbol graph for every template node checked, introducing noticeable build time overhead in large applications with many components and structural directives.
1 parent 32a7603 commit b9f7c1f

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

  • packages/compiler-cli/src/ngtsc/typecheck/extended/checks

‎packages/compiler-cli/src/ngtsc/typecheck/extended/checks/missing_control_flow_directive/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class MissingControlFlowDirectiveCheck extends TemplateCheckWithVisitor<ErrorCod
7272
);
7373
if (!controlFlowAttr) return [];
7474

75-
const symbol = ctx.templateTypeChecker.getSymbolOfNode(node, component);
76-
if (symbol === null || symbol.directives.length > 0) {
75+
const directives = ctx.templateTypeChecker.getDirectivesOfNode(component, node);
76+
if (directives?.length) {
7777
return [];
7878
}
7979

‎packages/compiler-cli/src/ngtsc/typecheck/extended/checks/missing_structural_directive/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class MissingStructuralDirectiveCheck extends TemplateCheckWithVisitor<ErrorCode
7171
);
7272
if (!customStructuralDirective) return [];
7373

74-
const symbol = ctx.templateTypeChecker.getSymbolOfNode(node, component);
74+
const directives = ctx.templateTypeChecker.getDirectivesOfNode(component, node);
7575
// Check if there's a directive that matches the structural directive we're checking.
7676
// The structural directive *foo desugars to [foo], so we need to check if any
7777
// directive's selector would match the attribute [foo].
78-
const hasStructuralDirective = symbol?.directives.some((dir) =>
78+
const hasStructuralDirective = directives?.some((dir) =>
7979
dir.selector?.includes(`[${customStructuralDirective.name}]`),
8080
);
8181
if (hasStructuralDirective) return [];

0 commit comments

Comments
 (0)