Skip to content

Commit 278149c

Browse files
committed
Merge branch 'master' into lookup-reexports-for-better-imports
2 parents c053413 + 11eee2b commit 278149c

File tree

273 files changed

+2862
-2036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+2862
-2036
lines changed

src/compiler/builder.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ namespace ts {
3838
* Already seen affected files
3939
*/
4040
seenAffectedFiles: Map<true> | undefined;
41+
/**
42+
* whether this program has cleaned semantic diagnostics cache for lib files
43+
*/
44+
cleanedDiagnosticsOfLibFiles?: boolean;
4145
/**
4246
* True if the semantic diagnostics were copied from the old state
4347
*/
@@ -64,9 +68,11 @@ namespace ts {
6468
state.semanticDiagnosticsPerFile = createMap<ReadonlyArray<Diagnostic>>();
6569
}
6670
state.changedFilesSet = createMap<true>();
71+
6772
const useOldState = BuilderState.canReuseOldState(state.referencedMap, oldState);
73+
const oldCompilerOptions = useOldState ? oldState!.program.getCompilerOptions() : undefined;
6874
const canCopySemanticDiagnostics = useOldState && oldState!.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile &&
69-
!compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldState!.program.getCompilerOptions());
75+
!compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldCompilerOptions!);
7076
if (useOldState) {
7177
// Verify the sanity of old state
7278
if (!oldState!.currentChangedFilePath) {
@@ -83,6 +89,8 @@ namespace ts {
8389
// Update changed files and copy semantic diagnostics if we can
8490
const referencedMap = state.referencedMap;
8591
const oldReferencedMap = useOldState ? oldState!.referencedMap : undefined;
92+
const copyDeclarationFileDiagnostics = canCopySemanticDiagnostics && !compilerOptions.skipLibCheck === !oldCompilerOptions!.skipLibCheck;
93+
const copyLibFileDiagnostics = copyDeclarationFileDiagnostics && !compilerOptions.skipDefaultLibCheck === !oldCompilerOptions!.skipDefaultLibCheck;
8694
state.fileInfos.forEach((info, sourceFilePath) => {
8795
let oldInfo: Readonly<BuilderState.FileInfo> | undefined;
8896
let newReferences: BuilderState.ReferencedSet | undefined;
@@ -101,6 +109,11 @@ namespace ts {
101109
state.changedFilesSet.set(sourceFilePath, true);
102110
}
103111
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+
104117
// Unchanged file copy diagnostics
105118
const diagnostics = oldState!.semanticDiagnosticsPerFile!.get(sourceFilePath);
106119
if (diagnostics) {
@@ -193,6 +206,19 @@ namespace ts {
193206
return;
194207
}
195208

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+
196222
// If there was change in signature for the changed file,
197223
// then delete the semantic diagnostics for files that are affected by using exports of this module
198224

@@ -268,7 +294,7 @@ namespace ts {
268294
*/
269295
function removeSemanticDiagnosticsOf(state: BuilderProgramState, path: Path) {
270296
if (!state.semanticDiagnosticsFromOldState) {
271-
return false;
297+
return true;
272298
}
273299
state.semanticDiagnosticsFromOldState.delete(path);
274300
state.semanticDiagnosticsPerFile!.delete(path);

src/compiler/builderState.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ namespace ts.BuilderState {
368368
}
369369

370370
// If this is non module emit, or its a global file, it depends on all the source files
371-
if (!state.referencedMap || (!isExternalModule(sourceFile) && !containsOnlyAmbientModules(sourceFile))) {
371+
if (!state.referencedMap || isFileAffectingGlobalScope(sourceFile)) {
372372
return getAllFileNames(state, programOfThisState);
373373
}
374374

@@ -430,6 +430,22 @@ namespace ts.BuilderState {
430430
return true;
431431
}
432432

433+
/**
434+
* Return true if file contains anything that augments to global scope we need to build them as if
435+
* they are global files as well as module
436+
*/
437+
function containsGlobalScopeAugmentation(sourceFile: SourceFile) {
438+
return some(sourceFile.moduleAugmentations, augmentation => isGlobalScopeAugmentation(augmentation.parent as ModuleDeclaration));
439+
}
440+
441+
/**
442+
* Return true if the file will invalidate all files because it affectes global scope
443+
*/
444+
function isFileAffectingGlobalScope(sourceFile: SourceFile) {
445+
return containsGlobalScopeAugmentation(sourceFile) ||
446+
!isExternalModule(sourceFile) && !containsOnlyAmbientModules(sourceFile);
447+
}
448+
433449
/**
434450
* Gets all files of the program excluding the default library file
435451
*/
@@ -473,7 +489,7 @@ namespace ts.BuilderState {
473489
* When program emits modular code, gets the files affected by the sourceFile whose shape has changed
474490
*/
475491
function getFilesAffectedByUpdatedShapeWhenModuleEmit(state: BuilderState, programOfThisState: Program, sourceFileWithUpdatedShape: SourceFile, cacheToUpdateSignature: Map<string>, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash | undefined, exportedModulesMapCache: ComputingExportedModulesMap | undefined) {
476-
if (!isExternalModule(sourceFileWithUpdatedShape) && !containsOnlyAmbientModules(sourceFileWithUpdatedShape)) {
492+
if (isFileAffectingGlobalScope(sourceFileWithUpdatedShape)) {
477493
return getAllFilesExcludingDefaultLibraryFile(state, programOfThisState, sourceFileWithUpdatedShape);
478494
}
479495

0 commit comments

Comments
 (0)