Skip to content

Commit ae2f5e1

Browse files
committed
Add more files to be strict-null checked (#60565)
1 parent 56df542 commit ae2f5e1

File tree

12 files changed

+82
-59
lines changed

12 files changed

+82
-59
lines changed

Diff for: src/tsconfig.strictNullChecks.json

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"include": [
88
"./typings",
99
"./vs/base/browser/history.ts",
10+
"./vs/base/browser/iframe.ts",
1011
"./vs/base/browser/ui/octiconLabel/octiconLabel.mock.ts",
1112
"./vs/base/browser/ui/octiconLabel/octiconLabel.ts",
1213
"./vs/base/browser/ui/scrollbar/scrollbarState.ts",
@@ -17,11 +18,13 @@
1718
"./vs/base/common/comparers.ts",
1819
"./vs/base/common/date.ts",
1920
"./vs/base/common/decorators.ts",
21+
"./vs/base/common/diff/diff.ts",
2022
"./vs/base/common/diff/diffChange.ts",
2123
"./vs/base/common/functional.ts",
2224
"./vs/base/common/idGenerator.ts",
2325
"./vs/base/common/iterator.ts",
2426
"./vs/base/common/jsonSchema.ts",
27+
"./vs/base/common/keybindingParser.ts",
2528
"./vs/base/common/keyCodes.ts",
2629
"./vs/base/common/lifecycle.ts",
2730
"./vs/base/common/marshalling.ts",
@@ -49,14 +52,21 @@
4952
"./vs/base/parts/contextmenu/electron-main/contextmenu.ts",
5053
"./vs/base/parts/quickopen/common/quickOpen.ts",
5154
"./vs/base/test/node/uri.test.perf.ts",
55+
"./vs/base/worker/workerMain.ts",
5256
"./vs/editor/common/controller/wordCharacterClassifier.ts",
5357
"./vs/editor/common/core/characterClassifier.ts",
5458
"./vs/editor/common/core/position.ts",
59+
"./vs/editor/common/core/range.ts",
5560
"./vs/editor/common/core/rgba.ts",
61+
"./vs/editor/common/core/stringBuilder.ts",
5662
"./vs/editor/common/core/uint.ts",
63+
"./vs/editor/common/view/overviewZoneManager.ts",
5764
"./vs/editor/common/viewLayout/whitespaceComputer.ts",
65+
"./vs/editor/common/viewModel/prefixSumComputer.ts",
5866
"./vs/editor/contrib/codeAction/codeActionTrigger.ts",
67+
"./vs/editor/contrib/find/replacePattern.ts",
5968
"./vs/editor/contrib/indentation/indentUtils.ts",
69+
"./vs/editor/standalone/common/monarch/monarchCommon.ts",
6070
"./vs/editor/standalone/common/monarch/monarchTypes.ts",
6171
"./vs/nls.mock.ts",
6272
"./vs/platform/clipboard/common/clipboardService.ts",

Diff for: src/vs/base/browser/iframe.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export interface IWindowChainElement {
1414
/**
1515
* The iframe element inside the window.parent corresponding to window
1616
*/
17-
iframeElement: HTMLIFrameElement;
17+
iframeElement: HTMLIFrameElement | null;
1818
}
1919

2020
let hasDifferentOriginAncestorFlag: boolean = false;
21-
let sameOriginWindowChainCache: IWindowChainElement[] = null;
21+
let sameOriginWindowChainCache: IWindowChainElement[] | null = null;
2222

23-
function getParentWindowIfSameOrigin(w: Window): Window {
23+
function getParentWindowIfSameOrigin(w: Window): Window | null {
2424
if (!w.parent || w.parent === w) {
2525
return null;
2626
}
@@ -41,7 +41,7 @@ function getParentWindowIfSameOrigin(w: Window): Window {
4141
return w.parent;
4242
}
4343

44-
function findIframeElementInParentWindow(parentWindow: Window, childWindow: Window): HTMLIFrameElement {
44+
function findIframeElementInParentWindow(parentWindow: Window, childWindow: Window): HTMLIFrameElement | null {
4545
let parentWindowIframes = parentWindow.document.getElementsByTagName('iframe');
4646
let iframe: HTMLIFrameElement;
4747
for (let i = 0, len = parentWindowIframes.length; i < len; i++) {
@@ -63,7 +63,8 @@ export class IframeUtils {
6363
public static getSameOriginWindowChain(): IWindowChainElement[] {
6464
if (!sameOriginWindowChainCache) {
6565
sameOriginWindowChainCache = [];
66-
let w = window, parent: Window;
66+
let w: Window | null = window;
67+
let parent: Window | null;
6768
do {
6869
parent = getParentWindowIfSameOrigin(w);
6970
if (parent) {

Diff for: src/vs/base/common/diff/diff.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ export class LcsDiff {
216216

217217
private OriginalSequence: ISequence;
218218
private ModifiedSequence: ISequence;
219-
private ContinueProcessingPredicate: IContinueProcessingPredicate;
219+
private ContinueProcessingPredicate: IContinueProcessingPredicate | null;
220220

221221
private m_forwardHistory: number[][];
222222
private m_reverseHistory: number[][];
223223

224224
/**
225225
* Constructs the DiffFinder
226226
*/
227-
constructor(originalSequence: ISequence, newSequence: ISequence, continueProcessingPredicate: IContinueProcessingPredicate = null) {
227+
constructor(originalSequence: ISequence, newSequence: ISequence, continueProcessingPredicate: IContinueProcessingPredicate | null = null) {
228228
this.OriginalSequence = originalSequence;
229229
this.ModifiedSequence = newSequence;
230230
this.ContinueProcessingPredicate = continueProcessingPredicate;
@@ -362,7 +362,7 @@ export class LcsDiff {
362362
originalIndex: number, originalEnd: number, midOriginalArr: number[],
363363
modifiedIndex: number, modifiedEnd: number, midModifiedArr: number[],
364364
deltaIsEven: boolean, quitEarlyArr: boolean[]): DiffChange[] {
365-
let forwardChanges: DiffChange[] = null, reverseChanges: DiffChange[] = null;
365+
let forwardChanges: DiffChange[] | null = null, reverseChanges: DiffChange[] | null = null;
366366

367367
// First, walk backward through the forward diagonals history
368368
let changeHelper = new DiffChangeHelper();
@@ -498,7 +498,7 @@ export class LcsDiff {
498498
* @returns The diff changes, if available, otherwise null
499499
*/
500500
private ComputeRecursionPoint(originalStart: number, originalEnd: number, modifiedStart: number, modifiedEnd: number, midOriginalArr: number[], midModifiedArr: number[], quitEarlyArr: boolean[]) {
501-
let originalIndex: number, modifiedIndex: number;
501+
let originalIndex = 0, modifiedIndex = 0;
502502
let diagonalForwardStart = 0, diagonalForwardEnd = 0;
503503
let diagonalReverseStart = 0, diagonalReverseEnd = 0;
504504
let numDifferences: number;
@@ -763,9 +763,9 @@ export class LcsDiff {
763763
change.modifiedStart++;
764764
}
765765

766-
let mergedChangeArr: DiffChange[] = [null];
766+
let mergedChangeArr: (DiffChange | null)[] = [null];
767767
if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) {
768-
changes[i] = mergedChangeArr[0];
768+
changes[i] = mergedChangeArr[0]!;
769769
changes.splice(i + 1, 1);
770770
i--;
771771
continue;
@@ -882,7 +882,6 @@ export class LcsDiff {
882882
*/
883883
private ConcatenateChanges(left: DiffChange[], right: DiffChange[]): DiffChange[] {
884884
let mergedChangeArr: DiffChange[] = [];
885-
let result: DiffChange[] = null;
886885

887886
if (left.length === 0 || right.length === 0) {
888887
return (right.length > 0) ? right : left;
@@ -891,14 +890,14 @@ export class LcsDiff {
891890
// might recurse in the middle of a change thereby splitting it into
892891
// two changes. Here in the combining stage, we detect and fuse those
893892
// changes back together
894-
result = new Array<DiffChange>(left.length + right.length - 1);
893+
let result = new Array<DiffChange>(left.length + right.length - 1);
895894
MyArray.Copy(left, 0, result, 0, left.length - 1);
896895
result[left.length - 1] = mergedChangeArr[0];
897896
MyArray.Copy(right, 1, result, left.length, right.length - 1);
898897

899898
return result;
900899
} else {
901-
result = new Array<DiffChange>(left.length + right.length);
900+
let result = new Array<DiffChange>(left.length + right.length);
902901
MyArray.Copy(left, 0, result, 0, left.length);
903902
MyArray.Copy(right, 0, result, left.length, right.length);
904903

@@ -914,7 +913,7 @@ export class LcsDiff {
914913
* @param mergedChange The merged change if the two overlap, null otherwise
915914
* @returns True if the two changes overlap
916915
*/
917-
private ChangesOverlap(left: DiffChange, right: DiffChange, mergedChangeArr: DiffChange[]): boolean {
916+
private ChangesOverlap(left: DiffChange, right: DiffChange, mergedChangeArr: (DiffChange | null)[]): boolean {
918917
Debug.Assert(left.originalStart <= right.originalStart, 'Left change is not less than or equal to right change');
919918
Debug.Assert(left.modifiedStart <= right.modifiedStart, 'Left change is not less than or equal to right change');
920919

Diff for: src/vs/base/common/keybindingParser.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export class KeybindingParser {
8080
return [new SimpleKeybinding(mods.ctrl, mods.shift, mods.alt, mods.meta, keyCode), mods.remains];
8181
}
8282

83-
public static parseKeybinding(input: string, OS: OperatingSystem): Keybinding {
83+
public static parseKeybinding(input: string, OS: OperatingSystem): Keybinding | null {
8484
if (!input) {
8585
return null;
8686
}
8787

8888
let [firstPart, remains] = this.parseSimpleKeybinding(input);
89-
let chordPart: SimpleKeybinding = null;
89+
let chordPart: SimpleKeybinding | null = null;
9090
if (remains.length > 0) {
9191
[chordPart] = this.parseSimpleKeybinding(remains);
9292
}
@@ -109,13 +109,13 @@ export class KeybindingParser {
109109
return [new SimpleKeybinding(mods.ctrl, mods.shift, mods.alt, mods.meta, keyCode), mods.remains];
110110
}
111111

112-
static parseUserBinding(input: string): [SimpleKeybinding | ScanCodeBinding, SimpleKeybinding | ScanCodeBinding] {
112+
static parseUserBinding(input: string): [SimpleKeybinding | ScanCodeBinding | null, SimpleKeybinding | ScanCodeBinding | null] {
113113
if (!input) {
114114
return [null, null];
115115
}
116116

117117
let [firstPart, remains] = this.parseSimpleUserBinding(input);
118-
let chordPart: SimpleKeybinding | ScanCodeBinding = null;
118+
let chordPart: SimpleKeybinding | ScanCodeBinding | null = null;
119119
if (remains.length > 0) {
120120
[chordPart] = this.parseSimpleUserBinding(remains);
121121
}

Diff for: src/vs/base/worker/workerMain.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
self.onmessage = (e) => messageHandler.onmessage(e.data);
2929
while (beforeReadyMessages.length > 0) {
30-
self.onmessage(beforeReadyMessages.shift());
30+
self.onmessage(beforeReadyMessages.shift()!);
3131
}
3232
}, 0);
3333
});

Diff for: src/vs/editor/common/core/range.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ export class Range {
172172
/**
173173
* A intersection of the two ranges.
174174
*/
175-
public intersectRanges(range: IRange): Range {
175+
public intersectRanges(range: IRange): Range | null {
176176
return Range.intersectRanges(this, range);
177177
}
178178

179179
/**
180180
* A intersection of the two ranges.
181181
*/
182-
public static intersectRanges(a: IRange, b: IRange): Range {
182+
public static intersectRanges(a: IRange, b: IRange): Range | null {
183183
let resultStartLineNumber = a.startLineNumber;
184184
let resultStartColumn = a.startColumn;
185185
let resultEndLineNumber = a.endLineNumber;
@@ -292,7 +292,9 @@ export class Range {
292292
/**
293293
* Create a `Range` from an `IRange`.
294294
*/
295-
public static lift(range: IRange): Range {
295+
public static lift(range: undefined | null): null;
296+
public static lift(range: IRange): Range;
297+
public static lift(range: IRange | undefined | null): Range | null {
296298
if (!range) {
297299
return null;
298300
}

Diff for: src/vs/editor/common/core/stringBuilder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StringBuilder implements IStringBuilder {
3232
private readonly _capacity: number;
3333
private readonly _buffer: Uint16Array;
3434

35-
private _completedStrings: string[];
35+
private _completedStrings: string[] | null;
3636
private _bufferLength: number;
3737

3838
constructor(capacity: number) {
@@ -104,7 +104,7 @@ class StringBuilder implements IStringBuilder {
104104
// This string does not fit in the remaining buffer space
105105

106106
this._flushBuffer();
107-
this._completedStrings[this._completedStrings.length] = str;
107+
this._completedStrings![this._completedStrings!.length] = str;
108108
return;
109109
}
110110

Diff for: src/vs/editor/common/view/overviewZoneManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class OverviewRulerZone {
4141
public readonly endLineNumber: number;
4242
public readonly color: string;
4343

44-
private _colorZone: ColorZone;
44+
private _colorZone: ColorZone | null;
4545

4646
constructor(
4747
startLineNumber: number,
@@ -68,7 +68,7 @@ export class OverviewRulerZone {
6868
this._colorZone = colorZone;
6969
}
7070

71-
public getColorZones(): ColorZone {
71+
public getColorZones(): ColorZone | null {
7272
return this._colorZone;
7373
}
7474
}

Diff for: src/vs/editor/common/viewModel/prefixSumComputer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ export class PrefixSumComputer {
165165

166166
let low = 0;
167167
let high = this.values.length - 1;
168-
let mid: number;
169-
let midStop: number;
170-
let midStart: number;
168+
let mid = 0;
169+
let midStop = 0;
170+
let midStart = 0;
171171

172172
while (low <= high) {
173173
mid = low + ((high - low) / 2) | 0;
@@ -192,7 +192,7 @@ export class PrefixSumComputerWithCache {
192192

193193
private readonly _actual: PrefixSumComputer;
194194
private _cacheAccumulatedValueStart: number = 0;
195-
private _cache: PrefixSumIndexOfResult[] = null;
195+
private _cache: PrefixSumIndexOfResult[] | null = null;
196196

197197
constructor(values: Uint32Array) {
198198
this._actual = new PrefixSumComputer(values);

Diff for: src/vs/editor/contrib/find/replacePattern.ts

+33-23
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,57 @@
55

66
import { CharCode } from 'vs/base/common/charCode';
77

8+
const enum ReplacePatternKind {
9+
StaticValue = 0,
10+
DynamicPieces = 1
11+
}
12+
13+
/**
14+
* Assigned when the replace pattern is entirely static.
15+
*/
16+
class StaticValueReplacePattern {
17+
public readonly kind = ReplacePatternKind.StaticValue;
18+
constructor(public readonly staticValue: string) { }
19+
}
20+
21+
/**
22+
* Assigned when the replace pattern has replacemend patterns.
23+
*/
24+
class DynamicPiecesReplacePattern {
25+
public readonly kind = ReplacePatternKind.DynamicPieces;
26+
constructor(public readonly pieces: ReplacePiece[]) { }
27+
}
28+
829
export class ReplacePattern {
930

1031
public static fromStaticValue(value: string): ReplacePattern {
1132
return new ReplacePattern([ReplacePiece.staticValue(value)]);
1233
}
1334

14-
/**
15-
* Assigned when the replace pattern is entirely static.
16-
*/
17-
private readonly _staticValue: string;
35+
private readonly _state: StaticValueReplacePattern | DynamicPiecesReplacePattern;
1836

1937
public get hasReplacementPatterns(): boolean {
20-
return this._staticValue === null;
38+
return (this._state.kind === ReplacePatternKind.DynamicPieces);
2139
}
2240

23-
/**
24-
* Assigned when the replace pattern has replacemend patterns.
25-
*/
26-
private readonly _pieces: ReplacePiece[];
27-
28-
constructor(pieces: ReplacePiece[]) {
41+
constructor(pieces: ReplacePiece[] | null) {
2942
if (!pieces || pieces.length === 0) {
30-
this._staticValue = '';
31-
this._pieces = null;
43+
this._state = new StaticValueReplacePattern('');
3244
} else if (pieces.length === 1 && pieces[0].staticValue !== null) {
33-
this._staticValue = pieces[0].staticValue;
34-
this._pieces = null;
45+
this._state = new StaticValueReplacePattern(pieces[0].staticValue);
3546
} else {
36-
this._staticValue = null;
37-
this._pieces = pieces;
47+
this._state = new DynamicPiecesReplacePattern(pieces);
3848
}
3949
}
4050

4151
public buildReplaceString(matches: string[]): string {
42-
if (this._staticValue !== null) {
43-
return this._staticValue;
52+
if (this._state.kind === ReplacePatternKind.StaticValue) {
53+
return this._state.staticValue;
4454
}
4555

4656
let result = '';
47-
for (let i = 0, len = this._pieces.length; i < len; i++) {
48-
let piece = this._pieces[i];
57+
for (let i = 0, len = this._state.pieces.length; i < len; i++) {
58+
let piece = this._state.pieces[i];
4959
if (piece.staticValue !== null) {
5060
// static value ReplacePiece
5161
result += piece.staticValue;
@@ -91,10 +101,10 @@ export class ReplacePiece {
91101
return new ReplacePiece(null, index);
92102
}
93103

94-
public readonly staticValue: string;
104+
public readonly staticValue: string | null;
95105
public readonly matchIndex: number;
96106

97-
private constructor(staticValue: string, matchIndex: number) {
107+
private constructor(staticValue: string | null, matchIndex: number) {
98108
this.staticValue = staticValue;
99109
this.matchIndex = matchIndex;
100110
}

0 commit comments

Comments
 (0)