@@ -38,6 +38,10 @@ namespace ts {
38
38
* Already seen affected files
39
39
*/
40
40
seenAffectedFiles : Map < true > | undefined ;
41
+ /**
42
+ * whether this program has cleaned semantic diagnostics cache for lib files
43
+ */
44
+ cleanedDiagnosticsOfLibFiles ?: boolean ;
41
45
/**
42
46
* True if the semantic diagnostics were copied from the old state
43
47
*/
@@ -64,9 +68,11 @@ namespace ts {
64
68
state . semanticDiagnosticsPerFile = createMap < ReadonlyArray < Diagnostic > > ( ) ;
65
69
}
66
70
state . changedFilesSet = createMap < true > ( ) ;
71
+
67
72
const useOldState = BuilderState . canReuseOldState ( state . referencedMap , oldState ) ;
73
+ const oldCompilerOptions = useOldState ? oldState ! . program . getCompilerOptions ( ) : undefined ;
68
74
const canCopySemanticDiagnostics = useOldState && oldState ! . semanticDiagnosticsPerFile && ! ! state . semanticDiagnosticsPerFile &&
69
- ! compilerOptionsAffectSemanticDiagnostics ( compilerOptions , oldState ! . program . getCompilerOptions ( ) ) ;
75
+ ! compilerOptionsAffectSemanticDiagnostics ( compilerOptions , oldCompilerOptions ! ) ;
70
76
if ( useOldState ) {
71
77
// Verify the sanity of old state
72
78
if ( ! oldState ! . currentChangedFilePath ) {
@@ -83,6 +89,8 @@ namespace ts {
83
89
// Update changed files and copy semantic diagnostics if we can
84
90
const referencedMap = state . referencedMap ;
85
91
const oldReferencedMap = useOldState ? oldState ! . referencedMap : undefined ;
92
+ const copyDeclarationFileDiagnostics = canCopySemanticDiagnostics && ! compilerOptions . skipLibCheck === ! oldCompilerOptions ! . skipLibCheck ;
93
+ const copyLibFileDiagnostics = copyDeclarationFileDiagnostics && ! compilerOptions . skipDefaultLibCheck === ! oldCompilerOptions ! . skipDefaultLibCheck ;
86
94
state . fileInfos . forEach ( ( info , sourceFilePath ) => {
87
95
let oldInfo : Readonly < BuilderState . FileInfo > | undefined ;
88
96
let newReferences : BuilderState . ReferencedSet | undefined ;
@@ -101,6 +109,11 @@ namespace ts {
101
109
state . changedFilesSet . set ( sourceFilePath , true ) ;
102
110
}
103
111
else if ( canCopySemanticDiagnostics ) {
112
+ const sourceFile = state . program . getSourceFileByPath ( sourceFilePath as Path ) ! ;
113
+
114
+ if ( sourceFile . isDeclarationFile && ! copyDeclarationFileDiagnostics ) { return ; }
115
+ if ( sourceFile . hasNoDefaultLib && ! copyLibFileDiagnostics ) { return ; }
116
+
104
117
// Unchanged file copy diagnostics
105
118
const diagnostics = oldState ! . semanticDiagnosticsPerFile ! . get ( sourceFilePath ) ;
106
119
if ( diagnostics ) {
@@ -193,6 +206,19 @@ namespace ts {
193
206
return ;
194
207
}
195
208
209
+ // Clean lib file diagnostics if its all files excluding default files to emit
210
+ if ( state . allFilesExcludingDefaultLibraryFile === state . affectedFiles && ! state . cleanedDiagnosticsOfLibFiles ) {
211
+ state . cleanedDiagnosticsOfLibFiles = true ;
212
+ const options = state . program . getCompilerOptions ( ) ;
213
+ if ( forEach ( state . program . getSourceFiles ( ) , f =>
214
+ state . program . isSourceFileDefaultLibrary ( f ) &&
215
+ ! skipTypeChecking ( f , options ) &&
216
+ removeSemanticDiagnosticsOf ( state , f . path )
217
+ ) ) {
218
+ return ;
219
+ }
220
+ }
221
+
196
222
// If there was change in signature for the changed file,
197
223
// then delete the semantic diagnostics for files that are affected by using exports of this module
198
224
@@ -268,7 +294,7 @@ namespace ts {
268
294
*/
269
295
function removeSemanticDiagnosticsOf ( state : BuilderProgramState , path : Path ) {
270
296
if ( ! state . semanticDiagnosticsFromOldState ) {
271
- return false ;
297
+ return true ;
272
298
}
273
299
state . semanticDiagnosticsFromOldState . delete ( path ) ;
274
300
state . semanticDiagnosticsPerFile ! . delete ( path ) ;
0 commit comments