@@ -339,7 +339,6 @@ namespace ts {
339
339
if ( ! seenAffectedFiles . has ( affectedFile . path ) ) {
340
340
// Set the next affected file as seen and remove the cached semantic diagnostics
341
341
state . affectedFilesIndex = affectedFilesIndex ;
342
- cleanSemanticDiagnosticsOfAffectedFile ( state , affectedFile ) ;
343
342
handleDtsMayChangeOfAffectedFile ( state , affectedFile , cancellationToken , computeHash ) ;
344
343
return affectedFile ;
345
344
}
@@ -407,60 +406,25 @@ namespace ts {
407
406
}
408
407
409
408
/**
410
- * Remove the semantic diagnostics cached from old state for affected File and the files that are referencing modules that export entities from affected file
411
- */
412
- function cleanSemanticDiagnosticsOfAffectedFile ( state : BuilderProgramState , affectedFile : SourceFile ) {
413
- if ( removeSemanticDiagnosticsOf ( state , affectedFile . path ) ) {
414
- // If there are no more diagnostics from old cache, done
415
- return ;
416
- }
417
-
418
- // Clean lib file diagnostics if its all files excluding default files to emit
419
- if ( state . allFilesExcludingDefaultLibraryFile === state . affectedFiles && ! state . cleanedDiagnosticsOfLibFiles ) {
420
- state . cleanedDiagnosticsOfLibFiles = true ;
421
- const program = Debug . assertDefined ( state . program ) ;
422
- const options = program . getCompilerOptions ( ) ;
423
- if ( forEach ( program . getSourceFiles ( ) , f =>
424
- program . isSourceFileDefaultLibrary ( f ) &&
425
- ! skipTypeChecking ( f , options ) &&
426
- removeSemanticDiagnosticsOf ( state , f . path )
427
- ) ) {
428
- return ;
429
- }
430
- }
431
-
432
- // If there was change in signature for the changed file,
433
- // then delete the semantic diagnostics for files that are affected by using exports of this module
434
- forEachReferencingModulesOfExportOfAffectedFile ( state , affectedFile , removeSemanticDiagnosticsOf ) ;
435
- }
436
-
437
- /**
438
- * Removes semantic diagnostics for path and
439
- * returns true if there are no more semantic diagnostics from the old state
440
- */
441
- function removeSemanticDiagnosticsOf ( state : BuilderProgramState , path : Path ) {
442
- if ( ! state . semanticDiagnosticsFromOldState ) {
443
- return true ;
444
- }
445
- state . semanticDiagnosticsFromOldState . delete ( path ) ;
446
- state . semanticDiagnosticsPerFile ! . delete ( path ) ;
447
- return ! state . semanticDiagnosticsFromOldState . size ;
448
- }
449
-
450
- /**
451
- * Add files, that are referencing modules that export entities from affected file as pending emit since dts may change
409
+ * Handles sematic diagnostics and dts emit for affectedFile and files, that are referencing modules that export entities from affected file
410
+ * This is because even though js emit doesnt change, dts emit / type used can change resulting in need for dts emit and js change
452
411
* Similar to cleanSemanticDiagnosticsOfAffectedFile
453
412
*/
454
413
function handleDtsMayChangeOfAffectedFile ( state : BuilderProgramState , affectedFile : SourceFile , cancellationToken : CancellationToken | undefined , computeHash : BuilderState . ComputeHash ) {
414
+ removeSemanticDiagnosticsOf ( state , affectedFile . path ) ;
455
415
456
416
// If affected files is everything except default librarry, then nothing more to do
457
417
if ( state . allFilesExcludingDefaultLibraryFile === state . affectedFiles ) {
458
- return ;
459
- }
460
-
461
- // If there was change in signature (dts output) for the changed file,
462
- // then only we need to handle pending file emit
463
- if ( ! state . exportedModulesMap || state . affectedFiles ! . length === 1 || ! state . changedFilesSet . has ( affectedFile . path ) ) {
418
+ if ( ! state . cleanedDiagnosticsOfLibFiles ) {
419
+ state . cleanedDiagnosticsOfLibFiles = true ;
420
+ const program = Debug . assertDefined ( state . program ) ;
421
+ const options = program . getCompilerOptions ( ) ;
422
+ forEach ( program . getSourceFiles ( ) , f =>
423
+ program . isSourceFileDefaultLibrary ( f ) &&
424
+ ! skipTypeChecking ( f , options ) &&
425
+ removeSemanticDiagnosticsOf ( state , f . path )
426
+ ) ;
427
+ }
464
428
return ;
465
429
}
466
430
@@ -472,6 +436,8 @@ namespace ts {
472
436
* Also we need to make sure signature is updated for these files
473
437
*/
474
438
function handleDtsMayChangeOf ( state : BuilderProgramState , path : Path , cancellationToken : CancellationToken | undefined , computeHash : BuilderState . ComputeHash ) {
439
+ removeSemanticDiagnosticsOf ( state , path ) ;
440
+
475
441
if ( ! state . changedFilesSet . has ( path ) ) {
476
442
const program = Debug . assertDefined ( state . program ) ;
477
443
const sourceFile = program . getSourceFileByPath ( path ) ;
@@ -483,9 +449,23 @@ namespace ts {
483
449
}
484
450
}
485
451
}
452
+
486
453
return false ;
487
454
}
488
455
456
+ /**
457
+ * Removes semantic diagnostics for path and
458
+ * returns true if there are no more semantic diagnostics from the old state
459
+ */
460
+ function removeSemanticDiagnosticsOf ( state : BuilderProgramState , path : Path ) {
461
+ if ( ! state . semanticDiagnosticsFromOldState ) {
462
+ return true ;
463
+ }
464
+ state . semanticDiagnosticsFromOldState . delete ( path ) ;
465
+ state . semanticDiagnosticsPerFile ! . delete ( path ) ;
466
+ return ! state . semanticDiagnosticsFromOldState . size ;
467
+ }
468
+
489
469
/**
490
470
* Iterate on referencing modules that export entities from affected file
491
471
*/
0 commit comments