@@ -646,6 +646,7 @@ namespace ts {
646
646
( ( typeDirectiveNames , containingFile , redirectedReference ) => resolutionCache . resolveTypeReferenceDirectives ( typeDirectiveNames , containingFile , redirectedReference ) ) ;
647
647
const userProvidedResolution = ! ! host . resolveModuleNames || ! ! host . resolveTypeReferenceDirectives ;
648
648
649
+ readBuilderProgram ( ) ;
649
650
synchronizeProgram ( ) ;
650
651
651
652
// Update the wild card directory watch
@@ -655,18 +656,30 @@ namespace ts {
655
656
{ getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram } :
656
657
{ getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram , updateRootFileNames } ;
657
658
659
+ function readBuilderProgram ( ) {
660
+ if ( compilerOptions . out || compilerOptions . outFile ) return ;
661
+ if ( ! isIncrementalCompilation ( compilerOptions ) ) return ;
662
+ const buildInfoPath = getOutputPathForBuildInfo ( compilerOptions ) ;
663
+ if ( ! buildInfoPath ) return ;
664
+ const content = directoryStructureHost . readFile ( buildInfoPath ) ;
665
+ if ( ! content ) return ;
666
+ const buildInfo = JSON . parse ( content ) as BuildInfo ;
667
+ if ( ! buildInfo . program ) return ;
668
+ builderProgram = createBuildProgramUsingProgramBuildInfo ( buildInfo . program ) as any as T ;
669
+ }
670
+
658
671
function getCurrentBuilderProgram ( ) {
659
672
return builderProgram ;
660
673
}
661
674
662
675
function getCurrentProgram ( ) {
663
- return builderProgram && builderProgram . getProgram ( ) ;
676
+ return builderProgram && builderProgram . getProgramOrUndefined ( ) ;
664
677
}
665
678
666
679
function synchronizeProgram ( ) {
667
680
writeLog ( `Synchronizing program` ) ;
668
681
669
- const program = getCurrentProgram ( ) ;
682
+ const program = getCurrentBuilderProgram ( ) ;
670
683
if ( hasChangedCompilerOptions ) {
671
684
newLine = updateNewLine ( ) ;
672
685
if ( program && changesAffectModuleResolution ( program . getCompilerOptions ( ) , compilerOptions ) ) {
@@ -683,7 +696,7 @@ namespace ts {
683
696
}
684
697
}
685
698
else {
686
- createNewProgram ( program , hasInvalidatedResolution ) ;
699
+ createNewProgram ( hasInvalidatedResolution ) ;
687
700
}
688
701
689
702
if ( host . afterProgramCreate ) {
@@ -693,13 +706,13 @@ namespace ts {
693
706
return builderProgram ;
694
707
}
695
708
696
- function createNewProgram ( program : Program , hasInvalidatedResolution : HasInvalidatedResolution ) {
709
+ function createNewProgram ( hasInvalidatedResolution : HasInvalidatedResolution ) {
697
710
// Compile the program
698
711
writeLog ( "CreatingProgramWith::" ) ;
699
712
writeLog ( ` roots: ${ JSON . stringify ( rootFileNames ) } ` ) ;
700
713
writeLog ( ` options: ${ JSON . stringify ( compilerOptions ) } ` ) ;
701
714
702
- const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || ! program ;
715
+ const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || ! getCurrentProgram ( ) ;
703
716
hasChangedCompilerOptions = false ;
704
717
hasChangedConfigFileParsingErrors = false ;
705
718
resolutionCache . startCachingPerDirectoryResolution ( ) ;
0 commit comments