@@ -129,7 +129,6 @@ namespace ts {
129
129
const diagnostics = program . getConfigFileParsingDiagnostics ( ) . slice ( ) ;
130
130
const configFileParsingDiagnosticsLength = diagnostics . length ;
131
131
addRange ( diagnostics , program . getSyntacticDiagnostics ( ) ) ;
132
- let reportSemanticDiagnostics = false ;
133
132
134
133
// If we didn't have any syntactic errors, then also try getting the global and
135
134
// semantic errors.
@@ -138,18 +137,14 @@ namespace ts {
138
137
addRange ( diagnostics , program . getGlobalDiagnostics ( ) ) ;
139
138
140
139
if ( diagnostics . length === configFileParsingDiagnosticsLength ) {
141
- reportSemanticDiagnostics = true ;
140
+ addRange ( diagnostics , program . getSemanticDiagnostics ( ) ) ;
142
141
}
143
142
}
144
143
145
144
// Emit and report any errors we ran into.
146
145
const { emittedFiles, emitSkipped, diagnostics : emitDiagnostics } = program . emit ( /*targetSourceFile*/ undefined , writeFile ) ;
147
146
addRange ( diagnostics , emitDiagnostics ) ;
148
147
149
- if ( reportSemanticDiagnostics ) {
150
- addRange ( diagnostics , program . getSemanticDiagnostics ( ) ) ;
151
- }
152
-
153
148
sortAndDeduplicateDiagnostics ( diagnostics ) . forEach ( reportDiagnostic ) ;
154
149
if ( writeFileName ) {
155
150
const currentDir = program . getCurrentDirectory ( ) ;
@@ -506,6 +501,9 @@ namespace ts {
506
501
/** Gets the existing program without synchronizing with changes on host */
507
502
/*@internal */
508
503
getCurrentProgram ( ) : T ;
504
+ /** Closes the watch */
505
+ /*@internal */
506
+ close ( ) : void ;
509
507
}
510
508
511
509
/**
@@ -603,8 +601,9 @@ namespace ts {
603
601
const getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
604
602
605
603
writeLog ( `Current directory: ${ currentDirectory } CaseSensitiveFileNames: ${ useCaseSensitiveFileNames } ` ) ;
604
+ let configFileWatcher : FileWatcher | undefined ;
606
605
if ( configFileName ) {
607
- watchFile ( host , configFileName , scheduleProgramReload , PollingInterval . High , WatchType . ConfigFile ) ;
606
+ configFileWatcher = watchFile ( host , configFileName , scheduleProgramReload , PollingInterval . High , WatchType . ConfigFile ) ;
608
607
}
609
608
610
609
const compilerHost = createCompilerHostFromProgramHost ( host , ( ) => compilerOptions , directoryStructureHost ) as CompilerHost & ResolutionCacheHost ;
@@ -653,8 +652,30 @@ namespace ts {
653
652
watchConfigFileWildCardDirectories ( ) ;
654
653
655
654
return configFileName ?
656
- { getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram } :
657
- { getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram , updateRootFileNames } ;
655
+ { getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram , close } :
656
+ { getCurrentProgram : getCurrentBuilderProgram , getProgram : synchronizeProgram , updateRootFileNames, close } ;
657
+
658
+ function close ( ) {
659
+ resolutionCache . clear ( ) ;
660
+ clearMap ( sourceFilesCache , value => {
661
+ if ( value && value . fileWatcher ) {
662
+ value . fileWatcher . close ( ) ;
663
+ value . fileWatcher = undefined ;
664
+ }
665
+ } ) ;
666
+ if ( configFileWatcher ) {
667
+ configFileWatcher . close ( ) ;
668
+ configFileWatcher = undefined ;
669
+ }
670
+ if ( watchedWildcardDirectories ) {
671
+ clearMap ( watchedWildcardDirectories , closeFileWatcherOf ) ;
672
+ watchedWildcardDirectories = undefined ! ;
673
+ }
674
+ if ( missingFilesMap ) {
675
+ clearMap ( missingFilesMap , closeFileWatcher ) ;
676
+ missingFilesMap = undefined ! ;
677
+ }
678
+ }
658
679
659
680
function readBuilderProgram ( ) {
660
681
if ( compilerOptions . out || compilerOptions . outFile ) return ;
0 commit comments