Skip to content

Commit ae7e00e

Browse files
committed
Combine semantic diagnostics of files using exported entities from modules and their dts emit
1 parent 17d2c8b commit ae7e00e

File tree

1 file changed

+29
-49
lines changed

1 file changed

+29
-49
lines changed

src/compiler/builder.ts

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ namespace ts {
339339
if (!seenAffectedFiles.has(affectedFile.path)) {
340340
// Set the next affected file as seen and remove the cached semantic diagnostics
341341
state.affectedFilesIndex = affectedFilesIndex;
342-
cleanSemanticDiagnosticsOfAffectedFile(state, affectedFile);
343342
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash);
344343
return affectedFile;
345344
}
@@ -407,60 +406,25 @@ namespace ts {
407406
}
408407

409408
/**
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
452411
* Similar to cleanSemanticDiagnosticsOfAffectedFile
453412
*/
454413
function handleDtsMayChangeOfAffectedFile(state: BuilderProgramState, affectedFile: SourceFile, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
414+
removeSemanticDiagnosticsOf(state, affectedFile.path);
455415

456416
// If affected files is everything except default librarry, then nothing more to do
457417
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+
}
464428
return;
465429
}
466430

@@ -472,6 +436,8 @@ namespace ts {
472436
* Also we need to make sure signature is updated for these files
473437
*/
474438
function handleDtsMayChangeOf(state: BuilderProgramState, path: Path, cancellationToken: CancellationToken | undefined, computeHash: BuilderState.ComputeHash) {
439+
removeSemanticDiagnosticsOf(state, path);
440+
475441
if (!state.changedFilesSet.has(path)) {
476442
const program = Debug.assertDefined(state.program);
477443
const sourceFile = program.getSourceFileByPath(path);
@@ -483,9 +449,23 @@ namespace ts {
483449
}
484450
}
485451
}
452+
486453
return false;
487454
}
488455

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+
489469
/**
490470
* Iterate on referencing modules that export entities from affected file
491471
*/

0 commit comments

Comments
 (0)