Skip to content

Commit 3f93ea6

Browse files
committed
Auto convert let -> const in base/common
1 parent 52556f9 commit 3f93ea6

29 files changed

Lines changed: 217 additions & 217 deletions

src/vs/base/common/arrays.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export function binarySearch<T>(array: ReadonlyArray<T>, key: T, comparator: (op
5151
high = array.length - 1;
5252

5353
while (low <= high) {
54-
let mid = ((low + high) / 2) | 0;
55-
let comp = comparator(array[mid], key);
54+
const mid = ((low + high) / 2) | 0;
55+
const comp = comparator(array[mid], key);
5656
if (comp < 0) {
5757
low = mid + 1;
5858
} else if (comp > 0) {
@@ -75,7 +75,7 @@ export function findFirstInSorted<T>(array: ReadonlyArray<T>, p: (x: T) => boole
7575
return 0; // no children
7676
}
7777
while (low < high) {
78-
let mid = Math.floor((low + high) / 2);
78+
const mid = Math.floor((low + high) / 2);
7979
if (p(array[mid])) {
8080
high = mid;
8181
} else {
@@ -122,7 +122,7 @@ function _sort<T>(a: T[], compare: Compare<T>, lo: number, hi: number, aux: T[])
122122
if (hi <= lo) {
123123
return;
124124
}
125-
let mid = lo + ((hi - lo) / 2) | 0;
125+
const mid = lo + ((hi - lo) / 2) | 0;
126126
_sort(a, compare, lo, mid, aux);
127127
_sort(a, compare, mid + 1, hi, aux);
128128
if (compare(a[mid], a[mid + 1]) <= 0) {
@@ -502,8 +502,8 @@ export function shuffle<T>(array: T[], _seed?: number): void {
502502
}
503503

504504
for (let i = array.length - 1; i > 0; i -= 1) {
505-
let j = Math.floor(rand() * (i + 1));
506-
let temp = array[i];
505+
const j = Math.floor(rand() * (i + 1));
506+
const temp = array[i];
507507
array[i] = array[j];
508508
array[j] = temp;
509509
}

src/vs/base/common/async.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function createCancelablePromise<T>(callback: (token: CancellationToken)
5252

5353
export function asPromise<T>(callback: () => T | Thenable<T>): Promise<T> {
5454
return new Promise<T>((resolve, reject) => {
55-
let item = callback();
55+
const item = callback();
5656
if (isThenable<T>(item)) {
5757
item.then(resolve, reject);
5858
} else {
@@ -688,12 +688,12 @@ declare function cancelIdleCallback(handle: number): void;
688688

689689
(function () {
690690
if (typeof requestIdleCallback !== 'function' || typeof cancelIdleCallback !== 'function') {
691-
let dummyIdle: IdleDeadline = Object.freeze({
691+
const dummyIdle: IdleDeadline = Object.freeze({
692692
didTimeout: true,
693693
timeRemaining() { return 15; }
694694
});
695695
runWhenIdle = (runner) => {
696-
let handle = setTimeout(() => runner(dummyIdle));
696+
const handle = setTimeout(() => runner(dummyIdle));
697697
let disposed = false;
698698
return {
699699
dispose() {
@@ -707,7 +707,7 @@ declare function cancelIdleCallback(handle: number): void;
707707
};
708708
} else {
709709
runWhenIdle = (runner, timeout?) => {
710-
let handle: number = requestIdleCallback(runner, typeof timeout === 'number' ? { timeout } : undefined);
710+
const handle: number = requestIdleCallback(runner, typeof timeout === 'number' ? { timeout } : undefined);
711711
let disposed = false;
712712
return {
713713
dispose() {

src/vs/base/common/cancellation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface CancellationToken {
1616
}
1717

1818
const shortcutEvent = Object.freeze(function (callback, context?): IDisposable {
19-
let handle = setTimeout(callback.bind(context), 0);
19+
const handle = setTimeout(callback.bind(context), 0);
2020
return { dispose() { clearTimeout(handle); } };
2121
} as Event<any>);
2222

src/vs/base/common/color.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ export class Color {
387387
const thisA = this.rgba.a;
388388
const colorA = rgba.a;
389389

390-
let a = thisA + colorA * (1 - thisA);
390+
const a = thisA + colorA * (1 - thisA);
391391
if (a < 1e-6) {
392392
return Color.transparent;
393393
}

src/vs/base/common/comparers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ export function comparePaths(one: string, other: string, caseSensitive = false):
144144
}
145145

146146
export function compareAnything(one: string, other: string, lookFor: string): number {
147-
let elementAName = one.toLowerCase();
148-
let elementBName = other.toLowerCase();
147+
const elementAName = one.toLowerCase();
148+
const elementBName = other.toLowerCase();
149149

150150
// Sort prefix matches over non prefix matches
151151
const prefixCompare = compareByPrefix(one, other, lookFor);
@@ -154,14 +154,14 @@ export function compareAnything(one: string, other: string, lookFor: string): nu
154154
}
155155

156156
// Sort suffix matches over non suffix matches
157-
let elementASuffixMatch = strings.endsWith(elementAName, lookFor);
158-
let elementBSuffixMatch = strings.endsWith(elementBName, lookFor);
157+
const elementASuffixMatch = strings.endsWith(elementAName, lookFor);
158+
const elementBSuffixMatch = strings.endsWith(elementBName, lookFor);
159159
if (elementASuffixMatch !== elementBSuffixMatch) {
160160
return elementASuffixMatch ? -1 : 1;
161161
}
162162

163163
// Understand file names
164-
let r = compareFileNames(elementAName, elementBName);
164+
const r = compareFileNames(elementAName, elementBName);
165165
if (r !== 0) {
166166
return r;
167167
}
@@ -171,12 +171,12 @@ export function compareAnything(one: string, other: string, lookFor: string): nu
171171
}
172172

173173
export function compareByPrefix(one: string, other: string, lookFor: string): number {
174-
let elementAName = one.toLowerCase();
175-
let elementBName = other.toLowerCase();
174+
const elementAName = one.toLowerCase();
175+
const elementBName = other.toLowerCase();
176176

177177
// Sort prefix matches over non prefix matches
178-
let elementAPrefixMatch = strings.startsWith(elementAName, lookFor);
179-
let elementBPrefixMatch = strings.startsWith(elementBName, lookFor);
178+
const elementAPrefixMatch = strings.startsWith(elementAName, lookFor);
179+
const elementBPrefixMatch = strings.startsWith(elementBName, lookFor);
180180
if (elementAPrefixMatch !== elementBPrefixMatch) {
181181
return elementAPrefixMatch ? -1 : 1;
182182
}

src/vs/base/common/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function transformErrorForSerialization(error: any): any;
102102
export function transformErrorForSerialization(error: any): any {
103103
if (error instanceof Error) {
104104
let { name, message } = error;
105-
let stack: string = (<any>error).stacktrace || (<any>error).stack;
105+
const stack: string = (<any>error).stacktrace || (<any>error).stack;
106106
return {
107107
$isError: true,
108108
name,
@@ -146,7 +146,7 @@ export function isPromiseCanceledError(error: any): boolean {
146146
* Returns an error that signals cancellation.
147147
*/
148148
export function canceled(): Error {
149-
let error = new Error(canceledName);
149+
const error = new Error(canceledName);
150150
error.name = error.message;
151151
return error;
152152
}

src/vs/base/common/event.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export namespace Event {
152152

153153
clearTimeout(handle);
154154
handle = setTimeout(() => {
155-
let _output = output;
155+
const _output = output;
156156
output = undefined;
157157
handle = undefined;
158158
if (!leading || numDebouncedCalls > 1) {
@@ -190,7 +190,7 @@ export namespace Event {
190190
let cache: T;
191191

192192
return filter(event, value => {
193-
let shouldEmit = firstCall || value !== cache;
193+
const shouldEmit = firstCall || value !== cache;
194194
firstCall = false;
195195
cache = value;
196196
return shouldEmit;
@@ -389,7 +389,7 @@ export interface EmitterOptions {
389389

390390
let _globalLeakWarningThreshold = -1;
391391
export function setGlobalLeakWarningThreshold(n: number): IDisposable {
392-
let oldValue = _globalLeakWarningThreshold;
392+
const oldValue = _globalLeakWarningThreshold;
393393
_globalLeakWarningThreshold = n;
394394
return {
395395
dispose() {
@@ -428,8 +428,8 @@ class LeakageMonitor {
428428
if (!this._stacks) {
429429
this._stacks = new Map();
430430
}
431-
let stack = new Error().stack!.split('\n').slice(3).join('\n');
432-
let count = (this._stacks.get(stack) || 0);
431+
const stack = new Error().stack!.split('\n').slice(3).join('\n');
432+
const count = (this._stacks.get(stack) || 0);
433433
this._stacks.set(stack, count + 1);
434434
this._warnCountdown -= 1;
435435

@@ -453,7 +453,7 @@ class LeakageMonitor {
453453
}
454454

455455
return () => {
456-
let count = (this._stacks!.get(stack) || 0);
456+
const count = (this._stacks!.get(stack) || 0);
457457
this._stacks!.set(stack, count - 1);
458458
};
459459
}
@@ -627,7 +627,7 @@ export class AsyncEmitter<T extends IWaitUntil> extends Emitter<T> {
627627
}
628628

629629
for (let iter = this._listeners.iterator(), e = iter.next(); !e.done; e = iter.next()) {
630-
let thenables: Promise<void>[] = [];
630+
const thenables: Promise<void>[] = [];
631631
this._asyncDeliveryQueue.push([e.value, eventFn(thenables, typeof e.value === 'function' ? e.value : e.value[0]), thenables]);
632632
}
633633

src/vs/base/common/extpath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export function getRoot(path: string, sep: string = posix.sep): string {
3232
return '';
3333
}
3434

35-
let len = path.length;
35+
const len = path.length;
3636
const firstLetter = path.charCodeAt(0);
3737
if (isPathSeparator(firstLetter)) {
3838
if (isPathSeparator(path.charCodeAt(1))) {
3939
// UNC candidate \\localhost\shares\ddd
4040
// ^^^^^^^^^^^^^^^^^^^
4141
if (!isPathSeparator(path.charCodeAt(2))) {
4242
let pos = 3;
43-
let start = pos;
43+
const start = pos;
4444
for (; pos < len; pos++) {
4545
if (isPathSeparator(path.charCodeAt(pos))) {
4646
break;
@@ -121,7 +121,7 @@ export function isUNC(path: string): boolean {
121121
return false;
122122
}
123123
let pos = 2;
124-
let start = pos;
124+
const start = pos;
125125
for (; pos < path.length; pos++) {
126126
code = path.charCodeAt(pos);
127127
if (code === CharCode.Backslash) {

src/vs/base/common/filters.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface IMatch {
2828
export function or(...filter: IFilter[]): IFilter {
2929
return function (word: string, wordToMatchAgainst: string): IMatch[] | null {
3030
for (let i = 0, len = filter.length; i < len; i++) {
31-
let match = filter[i](word, wordToMatchAgainst);
31+
const match = filter[i](word, wordToMatchAgainst);
3232
if (match) {
3333
return match;
3434
}
@@ -64,7 +64,7 @@ function _matchesPrefix(ignoreCase: boolean, word: string, wordToMatchAgainst: s
6464
// Contiguous Substring
6565

6666
export function matchesContiguousSubString(word: string, wordToMatchAgainst: string): IMatch[] | null {
67-
let index = wordToMatchAgainst.toLowerCase().indexOf(word.toLowerCase());
67+
const index = wordToMatchAgainst.toLowerCase().indexOf(word.toLowerCase());
6868
if (index === -1) {
6969
return null;
7070
}
@@ -136,7 +136,7 @@ function join(head: IMatch, tail: IMatch[]): IMatch[] {
136136

137137
function nextAnchor(camelCaseWord: string, start: number): number {
138138
for (let i = start; i < camelCaseWord.length; i++) {
139-
let c = camelCaseWord.charCodeAt(i);
139+
const c = camelCaseWord.charCodeAt(i);
140140
if (isUpper(c) || isNumber(c) || (i > 0 && !isAlphanumeric(camelCaseWord.charCodeAt(i - 1)))) {
141141
return i;
142142
}
@@ -184,10 +184,10 @@ function analyzeCamelCaseWord(word: string): ICamelCaseAnalysis {
184184
if (isNumber(code)) { numeric++; }
185185
}
186186

187-
let upperPercent = upper / word.length;
188-
let lowerPercent = lower / word.length;
189-
let alphaPercent = alpha / word.length;
190-
let numericPercent = numeric / word.length;
187+
const upperPercent = upper / word.length;
188+
const lowerPercent = lower / word.length;
189+
const alphaPercent = alpha / word.length;
190+
const numericPercent = numeric / word.length;
191191

192192
return { upperPercent, lowerPercent, alphaPercent, numericPercent };
193193
}
@@ -307,7 +307,7 @@ function _matchesWords(word: string, target: string, i: number, j: number, conti
307307

308308
function nextWord(word: string, start: number): number {
309309
for (let i = start; i < word.length; i++) {
310-
let c = word.charCodeAt(i);
310+
const c = word.charCodeAt(i);
311311
if (isWhitespace(c) || (i > 0 && isWhitespace(word.charCodeAt(i - 1)))) {
312312
return i;
313313
}
@@ -334,7 +334,7 @@ export function matchesFuzzy(word: string, wordToMatchAgainst: string, enableSep
334334
}
335335

336336
// RegExp Filter
337-
let match = regexp.exec(wordToMatchAgainst);
337+
const match = regexp.exec(wordToMatchAgainst);
338338
if (match) {
339339
return [{ start: match.index, end: match.index + match[0].length }];
340340
}
@@ -348,7 +348,7 @@ export function matchesFuzzy(word: string, wordToMatchAgainst: string, enableSep
348348
* powerfull than `matchesFuzzy`
349349
*/
350350
export function matchesFuzzy2(pattern: string, word: string): IMatch[] | null {
351-
let score = fuzzyScore(pattern, pattern.toLowerCase(), 0, word, word.toLowerCase(), 0, true);
351+
const score = fuzzyScore(pattern, pattern.toLowerCase(), 0, word, word.toLowerCase(), 0, true);
352352
return score ? createMatches(score) : null;
353353
}
354354

@@ -404,7 +404,7 @@ function initTable() {
404404
row.push(-i);
405405
}
406406
for (let i = 0; i <= _maxLen; i++) {
407-
let thisRow = row.slice(0);
407+
const thisRow = row.slice(0);
408408
thisRow[0] = -i;
409409
table.push(thisRow);
410410
}
@@ -566,9 +566,9 @@ export function fuzzyScore(pattern: string, patternLow: string, patternPos: numb
566566

567567
_scores[patternPos][wordPos] = score;
568568

569-
let diag = _table[patternPos - 1][wordPos - 1] + (score > 1 ? 1 : score);
570-
let top = _table[patternPos - 1][wordPos] + -1;
571-
let left = _table[patternPos][wordPos - 1] + -1;
569+
const diag = _table[patternPos - 1][wordPos - 1] + (score > 1 ? 1 : score);
570+
const top = _table[patternPos - 1][wordPos] + -1;
571+
const left = _table[patternPos][wordPos - 1] + -1;
572572

573573
if (left >= top) {
574574
// left or diag
@@ -635,8 +635,8 @@ function _findAllMatches2(patternPos: number, wordPos: number, total: number, ma
635635

636636
while (patternPos > _patternStartPos && wordPos > 0) {
637637

638-
let score = _scores[patternPos][wordPos];
639-
let arrow = _arrows[patternPos][wordPos];
638+
const score = _scores[patternPos][wordPos];
639+
const arrow = _arrows[patternPos][wordPos];
640640

641641
if (arrow === Arrow.Left) {
642642
// left -> no match, skip a word character
@@ -733,11 +733,11 @@ function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, pattern
733733
// permutations of the pattern to find a better match. The
734734
// permutations only swap neighbouring characters, e.g
735735
// `cnoso` becomes `conso`, `cnsoo`, `cnoos`.
736-
let tries = Math.min(7, pattern.length - 1);
736+
const tries = Math.min(7, pattern.length - 1);
737737
for (let movingPatternPos = patternPos + 1; movingPatternPos < tries; movingPatternPos++) {
738-
let newPattern = nextTypoPermutation(pattern, movingPatternPos);
738+
const newPattern = nextTypoPermutation(pattern, movingPatternPos);
739739
if (newPattern) {
740-
let candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
740+
const candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
741741
if (candidate) {
742742
candidate[0] -= 3; // permutation penalty
743743
if (!top || candidate[0] > top[0]) {
@@ -757,8 +757,8 @@ function nextTypoPermutation(pattern: string, patternPos: number): string | unde
757757
return undefined;
758758
}
759759

760-
let swap1 = pattern[patternPos];
761-
let swap2 = pattern[patternPos + 1];
760+
const swap1 = pattern[patternPos];
761+
const swap2 = pattern[patternPos + 1];
762762

763763
if (swap1 === swap2) {
764764
return undefined;

src/vs/base/common/glob.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function splitGlobAware(pattern: string, splitChar: string): string[] {
5353
return [];
5454
}
5555

56-
let segments: string[] = [];
56+
const segments: string[] = [];
5757

5858
let inBraces = false;
5959
let inBrackets = false;
@@ -102,7 +102,7 @@ function parseRegExp(pattern: string): string {
102102
let regEx = '';
103103

104104
// Split up into segments for each slash found
105-
let segments = splitGlobAware(pattern, GLOB_SPLIT);
105+
const segments = splitGlobAware(pattern, GLOB_SPLIT);
106106

107107
// Special case where we only have globstars
108108
if (segments.every(s => s === GLOBSTAR)) {
@@ -179,10 +179,10 @@ function parseRegExp(pattern: string): string {
179179
continue;
180180

181181
case '}':
182-
let choices = splitGlobAware(braceVal, ',');
182+
const choices = splitGlobAware(braceVal, ',');
183183

184184
// Converts {foo,bar} => [foo|bar]
185-
let braceRegExp = `(?:${choices.map(c => parseRegExp(c)).join('|')})`;
185+
const braceRegExp = `(?:${choices.map(c => parseRegExp(c)).join('|')})`;
186186

187187
regEx += braceRegExp;
188188

0 commit comments

Comments
 (0)