Skip to content

Commit 608fc2c

Browse files
committed
Auto convert let -> const in base/node
1 parent 3f93ea6 commit 608fc2c

9 files changed

Lines changed: 49 additions & 49 deletions

File tree

src/vs/base/node/decoder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class LineDecoder {
2424
}
2525

2626
public write(buffer: Buffer): string[] {
27-
let result: string[] = [];
28-
let value = this.remaining
27+
const result: string[] = [];
28+
const value = this.remaining
2929
? this.remaining + this.stringDecoder.write(buffer)
3030
: this.stringDecoder.write(buffer);
3131

@@ -41,7 +41,7 @@ export class LineDecoder {
4141
result.push(value.substring(start, idx));
4242
idx++;
4343
if (idx < value.length) {
44-
let lastChar = ch;
44+
const lastChar = ch;
4545
ch = value.charCodeAt(idx);
4646
if ((lastChar === CharCode.CarriageReturn && ch === CharCode.LineFeed) || (lastChar === CharCode.LineFeed && ch === CharCode.CarriageReturn)) {
4747
idx++;

src/vs/base/node/flow.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import * as assert from 'assert';
1010
* array to the callback (callback). The resulting errors and results are evaluated by calling the provided callback function.
1111
*/
1212
export function parallel<T, E>(list: T[], fn: (item: T, callback: (err: Error | null, result: E | null) => void) => void, callback: (err: Array<Error | null> | null, result: E[]) => void): void {
13-
let results = new Array(list.length);
14-
let errors = new Array<Error | null>(list.length);
13+
const results = new Array(list.length);
14+
const errors = new Array<Error | null>(list.length);
1515
let didErrorOccur = false;
1616
let doneCount = 0;
1717

@@ -68,9 +68,9 @@ export function loop<E>(param: any, fn: (item: any, callback: (error: Error | nu
6868

6969
// Expect the param to be an array and loop over it
7070
else {
71-
let results: E[] = [];
71+
const results: E[] = [];
7272

73-
let looper: (i: number) => void = function (i: number): void {
73+
const looper: (i: number) => void = function (i: number): void {
7474

7575
// Still work to do
7676
if (i < param.length) {
@@ -126,11 +126,11 @@ function Sequence(sequences: { (...param: any[]): void; }[]): void {
126126
});
127127

128128
// Execute in Loop
129-
let errorHandler = sequences.splice(0, 1)[0]; //Remove error handler
129+
const errorHandler = sequences.splice(0, 1)[0]; //Remove error handler
130130
let sequenceResult: any = null;
131131

132132
loop(sequences, (sequence, clb) => {
133-
let sequenceFunction = function (error: any, result: any): void {
133+
const sequenceFunction = function (error: any, result: any): void {
134134

135135
// A method might only send a boolean value as return value (e.g. fs.exists), support this case gracefully
136136
if (error === true || error === false) {

src/vs/base/node/ports.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as net from 'net';
99
* @returns Returns a random port between 1025 and 65535.
1010
*/
1111
export function randomPort(): number {
12-
let min = 1025;
13-
let max = 65535;
12+
const min = 1025;
13+
const max = 65535;
1414
return min + Math.floor((max - min) * Math.random());
1515
}
1616

src/vs/base/node/processes.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getWindowsCode(status: number): TerminateResponseCode {
4242
export function terminateProcess(process: cp.ChildProcess, cwd?: string): TerminateResponse {
4343
if (Platform.isWindows) {
4444
try {
45-
let options: any = {
45+
const options: any = {
4646
stdio: ['pipe', 'pipe', 'ignore']
4747
};
4848
if (cwd) {
@@ -54,8 +54,8 @@ export function terminateProcess(process: cp.ChildProcess, cwd?: string): Termin
5454
}
5555
} else if (Platform.isLinux || Platform.isMacintosh) {
5656
try {
57-
let cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
58-
let result = cp.spawnSync(cmd, [process.pid.toString()]);
57+
const cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
58+
const result = cp.spawnSync(cmd, [process.pid.toString()]);
5959
if (result.error) {
6060
return { success: false, error: result.error };
6161
}
@@ -113,7 +113,7 @@ export abstract class AbstractProcess<TProgressData> {
113113
this.shell = arg3;
114114
this.options = arg4;
115115
} else {
116-
let executable = <Executable>arg1;
116+
const executable = <Executable>arg1;
117117
this.cmd = executable.command;
118118
this.shell = executable.isShellCommand;
119119
this.args = executable.args.slice(0);
@@ -124,7 +124,7 @@ export abstract class AbstractProcess<TProgressData> {
124124
this.terminateRequested = false;
125125

126126
if (this.options.env) {
127-
let newEnv: IStringDictionary<string> = Object.create(null);
127+
const newEnv: IStringDictionary<string> = Object.create(null);
128128
Object.keys(process.env).forEach((key) => {
129129
newEnv[key] = process.env[key]!;
130130
});
@@ -137,7 +137,7 @@ export abstract class AbstractProcess<TProgressData> {
137137

138138
public getSanitizedCommand(): string {
139139
let result = this.cmd.toLowerCase();
140-
let index = result.lastIndexOf(path.sep);
140+
const index = result.lastIndexOf(path.sep);
141141
if (index !== -1) {
142142
result = result.substring(index + 1);
143143
}
@@ -154,7 +154,7 @@ export abstract class AbstractProcess<TProgressData> {
154154
return this.useExec().then((useExec) => {
155155
let cc: ValueCallback<SuccessData>;
156156
let ee: ErrorCallback;
157-
let result = new Promise<any>((c, e) => {
157+
const result = new Promise<any>((c, e) => {
158158
cc = c;
159159
ee = e;
160160
});
@@ -166,7 +166,7 @@ export abstract class AbstractProcess<TProgressData> {
166166
}
167167
this.childProcess = cp.exec(cmd, this.options, (error, stdout, stderr) => {
168168
this.childProcess = null;
169-
let err: any = error;
169+
const err: any = error;
170170
// This is tricky since executing a command shell reports error back in case the executed command return an
171171
// error or the command didn't exist at all. So we can't blindly treat an error as a failed command. So we
172172
// always parse the output and report success unless the job got killed.
@@ -178,11 +178,11 @@ export abstract class AbstractProcess<TProgressData> {
178178
});
179179
} else {
180180
let childProcess: cp.ChildProcess | null = null;
181-
let closeHandler = (data: any) => {
181+
const closeHandler = (data: any) => {
182182
this.childProcess = null;
183183
this.childProcessPromise = null;
184184
this.handleClose(data, cc, pp, ee);
185-
let result: SuccessData = {
185+
const result: SuccessData = {
186186
terminated: this.terminateRequested
187187
};
188188
if (Types.isNumber(data)) {
@@ -191,12 +191,12 @@ export abstract class AbstractProcess<TProgressData> {
191191
cc(result);
192192
};
193193
if (this.shell && Platform.isWindows) {
194-
let options: any = Objects.deepClone(this.options);
194+
const options: any = Objects.deepClone(this.options);
195195
options.windowsVerbatimArguments = true;
196196
options.detached = false;
197197
let quotedCommand: boolean = false;
198198
let quotedArg: boolean = false;
199-
let commandLine: string[] = [];
199+
const commandLine: string[] = [];
200200
let quoted = this.ensureQuotes(this.cmd);
201201
commandLine.push(quoted.value);
202202
quotedCommand = quoted.quoted;
@@ -207,7 +207,7 @@ export abstract class AbstractProcess<TProgressData> {
207207
quotedArg = quotedArg && quoted.quoted;
208208
});
209209
}
210-
let args: string[] = [
210+
const args: string[] = [
211211
'/s',
212212
'/c',
213213
];
@@ -287,7 +287,7 @@ export abstract class AbstractProcess<TProgressData> {
287287
}
288288
return this.childProcessPromise.then((childProcess) => {
289289
this.terminateRequested = true;
290-
let result = terminateProcess(childProcess, this.options.cwd);
290+
const result = terminateProcess(childProcess, this.options.cwd);
291291
if (result.success) {
292292
this.childProcess = null;
293293
}
@@ -302,7 +302,7 @@ export abstract class AbstractProcess<TProgressData> {
302302
if (!this.shell || !Platform.isWindows) {
303303
return c(false);
304304
}
305-
let cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']);
305+
const cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']);
306306
cmdShell.on('error', (error: Error) => {
307307
return c(true);
308308
});
@@ -326,12 +326,12 @@ export class LineProcess extends AbstractProcess<LineData> {
326326

327327
protected handleExec(cc: ValueCallback<SuccessData>, pp: ProgressCallback<LineData>, error: Error, stdout: Buffer, stderr: Buffer) {
328328
[stdout, stderr].forEach((buffer: Buffer, index: number) => {
329-
let lineDecoder = new LineDecoder();
330-
let lines = lineDecoder.write(buffer);
329+
const lineDecoder = new LineDecoder();
330+
const lines = lineDecoder.write(buffer);
331331
lines.forEach((line) => {
332332
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
333333
});
334-
let line = lineDecoder.end();
334+
const line = lineDecoder.end();
335335
if (line) {
336336
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
337337
}
@@ -343,11 +343,11 @@ export class LineProcess extends AbstractProcess<LineData> {
343343
this.stdoutLineDecoder = new LineDecoder();
344344
this.stderrLineDecoder = new LineDecoder();
345345
childProcess.stdout.on('data', (data: Buffer) => {
346-
let lines = this.stdoutLineDecoder.write(data);
346+
const lines = this.stdoutLineDecoder.write(data);
347347
lines.forEach(line => pp({ line: line, source: Source.stdout }));
348348
});
349349
childProcess.stderr.on('data', (data: Buffer) => {
350-
let lines = this.stderrLineDecoder.write(data);
350+
const lines = this.stderrLineDecoder.write(data);
351351
lines.forEach(line => pp({ line: line, source: Source.stderr }));
352352
});
353353
}
@@ -380,7 +380,7 @@ export function createQueuedSender(childProcess: cp.ChildProcess): IQueuedSender
380380
return;
381381
}
382382

383-
let result = childProcess.send(msg, (error: Error) => {
383+
const result = childProcess.send(msg, (error: Error) => {
384384
if (error) {
385385
console.error(error); // unlikely to happen, best we can do is log this error
386386
}
@@ -412,7 +412,7 @@ export namespace win32 {
412412
if (cwd === undefined) {
413413
cwd = process.cwd();
414414
}
415-
let dir = path.dirname(command);
415+
const dir = path.dirname(command);
416416
if (dir !== '.') {
417417
// We have a directory and the directory is relative (see above). Make the path absolute
418418
// to the current working directory.

src/vs/base/node/ps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
151151
rootItem = processItems.get(rootPid);
152152
if (rootItem) {
153153
processItems.forEach(item => {
154-
let parent = processItems.get(item.ppid);
154+
const parent = processItems.get(item.ppid);
155155
if (parent) {
156156
if (!parent.children) {
157157
parent.children = [];
@@ -186,7 +186,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
186186

187187
const lines = stdout.toString().split('\n');
188188
for (const line of lines) {
189-
let matches = PID_CMD.exec(line.trim());
189+
const matches = PID_CMD.exec(line.trim());
190190
if (matches && matches.length === 6) {
191191
addToTree(parseInt(matches[1]), parseInt(matches[2]), matches[5], parseFloat(matches[3]), parseFloat(matches[4]));
192192
}

src/vs/base/node/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function asText(context: IRequestContext): Promise<string | null> {
152152
return c(null);
153153
}
154154

155-
let buffer: string[] = [];
155+
const buffer: string[] = [];
156156
context.stream.on('data', (d: string) => buffer.push(d));
157157
context.stream.on('end', () => c(buffer.join('')));
158158
context.stream.on('error', e);

src/vs/base/node/stats.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export interface WorkspaceStats {
2121
}
2222

2323
function asSortedItems(map: Map<string, number>): WorkspaceStatItem[] {
24-
let a: WorkspaceStatItem[] = [];
24+
const a: WorkspaceStatItem[] = [];
2525
map.forEach((value, index) => a.push({ name: index, count: value }));
2626
return a.sort((a, b) => b.count - a.count);
2727
}
2828

2929
export function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> {
30-
let launchConfigs = new Map<string, number>();
30+
const launchConfigs = new Map<string, number>();
3131

32-
let launchConfig = join(folder, '.vscode', 'launch.json');
32+
const launchConfig = join(folder, '.vscode', 'launch.json');
3333
return new Promise((resolve, reject) => {
3434
exists(launchConfig, (doesExist) => {
3535
if (doesExist) {
@@ -87,8 +87,8 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
8787
{ 'tag': 'cmake', 'pattern': /^.+\.cmake$/i }
8888
];
8989

90-
let fileTypes = new Map<string, number>();
91-
let configFiles = new Map<string, number>();
90+
const fileTypes = new Map<string, number>();
91+
const configFiles = new Map<string, number>();
9292

9393
const MAX_FILES = 20000;
9494

@@ -149,7 +149,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
149149
});
150150
}
151151

152-
let addFileType = (fileType: string) => {
152+
const addFileType = (fileType: string) => {
153153
if (fileTypes.has(fileType)) {
154154
fileTypes.set(fileType, fileTypes.get(fileType)! + 1);
155155
}
@@ -158,7 +158,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
158158
}
159159
};
160160

161-
let addConfigFiles = (fileName: string) => {
161+
const addConfigFiles = (fileName: string) => {
162162
for (const each of configFilePatterns) {
163163
if (each.pattern.test(fileName)) {
164164
if (configFiles.has(each.tag)) {
@@ -170,23 +170,23 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
170170
}
171171
};
172172

173-
let acceptFile = (name: string) => {
173+
const acceptFile = (name: string) => {
174174
if (name.lastIndexOf('.') >= 0) {
175-
let suffix: string | undefined = name.split('.').pop();
175+
const suffix: string | undefined = name.split('.').pop();
176176
if (suffix) {
177177
addFileType(suffix);
178178
}
179179
}
180180
addConfigFiles(name);
181181
};
182182

183-
let token: { count: number, maxReached: boolean } = { count: 0, maxReached: false };
183+
const token: { count: number, maxReached: boolean } = { count: 0, maxReached: false };
184184

185185
return new Promise((resolve, reject) => {
186186
walk(folder, filter, token, async (files) => {
187187
files.forEach(acceptFile);
188188

189-
let launchConfigs = await collectLaunchConfigs(folder);
189+
const launchConfigs = await collectLaunchConfigs(folder);
190190

191191
resolve({
192192
configFiles: asSortedItems(configFiles),

src/vs/base/node/stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function readToMatchingString(file: string, matchingString: string, chunk
9292
});
9393
}
9494

95-
let buffer = Buffer.allocUnsafe(maximumBytesToRead);
95+
const buffer = Buffer.allocUnsafe(maximumBytesToRead);
9696
let offset = 0;
9797

9898
function readChunk(): void {

src/vs/base/node/zip.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class ExtractError extends Error {
4949
}
5050

5151
function modeFromEntry(entry: Entry) {
52-
let attr = entry.externalFileAttributes >> 16 || 33188;
52+
const attr = entry.externalFileAttributes >> 16 || 33188;
5353

5454
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
5555
.map(mask => attr & mask)

0 commit comments

Comments
 (0)