diff --git a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts index a5bf2798ae..87186fbb2b 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts @@ -82,6 +82,12 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { */ protected fileToClasses = new Map>(); + /** + * Tracks which source files have been analyzed but did not contain any traits. This set allows + * the compiler to skip analyzing these files in an incremental rebuild. + */ + protected filesWithoutTraits = new Set(); + private reexportMap = new Map>(); private handlersByName = @@ -121,12 +127,17 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { const priorWork = this.incrementalBuild.priorAnalysisFor(sf); if (priorWork !== null) { - for (const priorRecord of priorWork) { - this.adopt(priorRecord); - } - this.perf.eventCount(PerfEvent.SourceFileReuseAnalysis); - this.perf.eventCount(PerfEvent.TraitReuseAnalysis, priorWork.length); + + if (priorWork.length > 0) { + for (const priorRecord of priorWork) { + this.adopt(priorRecord); + } + + this.perf.eventCount(PerfEvent.TraitReuseAnalysis, priorWork.length); + } else { + this.filesWithoutTraits.add(sf); + } // Skip the rest of analysis, as this file's prior traits are being reused. return; @@ -176,6 +187,9 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { } result.set(sf, records); } + for (const sf of this.filesWithoutTraits) { + result.set(sf, []); + } return result; }