diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1e2f4fbc91..e7e53c9e7ac 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5019,8 +5019,7 @@ namespace ts { // If this is a JSDoc construct signature, then skip the first parameter in the // parameter list. The first parameter represents the return type of the construct // signature. - const n = declaration.parameters.length; - for (let i = isJSConstructSignature ? 1 : 0; i < n; i++) { + for (let i = isJSConstructSignature ? 1 : 0; i < declaration.parameters.length; i++) { const param = declaration.parameters[i]; let paramSymbol = param.symbol; @@ -5119,8 +5118,7 @@ namespace ts { function getSignaturesOfSymbol(symbol: Symbol): Signature[] { if (!symbol) return emptyArray; const result: Signature[] = []; - const len = symbol.declarations.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < symbol.declarations.length; i++) { const node = symbol.declarations[i]; switch (node.kind) { case SyntaxKind.FunctionType: @@ -7913,8 +7911,7 @@ namespace ts { return Ternary.False; } let result = Ternary.True; - const len = sourceSignatures.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < sourceSignatures.length; i++) { const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, isRelatedTo); if (!related) { return Ternary.False; @@ -18047,8 +18044,7 @@ namespace ts { /** Check each type parameter and check that type parameters have no duplicate type parameter declarations */ function checkTypeParameters(typeParameterDeclarations: TypeParameterDeclaration[]) { if (typeParameterDeclarations) { - const n = typeParameterDeclarations.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < typeParameterDeclarations.length; i++) { const node = typeParameterDeclarations[i]; checkTypeParameter(node); @@ -18328,8 +18324,7 @@ namespace ts { // TypeScript 1.0 spec (April 2014): // When a generic interface has multiple declarations, all declarations must have identical type parameter // lists, i.e. identical type parameter names with identical constraints in identical order. - const len = list1.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < list1.length; i++) { const tp1 = list1[i]; const tp2 = list2[i]; if (tp1.name.text !== tp2.name.text) { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a94b36c602d..2daf5c4e564 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -119,8 +119,7 @@ namespace ts { */ export function forEach(array: T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined { if (array) { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { const result = callback(array[i], i); if (result) { return result; @@ -144,8 +143,7 @@ namespace ts { */ export function every(array: T[], callback: (element: T, index: number) => boolean): boolean { if (array) { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { if (!callback(array[i], i)) { return false; } @@ -157,8 +155,7 @@ namespace ts { /** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */ export function find(array: T[], predicate: (element: T, index: number) => boolean): T | undefined { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { const value = array[i]; if (predicate(value, i)) { return value; @@ -172,8 +169,7 @@ namespace ts { * This is like `forEach`, but never returns undefined. */ export function findMap(array: T[], callback: (element: T, index: number) => U | undefined): U { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { const result = callback(array[i], i); if (result) { return result; @@ -195,8 +191,7 @@ namespace ts { export function indexOf(array: T[], value: T): number { if (array) { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { if (array[i] === value) { return i; } @@ -206,8 +201,7 @@ namespace ts { } export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number { - const len = text.length; - for (let i = start || 0; i < len; i++) { + for (let i = start || 0; i < text.length; i++) { if (contains(charCodes, text.charCodeAt(i))) { return i; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 38e967b86d0..56dd42a1045 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7404,8 +7404,7 @@ namespace ts { if (position >= array.pos && position < array.end) { // position was in this array. Search through this array to see if we find a // viable element. - const n = array.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < array.length; i++) { const child = array[i]; if (child) { if (child.pos === position) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5cf573bae4c..99160a1e5e6 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -696,8 +696,7 @@ namespace ts { } // update fileName -> file mapping - const len = newSourceFiles.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < newSourceFiles.length; i++) { filesByName.set(filePaths[i], newSourceFiles[i]); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 24ee38b5c4d..a2ca6057845 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -766,8 +766,7 @@ namespace ts { return false; } - const n = name.length; - for (let i = 1; i < n; i++) { + for (let i = 1; i < name.length; i++) { if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) { return false; } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 3c4e452095f..4094fc773ea 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -344,8 +344,7 @@ namespace Utils { assert.equal(array1.length, array2.length, "array1.length !== array2.length"); - const n = array1.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < array1.length; i++) { const d1 = array1[i]; const d2 = array2[i]; @@ -401,8 +400,7 @@ namespace Utils { assert.equal(array1.end, array2.end, "array1.end !== array2.end"); assert.equal(array1.length, array2.length, "array1.length !== array2.length"); - const n = array1.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < array1.length; i++) { assertStructuralEquals(array1[i], array2[i]); } } diff --git a/src/harness/unittests/incrementalParser.ts b/src/harness/unittests/incrementalParser.ts index 214ac3a1a58..fbd8a60da92 100644 --- a/src/harness/unittests/incrementalParser.ts +++ b/src/harness/unittests/incrementalParser.ts @@ -28,8 +28,7 @@ namespace ts { const diagnostics2 = file2.parseDiagnostics; assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length"); - const n = diagnostics1.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < diagnostics1.length; i++) { const d1 = diagnostics1[i]; const d2 = diagnostics2[i]; diff --git a/src/harness/unittests/services/patternMatcher.ts b/src/harness/unittests/services/patternMatcher.ts index 3052aa77720..728636e9af2 100644 --- a/src/harness/unittests/services/patternMatcher.ts +++ b/src/harness/unittests/services/patternMatcher.ts @@ -502,8 +502,7 @@ describe("PatternMatcher", function () { function assertArrayEquals(array1: T[], array2: T[]) { assert.equal(array1.length, array2.length); - const n = array1.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < array1.length; i++) { assert.equal(array1[i], array2[i]); } } diff --git a/src/harness/unittests/versionCache.ts b/src/harness/unittests/versionCache.ts index b38ac527f51..17a70f59d59 100644 --- a/src/harness/unittests/versionCache.ts +++ b/src/harness/unittests/versionCache.ts @@ -307,8 +307,7 @@ and grew 1cm per day`; it("Start pos from line", () => { for (let i = 0; i < iterationCount; i++) { - const llen = lines.length; - for (let j = 0; j < llen; j++) { + for (let j = 0; j < lines.length; j++) { const lineInfo = lineIndex.lineNumberToInfo(j + 1); const lineIndexOffset = lineInfo.offset; const lineMapOffset = lineMap[j]; diff --git a/src/server/scriptVersionCache.ts b/src/server/scriptVersionCache.ts index 0365dfd5e41..7f09bcd549b 100644 --- a/src/server/scriptVersionCache.ts +++ b/src/server/scriptVersionCache.ts @@ -113,8 +113,7 @@ namespace ts.server { if (len > 1) { let insertedNodes = new Array(len - 1); let startNode = leafNode; - const n = lines.length - for (let i = 1; i < n; i++) { + for (let i = 1; i < lines.length; i++) { insertedNodes[i - 1] = new LineLeaf(lines[i]); } let pathIndex = this.startPath.length - 2; @@ -470,8 +469,7 @@ namespace ts.server { load(lines: string[]) { if (lines.length > 0) { const leaves: LineLeaf[] = []; - const len = lines.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < lines.length; i++) { leaves[i] = new LineLeaf(lines[i]); } this.root = LineIndex.buildTreeFromBottom(leaves); diff --git a/src/server/server.ts b/src/server/server.ts index 0e6f8a85cf1..e689a2fc782 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -409,8 +409,8 @@ namespace ts.server { function parseLoggingEnvironmentString(logEnvStr: string): LogOptions { const logEnv: LogOptions = { logToFile: true }; const args = logEnvStr.split(" "); - const len = args.length; - for (let i = 0; i < (len - 1); i += 2) { + const len = args.length - 1; + for (let i = 0; i < len; i += 2) { const option = args[i]; const value = args[i + 1]; if (option && value) { diff --git a/src/services/classifier.ts b/src/services/classifier.ts index 249511e2aad..e8a29977802 100644 --- a/src/services/classifier.ts +++ b/src/services/classifier.ts @@ -71,8 +71,7 @@ namespace ts { const dense = classifications.spans; let lastEnd = 0; - const n = dense.length; - for (let i = 0; i < n; i += 3) { + for (let i = 0; i < dense.length; i += 3) { const start = dense[i]; const length = dense[i + 1]; const type = dense[i + 2]; @@ -607,8 +606,7 @@ namespace ts { const dense = classifications.spans; const result: ClassifiedSpan[] = []; - const n = dense.length; - for (let i = 0; i < n; i += 3) { + for (let i = 0; i < dense.length; i += 3) { result.push({ textSpan: createTextSpan(dense[i], dense[i + 1]), classificationType: getClassificationTypeName(dense[i + 2]) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 5d7dc665790..ba47c420817 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -950,8 +950,7 @@ namespace ts.formatting { // shift all parts on the delta size const delta = indentation - nonWhitespaceColumnInFirstPart.column; - const len = parts.length; - for (let i = startIndex; i < len; i++ , startLine++) { + for (let i = startIndex; i < parts.length; i++ , startLine++) { const startLinePos = getStartPositionOfLine(startLine, sourceFile); const nonWhitespaceCharacterAndColumn = i === 0 diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 2f08af3127a..08a51a63e63 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -76,8 +76,7 @@ namespace ts.JsDoc { */ function forEachUnique(array: T[], callback: (element: T, index: number) => U): U { if (array) { - const len = array.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < array.length; i++) { if (indexOf(array, array[i]) === i) { const result = callback(array[i], i); if (result) { @@ -171,8 +170,7 @@ namespace ts.JsDoc { const isJavaScriptFile = hasJavaScriptFileExtension(sourceFile.fileName); let docParams = ""; - const numParams = parameters.length; - for (let i = 0; i < numParams; i++) { + for (let i = 0; i < parameters.length; i++) { const currentName = parameters[i].name; const paramName = currentName.kind === SyntaxKind.Identifier ? (currentName).text : diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index d07e9191309..ad638099695 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -528,8 +528,7 @@ namespace ts { // Assumes 'value' is already lowercase. function startsWithIgnoringCase(string: string, value: string, start: number): boolean { - const n = value.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < value.length; i++) { const ch1 = toLowerCase(string.charCodeAt(i + start)); const ch2 = value.charCodeAt(i); @@ -615,8 +614,7 @@ namespace ts { const result: TextSpan[] = []; let wordStart = 0; - const n = identifier.length; - for (let i = 1; i < n; i++) { + for (let i = 1; i < identifier.length; i++) { const lastIsDigit = isDigit(identifier.charCodeAt(i - 1)); const currentIsDigit = isDigit(identifier.charCodeAt(i)); diff --git a/src/services/services.ts b/src/services/services.ts index 43903cec1ff..4ca983529be 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1793,8 +1793,7 @@ namespace ts { } let descriptor: TodoCommentDescriptor = undefined; - const n = descriptors.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < descriptors.length; i++) { if (matchArray[i + firstDescriptorCaptureIndex]) { descriptor = descriptors[i]; } diff --git a/src/services/shims.ts b/src/services/shims.ts index bd13843f751..cf6bceb816c 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -1239,8 +1239,7 @@ namespace ts { } public unregisterShim(shim: Shim): void { - const n = this._shims.length; - for (let i = 0; i < n; i++) { + for (let i = 0; i < this._shims.length; i++) { if (this._shims[i] === shim) { delete this._shims[i]; return; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index d3354dc5466..c66ff6a8059 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -765,8 +765,7 @@ namespace ts { } const children = n.getChildren(); - const len = children.length; - for (let i = 0; i < len; i++) { + for (let i = 0; i < children.length; i++) { const child = children[i]; // condition 'position < child.end' checks if child node end after the position // in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc'