Skip to content

Commit 1071802

Browse files
atscottthePunderWoman
authored andcommitted
fix(compiler-cli): Always retain prior results for all files (#61487)
This change ensures that prior results for all files are retained even when a request is made such that we only need a shim for a single file. Prior to this change, any prior results that were not part of the request were discarded. PR Close #61487
1 parent 9ce79be commit 1071802

File tree

1 file changed

+31
-20
lines changed
  • packages/compiler-cli/src/ngtsc/typecheck/src

1 file changed

+31
-20
lines changed

packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
130130
private elementTagCache = new Map<ts.ClassDeclaration, Map<string, PotentialDirective | null>>();
131131

132132
private isComplete = false;
133+
private priorResultsAdopted = false;
133134

134135
constructor(
135136
private originalProgram: ts.Program,
@@ -497,30 +498,43 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
497498
return engine;
498499
}
499500

500-
private maybeAdoptPriorResultsForFile(sf: ts.SourceFile): void {
501-
const sfPath = absoluteFromSourceFile(sf);
502-
if (this.state.has(sfPath)) {
503-
const existingResults = this.state.get(sfPath)!;
501+
private maybeAdoptPriorResults() {
502+
if (this.priorResultsAdopted) {
503+
return;
504+
}
504505

505-
if (existingResults.isComplete) {
506-
// All data for this file has already been generated, so no need to adopt anything.
507-
return;
506+
for (const sf of this.originalProgram.getSourceFiles()) {
507+
if (sf.isDeclarationFile || isShim(sf)) {
508+
continue;
508509
}
509-
}
510510

511-
const previousResults = this.priorBuild.priorTypeCheckingResultsFor(sf);
512-
if (previousResults === null || !previousResults.isComplete) {
513-
return;
511+
const sfPath = absoluteFromSourceFile(sf);
512+
if (this.state.has(sfPath)) {
513+
const existingResults = this.state.get(sfPath)!;
514+
515+
if (existingResults.isComplete) {
516+
// All data for this file has already been generated, so no need to adopt anything.
517+
continue;
518+
}
519+
}
520+
521+
const previousResults = this.priorBuild.priorTypeCheckingResultsFor(sf);
522+
if (previousResults === null || !previousResults.isComplete) {
523+
continue;
524+
}
525+
526+
this.perf.eventCount(PerfEvent.ReuseTypeCheckFile);
527+
this.state.set(sfPath, previousResults);
514528
}
515529

516-
this.perf.eventCount(PerfEvent.ReuseTypeCheckFile);
517-
this.state.set(sfPath, previousResults);
530+
this.priorResultsAdopted = true;
518531
}
519532

520533
private ensureAllShimsForAllFiles(): void {
521534
if (this.isComplete) {
522535
return;
523536
}
537+
this.maybeAdoptPriorResults();
524538

525539
this.perf.inPhase(PerfPhase.TcbGeneration, () => {
526540
const host = new WholeProgramTypeCheckingHost(this);
@@ -531,8 +545,6 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
531545
continue;
532546
}
533547

534-
this.maybeAdoptPriorResultsForFile(sf);
535-
536548
const sfPath = absoluteFromSourceFile(sf);
537549
const fileData = this.getFileData(sfPath);
538550
if (fileData.isComplete) {
@@ -550,9 +562,9 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
550562
}
551563

552564
private ensureAllShimsForOneFile(sf: ts.SourceFile): void {
553-
this.perf.inPhase(PerfPhase.TcbGeneration, () => {
554-
this.maybeAdoptPriorResultsForFile(sf);
565+
this.maybeAdoptPriorResults();
555566

567+
this.perf.inPhase(PerfPhase.TcbGeneration, () => {
556568
const sfPath = absoluteFromSourceFile(sf);
557569

558570
const fileData = this.getFileData(sfPath);
@@ -573,12 +585,11 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker {
573585
}
574586

575587
private ensureShimForComponent(component: ts.ClassDeclaration): void {
588+
this.maybeAdoptPriorResults();
589+
576590
const sf = component.getSourceFile();
577591
const sfPath = absoluteFromSourceFile(sf);
578592
const shimPath = TypeCheckShimGenerator.shimFor(sfPath);
579-
580-
this.maybeAdoptPriorResultsForFile(sf);
581-
582593
const fileData = this.getFileData(sfPath);
583594

584595
if (fileData.shimData.has(shimPath)) {

0 commit comments

Comments
 (0)