Auto convert let -> const in base/node

This commit is contained in:
Matt Bierner
2019-03-05 16:53:02 -08:00
parent 3f93ea6521
commit 608fc2cee2
9 changed files with 49 additions and 49 deletions

View File

@@ -24,8 +24,8 @@ export class LineDecoder {
} }
public write(buffer: Buffer): string[] { public write(buffer: Buffer): string[] {
let result: string[] = []; const result: string[] = [];
let value = this.remaining const value = this.remaining
? this.remaining + this.stringDecoder.write(buffer) ? this.remaining + this.stringDecoder.write(buffer)
: this.stringDecoder.write(buffer); : this.stringDecoder.write(buffer);
@@ -41,7 +41,7 @@ export class LineDecoder {
result.push(value.substring(start, idx)); result.push(value.substring(start, idx));
idx++; idx++;
if (idx < value.length) { if (idx < value.length) {
let lastChar = ch; const lastChar = ch;
ch = value.charCodeAt(idx); ch = value.charCodeAt(idx);
if ((lastChar === CharCode.CarriageReturn && ch === CharCode.LineFeed) || (lastChar === CharCode.LineFeed && ch === CharCode.CarriageReturn)) { if ((lastChar === CharCode.CarriageReturn && ch === CharCode.LineFeed) || (lastChar === CharCode.LineFeed && ch === CharCode.CarriageReturn)) {
idx++; idx++;

View File

@@ -10,8 +10,8 @@ import * as assert from 'assert';
* array to the callback (callback). The resulting errors and results are evaluated by calling the provided callback function. * array to the callback (callback). The resulting errors and results are evaluated by calling the provided callback function.
*/ */
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 { 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 {
let results = new Array(list.length); const results = new Array(list.length);
let errors = new Array<Error | null>(list.length); const errors = new Array<Error | null>(list.length);
let didErrorOccur = false; let didErrorOccur = false;
let doneCount = 0; let doneCount = 0;
@@ -68,9 +68,9 @@ export function loop<E>(param: any, fn: (item: any, callback: (error: Error | nu
// Expect the param to be an array and loop over it // Expect the param to be an array and loop over it
else { else {
let results: E[] = []; const results: E[] = [];
let looper: (i: number) => void = function (i: number): void { const looper: (i: number) => void = function (i: number): void {
// Still work to do // Still work to do
if (i < param.length) { if (i < param.length) {
@@ -126,11 +126,11 @@ function Sequence(sequences: { (...param: any[]): void; }[]): void {
}); });
// Execute in Loop // Execute in Loop
let errorHandler = sequences.splice(0, 1)[0]; //Remove error handler const errorHandler = sequences.splice(0, 1)[0]; //Remove error handler
let sequenceResult: any = null; let sequenceResult: any = null;
loop(sequences, (sequence, clb) => { loop(sequences, (sequence, clb) => {
let sequenceFunction = function (error: any, result: any): void { const sequenceFunction = function (error: any, result: any): void {
// A method might only send a boolean value as return value (e.g. fs.exists), support this case gracefully // A method might only send a boolean value as return value (e.g. fs.exists), support this case gracefully
if (error === true || error === false) { if (error === true || error === false) {

View File

@@ -9,8 +9,8 @@ import * as net from 'net';
* @returns Returns a random port between 1025 and 65535. * @returns Returns a random port between 1025 and 65535.
*/ */
export function randomPort(): number { export function randomPort(): number {
let min = 1025; const min = 1025;
let max = 65535; const max = 65535;
return min + Math.floor((max - min) * Math.random()); return min + Math.floor((max - min) * Math.random());
} }

View File

@@ -42,7 +42,7 @@ function getWindowsCode(status: number): TerminateResponseCode {
export function terminateProcess(process: cp.ChildProcess, cwd?: string): TerminateResponse { export function terminateProcess(process: cp.ChildProcess, cwd?: string): TerminateResponse {
if (Platform.isWindows) { if (Platform.isWindows) {
try { try {
let options: any = { const options: any = {
stdio: ['pipe', 'pipe', 'ignore'] stdio: ['pipe', 'pipe', 'ignore']
}; };
if (cwd) { if (cwd) {
@@ -54,8 +54,8 @@ export function terminateProcess(process: cp.ChildProcess, cwd?: string): Termin
} }
} else if (Platform.isLinux || Platform.isMacintosh) { } else if (Platform.isLinux || Platform.isMacintosh) {
try { try {
let cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh'); const cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
let result = cp.spawnSync(cmd, [process.pid.toString()]); const result = cp.spawnSync(cmd, [process.pid.toString()]);
if (result.error) { if (result.error) {
return { success: false, error: result.error }; return { success: false, error: result.error };
} }
@@ -113,7 +113,7 @@ export abstract class AbstractProcess<TProgressData> {
this.shell = arg3; this.shell = arg3;
this.options = arg4; this.options = arg4;
} else { } else {
let executable = <Executable>arg1; const executable = <Executable>arg1;
this.cmd = executable.command; this.cmd = executable.command;
this.shell = executable.isShellCommand; this.shell = executable.isShellCommand;
this.args = executable.args.slice(0); this.args = executable.args.slice(0);
@@ -124,7 +124,7 @@ export abstract class AbstractProcess<TProgressData> {
this.terminateRequested = false; this.terminateRequested = false;
if (this.options.env) { if (this.options.env) {
let newEnv: IStringDictionary<string> = Object.create(null); const newEnv: IStringDictionary<string> = Object.create(null);
Object.keys(process.env).forEach((key) => { Object.keys(process.env).forEach((key) => {
newEnv[key] = process.env[key]!; newEnv[key] = process.env[key]!;
}); });
@@ -137,7 +137,7 @@ export abstract class AbstractProcess<TProgressData> {
public getSanitizedCommand(): string { public getSanitizedCommand(): string {
let result = this.cmd.toLowerCase(); let result = this.cmd.toLowerCase();
let index = result.lastIndexOf(path.sep); const index = result.lastIndexOf(path.sep);
if (index !== -1) { if (index !== -1) {
result = result.substring(index + 1); result = result.substring(index + 1);
} }
@@ -154,7 +154,7 @@ export abstract class AbstractProcess<TProgressData> {
return this.useExec().then((useExec) => { return this.useExec().then((useExec) => {
let cc: ValueCallback<SuccessData>; let cc: ValueCallback<SuccessData>;
let ee: ErrorCallback; let ee: ErrorCallback;
let result = new Promise<any>((c, e) => { const result = new Promise<any>((c, e) => {
cc = c; cc = c;
ee = e; ee = e;
}); });
@@ -166,7 +166,7 @@ export abstract class AbstractProcess<TProgressData> {
} }
this.childProcess = cp.exec(cmd, this.options, (error, stdout, stderr) => { this.childProcess = cp.exec(cmd, this.options, (error, stdout, stderr) => {
this.childProcess = null; this.childProcess = null;
let err: any = error; const err: any = error;
// This is tricky since executing a command shell reports error back in case the executed command return an // This is tricky since executing a command shell reports error back in case the executed command return an
// error or the command didn't exist at all. So we can't blindly treat an error as a failed command. So we // error or the command didn't exist at all. So we can't blindly treat an error as a failed command. So we
// always parse the output and report success unless the job got killed. // always parse the output and report success unless the job got killed.
@@ -178,11 +178,11 @@ export abstract class AbstractProcess<TProgressData> {
}); });
} else { } else {
let childProcess: cp.ChildProcess | null = null; let childProcess: cp.ChildProcess | null = null;
let closeHandler = (data: any) => { const closeHandler = (data: any) => {
this.childProcess = null; this.childProcess = null;
this.childProcessPromise = null; this.childProcessPromise = null;
this.handleClose(data, cc, pp, ee); this.handleClose(data, cc, pp, ee);
let result: SuccessData = { const result: SuccessData = {
terminated: this.terminateRequested terminated: this.terminateRequested
}; };
if (Types.isNumber(data)) { if (Types.isNumber(data)) {
@@ -191,12 +191,12 @@ export abstract class AbstractProcess<TProgressData> {
cc(result); cc(result);
}; };
if (this.shell && Platform.isWindows) { if (this.shell && Platform.isWindows) {
let options: any = Objects.deepClone(this.options); const options: any = Objects.deepClone(this.options);
options.windowsVerbatimArguments = true; options.windowsVerbatimArguments = true;
options.detached = false; options.detached = false;
let quotedCommand: boolean = false; let quotedCommand: boolean = false;
let quotedArg: boolean = false; let quotedArg: boolean = false;
let commandLine: string[] = []; const commandLine: string[] = [];
let quoted = this.ensureQuotes(this.cmd); let quoted = this.ensureQuotes(this.cmd);
commandLine.push(quoted.value); commandLine.push(quoted.value);
quotedCommand = quoted.quoted; quotedCommand = quoted.quoted;
@@ -207,7 +207,7 @@ export abstract class AbstractProcess<TProgressData> {
quotedArg = quotedArg && quoted.quoted; quotedArg = quotedArg && quoted.quoted;
}); });
} }
let args: string[] = [ const args: string[] = [
'/s', '/s',
'/c', '/c',
]; ];
@@ -287,7 +287,7 @@ export abstract class AbstractProcess<TProgressData> {
} }
return this.childProcessPromise.then((childProcess) => { return this.childProcessPromise.then((childProcess) => {
this.terminateRequested = true; this.terminateRequested = true;
let result = terminateProcess(childProcess, this.options.cwd); const result = terminateProcess(childProcess, this.options.cwd);
if (result.success) { if (result.success) {
this.childProcess = null; this.childProcess = null;
} }
@@ -302,7 +302,7 @@ export abstract class AbstractProcess<TProgressData> {
if (!this.shell || !Platform.isWindows) { if (!this.shell || !Platform.isWindows) {
return c(false); return c(false);
} }
let cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']); const cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']);
cmdShell.on('error', (error: Error) => { cmdShell.on('error', (error: Error) => {
return c(true); return c(true);
}); });
@@ -326,12 +326,12 @@ export class LineProcess extends AbstractProcess<LineData> {
protected handleExec(cc: ValueCallback<SuccessData>, pp: ProgressCallback<LineData>, error: Error, stdout: Buffer, stderr: Buffer) { protected handleExec(cc: ValueCallback<SuccessData>, pp: ProgressCallback<LineData>, error: Error, stdout: Buffer, stderr: Buffer) {
[stdout, stderr].forEach((buffer: Buffer, index: number) => { [stdout, stderr].forEach((buffer: Buffer, index: number) => {
let lineDecoder = new LineDecoder(); const lineDecoder = new LineDecoder();
let lines = lineDecoder.write(buffer); const lines = lineDecoder.write(buffer);
lines.forEach((line) => { lines.forEach((line) => {
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr }); pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
}); });
let line = lineDecoder.end(); const line = lineDecoder.end();
if (line) { if (line) {
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr }); pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
} }
@@ -343,11 +343,11 @@ export class LineProcess extends AbstractProcess<LineData> {
this.stdoutLineDecoder = new LineDecoder(); this.stdoutLineDecoder = new LineDecoder();
this.stderrLineDecoder = new LineDecoder(); this.stderrLineDecoder = new LineDecoder();
childProcess.stdout.on('data', (data: Buffer) => { childProcess.stdout.on('data', (data: Buffer) => {
let lines = this.stdoutLineDecoder.write(data); const lines = this.stdoutLineDecoder.write(data);
lines.forEach(line => pp({ line: line, source: Source.stdout })); lines.forEach(line => pp({ line: line, source: Source.stdout }));
}); });
childProcess.stderr.on('data', (data: Buffer) => { childProcess.stderr.on('data', (data: Buffer) => {
let lines = this.stderrLineDecoder.write(data); const lines = this.stderrLineDecoder.write(data);
lines.forEach(line => pp({ line: line, source: Source.stderr })); lines.forEach(line => pp({ line: line, source: Source.stderr }));
}); });
} }
@@ -380,7 +380,7 @@ export function createQueuedSender(childProcess: cp.ChildProcess): IQueuedSender
return; return;
} }
let result = childProcess.send(msg, (error: Error) => { const result = childProcess.send(msg, (error: Error) => {
if (error) { if (error) {
console.error(error); // unlikely to happen, best we can do is log this error console.error(error); // unlikely to happen, best we can do is log this error
} }
@@ -412,7 +412,7 @@ export namespace win32 {
if (cwd === undefined) { if (cwd === undefined) {
cwd = process.cwd(); cwd = process.cwd();
} }
let dir = path.dirname(command); const dir = path.dirname(command);
if (dir !== '.') { if (dir !== '.') {
// We have a directory and the directory is relative (see above). Make the path absolute // We have a directory and the directory is relative (see above). Make the path absolute
// to the current working directory. // to the current working directory.

View File

@@ -151,7 +151,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
rootItem = processItems.get(rootPid); rootItem = processItems.get(rootPid);
if (rootItem) { if (rootItem) {
processItems.forEach(item => { processItems.forEach(item => {
let parent = processItems.get(item.ppid); const parent = processItems.get(item.ppid);
if (parent) { if (parent) {
if (!parent.children) { if (!parent.children) {
parent.children = []; parent.children = [];
@@ -186,7 +186,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
const lines = stdout.toString().split('\n'); const lines = stdout.toString().split('\n');
for (const line of lines) { for (const line of lines) {
let matches = PID_CMD.exec(line.trim()); const matches = PID_CMD.exec(line.trim());
if (matches && matches.length === 6) { if (matches && matches.length === 6) {
addToTree(parseInt(matches[1]), parseInt(matches[2]), matches[5], parseFloat(matches[3]), parseFloat(matches[4])); addToTree(parseInt(matches[1]), parseInt(matches[2]), matches[5], parseFloat(matches[3]), parseFloat(matches[4]));
} }

View File

@@ -152,7 +152,7 @@ export function asText(context: IRequestContext): Promise<string | null> {
return c(null); return c(null);
} }
let buffer: string[] = []; const buffer: string[] = [];
context.stream.on('data', (d: string) => buffer.push(d)); context.stream.on('data', (d: string) => buffer.push(d));
context.stream.on('end', () => c(buffer.join(''))); context.stream.on('end', () => c(buffer.join('')));
context.stream.on('error', e); context.stream.on('error', e);

View File

@@ -21,15 +21,15 @@ export interface WorkspaceStats {
} }
function asSortedItems(map: Map<string, number>): WorkspaceStatItem[] { function asSortedItems(map: Map<string, number>): WorkspaceStatItem[] {
let a: WorkspaceStatItem[] = []; const a: WorkspaceStatItem[] = [];
map.forEach((value, index) => a.push({ name: index, count: value })); map.forEach((value, index) => a.push({ name: index, count: value }));
return a.sort((a, b) => b.count - a.count); return a.sort((a, b) => b.count - a.count);
} }
export function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> { export function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> {
let launchConfigs = new Map<string, number>(); const launchConfigs = new Map<string, number>();
let launchConfig = join(folder, '.vscode', 'launch.json'); const launchConfig = join(folder, '.vscode', 'launch.json');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exists(launchConfig, (doesExist) => { exists(launchConfig, (doesExist) => {
if (doesExist) { if (doesExist) {
@@ -87,8 +87,8 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
{ 'tag': 'cmake', 'pattern': /^.+\.cmake$/i } { 'tag': 'cmake', 'pattern': /^.+\.cmake$/i }
]; ];
let fileTypes = new Map<string, number>(); const fileTypes = new Map<string, number>();
let configFiles = new Map<string, number>(); const configFiles = new Map<string, number>();
const MAX_FILES = 20000; const MAX_FILES = 20000;
@@ -149,7 +149,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
}); });
} }
let addFileType = (fileType: string) => { const addFileType = (fileType: string) => {
if (fileTypes.has(fileType)) { if (fileTypes.has(fileType)) {
fileTypes.set(fileType, fileTypes.get(fileType)! + 1); fileTypes.set(fileType, fileTypes.get(fileType)! + 1);
} }
@@ -158,7 +158,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
} }
}; };
let addConfigFiles = (fileName: string) => { const addConfigFiles = (fileName: string) => {
for (const each of configFilePatterns) { for (const each of configFilePatterns) {
if (each.pattern.test(fileName)) { if (each.pattern.test(fileName)) {
if (configFiles.has(each.tag)) { if (configFiles.has(each.tag)) {
@@ -170,9 +170,9 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
} }
}; };
let acceptFile = (name: string) => { const acceptFile = (name: string) => {
if (name.lastIndexOf('.') >= 0) { if (name.lastIndexOf('.') >= 0) {
let suffix: string | undefined = name.split('.').pop(); const suffix: string | undefined = name.split('.').pop();
if (suffix) { if (suffix) {
addFileType(suffix); addFileType(suffix);
} }
@@ -180,13 +180,13 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
addConfigFiles(name); addConfigFiles(name);
}; };
let token: { count: number, maxReached: boolean } = { count: 0, maxReached: false }; const token: { count: number, maxReached: boolean } = { count: 0, maxReached: false };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
walk(folder, filter, token, async (files) => { walk(folder, filter, token, async (files) => {
files.forEach(acceptFile); files.forEach(acceptFile);
let launchConfigs = await collectLaunchConfigs(folder); const launchConfigs = await collectLaunchConfigs(folder);
resolve({ resolve({
configFiles: asSortedItems(configFiles), configFiles: asSortedItems(configFiles),

View File

@@ -92,7 +92,7 @@ export function readToMatchingString(file: string, matchingString: string, chunk
}); });
} }
let buffer = Buffer.allocUnsafe(maximumBytesToRead); const buffer = Buffer.allocUnsafe(maximumBytesToRead);
let offset = 0; let offset = 0;
function readChunk(): void { function readChunk(): void {

View File

@@ -49,7 +49,7 @@ export class ExtractError extends Error {
} }
function modeFromEntry(entry: Entry) { function modeFromEntry(entry: Entry) {
let attr = entry.externalFileAttributes >> 16 || 33188; const attr = entry.externalFileAttributes >> 16 || 33188;
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */] return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
.map(mask => attr & mask) .map(mask => attr & mask)