Skip to content

Commit 8deee11

Browse files
author
Andy Hanson
committed
Enable '--strictNullChecks'
1 parent 8a52ead commit 8deee11

File tree

151 files changed

+5171
-5062
lines changed

Some content is hidden

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

151 files changed

+5171
-5062
lines changed

scripts/tslint/rules/noUnnecessaryTypeAssertion2Rule.ts

-98
This file was deleted.

src/compiler/binder.ts

+89-87
Large diffs are not rendered by default.

src/compiler/builder.ts

+32-31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace ts {
55
/**
66
* State to store the changed files, affected files and cache semantic diagnostics
77
*/
8+
// TODO: GH#18217 Properties of this interface are frequently asserted to be defined.
89
export interface BuilderProgramState extends BuilderState {
910
/**
1011
* Cache of semantic diagnostics for files with their Path being the key
@@ -43,7 +44,7 @@ namespace ts {
4344

4445
function hasSameKeys<T, U>(map1: ReadonlyMap<T> | undefined, map2: ReadonlyMap<U> | undefined): boolean {
4546
// Has same size and every key is present in both maps
46-
return map1 as ReadonlyMap<T | U> === map2 || map1 && map2 && map1.size === map2.size && !forEachKey(map1, key => !map2.has(key));
47+
return map1 as ReadonlyMap<T | U> === map2 || map1 !== undefined && map2 !== undefined && map1.size === map2.size && !forEachKey(map1, key => !map2.has(key));
4748
}
4849

4950
/**
@@ -58,45 +59,45 @@ namespace ts {
5859
}
5960
state.changedFilesSet = createMap<true>();
6061
const useOldState = BuilderState.canReuseOldState(state.referencedMap, oldState);
61-
const canCopySemanticDiagnostics = useOldState && oldState.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile;
62+
const canCopySemanticDiagnostics = useOldState && oldState!.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile;
6263
if (useOldState) {
6364
// Verify the sanity of old state
64-
if (!oldState.currentChangedFilePath) {
65-
Debug.assert(!oldState.affectedFiles && (!oldState.currentAffectedFilesSignatures || !oldState.currentAffectedFilesSignatures.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
65+
if (!oldState!.currentChangedFilePath) {
66+
Debug.assert(!oldState!.affectedFiles && (!oldState!.currentAffectedFilesSignatures || !oldState!.currentAffectedFilesSignatures!.size), "Cannot reuse if only few affected files of currentChangedFile were iterated");
6667
}
6768
if (canCopySemanticDiagnostics) {
68-
Debug.assert(!forEachKey(oldState.changedFilesSet, path => oldState.semanticDiagnosticsPerFile.has(path)), "Semantic diagnostics shouldnt be available for changed files");
69+
Debug.assert(!forEachKey(oldState!.changedFilesSet, path => oldState!.semanticDiagnosticsPerFile!.has(path)), "Semantic diagnostics shouldnt be available for changed files");
6970
}
7071

7172
// Copy old state's changed files set
72-
copyEntries(oldState.changedFilesSet, state.changedFilesSet);
73+
copyEntries(oldState!.changedFilesSet, state.changedFilesSet);
7374
}
7475

7576
// Update changed files and copy semantic diagnostics if we can
7677
const referencedMap = state.referencedMap;
77-
const oldReferencedMap = useOldState && oldState.referencedMap;
78+
const oldReferencedMap = useOldState ? oldState!.referencedMap : undefined;
7879
state.fileInfos.forEach((info, sourceFilePath) => {
79-
let oldInfo: Readonly<BuilderState.FileInfo>;
80-
let newReferences: BuilderState.ReferencedSet;
80+
let oldInfo: Readonly<BuilderState.FileInfo> | undefined;
81+
let newReferences: BuilderState.ReferencedSet | undefined;
8182

8283
// if not using old state, every file is changed
8384
if (!useOldState ||
8485
// File wasnt present in old state
85-
!(oldInfo = oldState.fileInfos.get(sourceFilePath)) ||
86+
!(oldInfo = oldState!.fileInfos.get(sourceFilePath)) ||
8687
// versions dont match
8788
oldInfo.version !== info.version ||
8889
// Referenced files changed
8990
!hasSameKeys(newReferences = referencedMap && referencedMap.get(sourceFilePath), oldReferencedMap && oldReferencedMap.get(sourceFilePath)) ||
9091
// Referenced file was deleted in the new program
91-
newReferences && forEachKey(newReferences, path => !state.fileInfos.has(path) && oldState.fileInfos.has(path))) {
92+
newReferences && forEachKey(newReferences, path => !state.fileInfos.has(path) && oldState!.fileInfos.has(path))) {
9293
// Register file as changed file and do not copy semantic diagnostics, since all changed files need to be re-evaluated
9394
state.changedFilesSet.set(sourceFilePath, true);
9495
}
9596
else if (canCopySemanticDiagnostics) {
9697
// Unchanged file copy diagnostics
97-
const diagnostics = oldState.semanticDiagnosticsPerFile.get(sourceFilePath);
98+
const diagnostics = oldState!.semanticDiagnosticsPerFile!.get(sourceFilePath);
9899
if (diagnostics) {
99-
state.semanticDiagnosticsPerFile.set(sourceFilePath, diagnostics);
100+
state.semanticDiagnosticsPerFile!.set(sourceFilePath, diagnostics);
100101
}
101102
}
102103
});
@@ -108,7 +109,7 @@ namespace ts {
108109
* Verifies that source file is ok to be used in calls that arent handled by next
109110
*/
110111
function assertSourceFileOkWithoutNextAffectedCall(state: BuilderProgramState, sourceFile: SourceFile | undefined) {
111-
Debug.assert(!sourceFile || !state.affectedFiles || state.affectedFiles[state.affectedFilesIndex - 1] !== sourceFile || !state.semanticDiagnosticsPerFile.has(sourceFile.path));
112+
Debug.assert(!sourceFile || !state.affectedFiles || state.affectedFiles[state.affectedFilesIndex! - 1] !== sourceFile || !state.semanticDiagnosticsPerFile!.has(sourceFile.path));
112113
}
113114

114115
/**
@@ -122,25 +123,25 @@ namespace ts {
122123
const { affectedFiles } = state;
123124
if (affectedFiles) {
124125
const { seenAffectedFiles, semanticDiagnosticsPerFile } = state;
125-
let { affectedFilesIndex } = state;
126+
let affectedFilesIndex = state.affectedFilesIndex!; // TODO: GH#18217
126127
while (affectedFilesIndex < affectedFiles.length) {
127128
const affectedFile = affectedFiles[affectedFilesIndex];
128-
if (!seenAffectedFiles.has(affectedFile.path)) {
129+
if (!seenAffectedFiles!.has(affectedFile.path)) {
129130
// Set the next affected file as seen and remove the cached semantic diagnostics
130131
state.affectedFilesIndex = affectedFilesIndex;
131-
semanticDiagnosticsPerFile.delete(affectedFile.path);
132+
semanticDiagnosticsPerFile!.delete(affectedFile.path);
132133
return affectedFile;
133134
}
134-
seenAffectedFiles.set(affectedFile.path, true);
135+
seenAffectedFiles!.set(affectedFile.path, true);
135136
affectedFilesIndex++;
136137
}
137138

138139
// Remove the changed file from the change set
139-
state.changedFilesSet.delete(state.currentChangedFilePath);
140+
state.changedFilesSet.delete(state.currentChangedFilePath!);
140141
state.currentChangedFilePath = undefined;
141142
// Commit the changes in file signature
142-
BuilderState.updateSignaturesFromCache(state, state.currentAffectedFilesSignatures);
143-
state.currentAffectedFilesSignatures.clear();
143+
BuilderState.updateSignaturesFromCache(state, state.currentAffectedFilesSignatures!);
144+
state.currentAffectedFilesSignatures!.clear();
144145
state.affectedFiles = undefined;
145146
}
146147

@@ -163,7 +164,7 @@ namespace ts {
163164
state.currentAffectedFilesSignatures = state.currentAffectedFilesSignatures || createMap();
164165
state.affectedFiles = BuilderState.getFilesAffectedBy(state, state.program, nextKey.value as Path, cancellationToken, computeHash, state.currentAffectedFilesSignatures);
165166
state.currentChangedFilePath = nextKey.value as Path;
166-
state.semanticDiagnosticsPerFile.delete(nextKey.value as Path);
167+
state.semanticDiagnosticsPerFile!.delete(nextKey.value as Path);
167168
state.affectedFilesIndex = 0;
168169
state.seenAffectedFiles = state.seenAffectedFiles || createMap<true>();
169170
}
@@ -178,8 +179,8 @@ namespace ts {
178179
state.changedFilesSet.clear();
179180
}
180181
else {
181-
state.seenAffectedFiles.set((affected as SourceFile).path, true);
182-
state.affectedFilesIndex++;
182+
state.seenAffectedFiles!.set((affected as SourceFile).path, true);
183+
state.affectedFilesIndex!++;
183184
}
184185
}
185186

@@ -197,15 +198,15 @@ namespace ts {
197198
*/
198199
function getSemanticDiagnosticsOfFile(state: BuilderProgramState, sourceFile: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic> {
199200
const path = sourceFile.path;
200-
const cachedDiagnostics = state.semanticDiagnosticsPerFile.get(path);
201+
const cachedDiagnostics = state.semanticDiagnosticsPerFile!.get(path);
201202
// Report the semantic diagnostics from the cache if we already have those diagnostics present
202203
if (cachedDiagnostics) {
203204
return cachedDiagnostics;
204205
}
205206

206207
// Diagnostics werent cached, get them from program, and cache the result
207208
const diagnostics = state.program.getSemanticDiagnostics(sourceFile, cancellationToken);
208-
state.semanticDiagnosticsPerFile.set(path, diagnostics);
209+
state.semanticDiagnosticsPerFile!.set(path, diagnostics);
209210
return diagnostics;
210211
}
211212

@@ -241,7 +242,7 @@ namespace ts {
241242
// Return same program if underlying program doesnt change
242243
let oldState = oldProgram && oldProgram.getState();
243244
if (oldState && newProgram === oldState.program) {
244-
newProgram = undefined;
245+
newProgram = undefined!; // TODO: GH#18217
245246
oldState = undefined;
246247
return oldProgram;
247248
}
@@ -257,7 +258,7 @@ namespace ts {
257258
const state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
258259

259260
// To ensure that we arent storing any references to old program or new program without state
260-
newProgram = undefined;
261+
newProgram = undefined!; // TODO: GH#18217
261262
oldProgram = undefined;
262263
oldState = undefined;
263264

@@ -326,8 +327,8 @@ namespace ts {
326327
if (!targetSourceFile) {
327328
// Emit and report any errors we ran into.
328329
let sourceMaps: SourceMapData[] = [];
329-
let emitSkipped: boolean;
330-
let diagnostics: Diagnostic[];
330+
let emitSkipped = false;
331+
let diagnostics: Diagnostic[] | undefined;
331332
let emittedFiles: string[] = [];
332333

333334
let affectedEmitResult: AffectedFileResult<EmitResult>;
@@ -413,7 +414,7 @@ namespace ts {
413414
}
414415
}
415416

416-
let diagnostics: Diagnostic[];
417+
let diagnostics: Diagnostic[] | undefined;
417418
for (const sourceFile of state.program.getSourceFiles()) {
418419
diagnostics = addRange(diagnostics, getSemanticDiagnosticsOfFile(state, sourceFile, cancellationToken));
419420
}

0 commit comments

Comments
 (0)