diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index dd12b452b57..b20d8fea22d 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -609,8 +609,8 @@ module ts.formatting { } var inheritedIndentation = Constants.Unknown; - for (var i = 0, len = nodes.length; i < len; ++i) { - inheritedIndentation = processChildNode(nodes[i], inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true) + for (let child of nodes) { + inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true) } if (listEndToken !== SyntaxKind.Unknown) { @@ -668,8 +668,7 @@ module ts.formatting { if (indentToken) { var indentNextTokenOrTrivia = true; if (currentTokenInfo.leadingTrivia) { - for (var i = 0, len = currentTokenInfo.leadingTrivia.length; i < len; ++i) { - var triviaItem = currentTokenInfo.leadingTrivia[i]; + for (let triviaItem of currentTokenInfo.leadingTrivia) { if (!rangeContainsRange(originalRange, triviaItem)) { continue; } @@ -709,8 +708,7 @@ module ts.formatting { } function processTrivia(trivia: TextRangeWithKind[], parent: Node, contextNode: Node, dynamicIndentation: DynamicIndentation): void { - for (var i = 0, len = trivia.length; i < len; ++i) { - var triviaItem = trivia[i]; + for (let triviaItem of trivia) { if (isComment(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) { var triviaItemStart = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos); processRange(triviaItem, triviaItemStart, parent, contextNode, dynamicIndentation); diff --git a/src/services/formatting/ruleOperationContext.ts b/src/services/formatting/ruleOperationContext.ts index d037f8e70d7..dc4e5d4f105 100644 --- a/src/services/formatting/ruleOperationContext.ts +++ b/src/services/formatting/ruleOperationContext.ts @@ -36,8 +36,8 @@ module ts.formatting { return true; } - for (var i = 0, len = this.customContextChecks.length; i < len; i++) { - if (!this.customContextChecks[i](context)) { + for (let check of this.customContextChecks) { + if (!check(context)) { return false; } } diff --git a/src/services/formatting/rulesMap.ts b/src/services/formatting/rulesMap.ts index d25320f16a8..634ec61de9c 100644 --- a/src/services/formatting/rulesMap.ts +++ b/src/services/formatting/rulesMap.ts @@ -76,10 +76,10 @@ module ts.formatting { var bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind); var bucket = this.map[bucketIndex]; if (bucket != null) { - for (var i = 0, len = bucket.Rules().length; i < len; i++) { - var rule = bucket.Rules()[i]; - if (rule.Operation.Context.InContext(context)) + for (let rule of bucket.Rules()) { + if (rule.Operation.Context.InContext(context)) { return rule; + } } } return null; diff --git a/src/services/navigateTo.ts b/src/services/navigateTo.ts index b3f72d83cb3..7757a7acf3a 100644 --- a/src/services/navigateTo.ts +++ b/src/services/navigateTo.ts @@ -10,8 +10,7 @@ module ts.NavigateTo { cancellationToken.throwIfCancellationRequested(); var declarations = sourceFile.getNamedDeclarations(); - for (var i = 0, n = declarations.length; i < n; i++) { - var declaration = declarations[i]; + for (let declaration of declarations) { var name = getDeclarationName(declaration); if (name !== undefined) { @@ -58,8 +57,8 @@ module ts.NavigateTo { Debug.assert(matches.length > 0); // This is a case sensitive match, only if all the submatches were case sensitive. - for (var i = 0, n = matches.length; i < n; i++) { - if (!matches[i].isCaseSensitive) { + for (let match of matches) { + if (!match.isCaseSensitive) { return false; } } @@ -167,8 +166,8 @@ module ts.NavigateTo { Debug.assert(matches.length > 0); var bestMatchKind = PatternMatchKind.camelCase; - for (var i = 0, n = matches.length; i < n; i++) { - var kind = matches[i].kind; + for (let match of matches) { + var kind = match.kind; if (kind < bestMatchKind) { bestMatchKind = kind; } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 20e80cc88c0..1f67fef5e71 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -150,8 +150,7 @@ module ts.NavigationBar { function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void { nodes = sortNodes(nodes); - for (var i = 0, n = nodes.length; i < n; i++) { - var node = nodes[i]; + for (let node of nodes) { switch (node.kind) { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: @@ -204,8 +203,7 @@ module ts.NavigationBar { var keyToItem: Map = {}; - for (var i = 0, n = nodes.length; i < n; i++) { - var child = nodes[i]; + for (let child of nodes) { var item = createItem(child); if (item !== undefined) { if (item.text.length > 0) { @@ -238,12 +236,8 @@ module ts.NavigationBar { // Next, recursively merge or add any children in the source as appropriate. outer: - for (var i = 0, n = source.childItems.length; i < n; i++) { - var sourceChild = source.childItems[i]; - - for (var j = 0, m = target.childItems.length; j < m; j++) { - var targetChild = target.childItems[j]; - + for (let sourceChild of source.childItems) { + for (let targetChild of target.childItems) { if (targetChild.text === sourceChild.text && targetChild.kind === sourceChild.kind) { // Found a match. merge them. merge(targetChild, sourceChild); diff --git a/src/services/patternMatcher.ts b/src/services/patternMatcher.ts index 9bcd3e1d000..f7874519334 100644 --- a/src/services/patternMatcher.ts +++ b/src/services/patternMatcher.ts @@ -221,8 +221,7 @@ module ts { // word part. That way we don't match something like 'Class' when the user types 'a'. // But we would match 'FooAttribute' (since 'Attribute' starts with 'a'). var wordSpans = getWordSpans(candidate); - for (var i = 0, n = wordSpans.length; i < n; i++) { - var span = wordSpans[i] + for (let span of wordSpans) { if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) { return createPatternMatch(PatternMatchKind.substring, punctuationStripped, /*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false)); @@ -339,9 +338,7 @@ module ts { var subWordTextChunks = segment.subWordTextChunks; var matches: PatternMatch[] = undefined; - for (var i = 0, n = subWordTextChunks.length; i < n; i++) { - var subWordTextChunk = subWordTextChunks[i]; - + for (let subWordTextChunk of subWordTextChunks) { // Try to match the candidate with this word var result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true); if (!result) { diff --git a/src/services/services.ts b/src/services/services.ts index 61d7a0736b0..f0e934ed6a2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -196,8 +196,7 @@ module ts { var list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this); list._children = []; var pos = nodes.pos; - for (var i = 0, len = nodes.length; i < len; i++) { - var node = nodes[i]; + for (let node of nodes) { if (pos < node.pos) { pos = this.addSyntheticNodes(list._children, pos, node.pos); } @@ -255,8 +254,7 @@ module ts { public getFirstToken(sourceFile?: SourceFile): Node { var children = this.getChildren(); - for (var i = 0; i < children.length; i++) { - var child = children[i]; + for (let child of children) { if (child.kind < SyntaxKind.FirstNode) { return child; } @@ -1523,8 +1521,8 @@ module ts { // Initialize the list with the root file names var rootFileNames = host.getScriptFileNames(); - for (var i = 0, n = rootFileNames.length; i < n; i++) { - this.createEntry(rootFileNames[i]); + for (let fileName of rootFileNames) { + this.createEntry(fileName); } // store the compilation settings @@ -2252,8 +2250,8 @@ module ts { // not part of the new program. if (program) { var oldSourceFiles = program.getSourceFiles(); - for (var i = 0, n = oldSourceFiles.length; i < n; i++) { - var fileName = oldSourceFiles[i].fileName; + for (let oldSourceFile of oldSourceFiles) { + var fileName = oldSourceFile.fileName; if (!newProgram.getSourceFile(fileName) || changesInCompilationSettingsAffectSyntax) { documentRegistry.releaseDocument(fileName, oldSettings); } @@ -2329,8 +2327,8 @@ module ts { } // If any file is not up-to-date, then the whole program is not up-to-date - for (var i = 0, n = rootFileNames.length; i < n; i++) { - if (!sourceFileUpToDate(program.getSourceFile(rootFileNames[i]))) { + for (let fileName of rootFileNames) { + if (!sourceFileUpToDate(program.getSourceFile(fileName))) { return false; } } @@ -4314,8 +4312,8 @@ module ts { var declarations = symbol.getDeclarations(); if (declarations) { - for (var i = 0, n = declarations.length; i < n; i++) { - var container = getContainerNode(declarations[i]); + for (let declaration of declarations) { + var container = getContainerNode(declaration); if (!container) { return undefined; @@ -4831,8 +4829,8 @@ module ts { // Remember the last meaning var lastIterationMeaning = meaning; - for (var i = 0, n = declarations.length; i < n; i++) { - var declarationMeaning = getMeaningFromDeclaration(declarations[i]); + for (let declaration of declarations) { + var declarationMeaning = getMeaningFromDeclaration(declaration); if (declarationMeaning & meaning) { meaning |= declarationMeaning; @@ -5401,8 +5399,7 @@ module ts { // Ignore nodes that don't intersect the original span to classify. if (textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { var children = element.getChildren(); - for (var i = 0, n = children.length; i < n; i++) { - var child = children[i]; + for (let child of children) { if (isToken(child)) { classifyToken(child); } @@ -5435,9 +5432,7 @@ module ts { var parentElement = token.parent; var childNodes = parentElement.getChildren(sourceFile); - for (var i = 0, n = childNodes.length; i < n; i++) { - var current = childNodes[i]; - + for (let current of childNodes) { if (current.kind === matchKind) { var range1 = createTextSpan(token.getStart(sourceFile), token.getWidth(sourceFile)); var range2 = createTextSpan(current.getStart(sourceFile), current.getWidth(sourceFile)); diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 52a7b41d8a7..3a677c9506c 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -318,8 +318,7 @@ module ts.SignatureHelp { // arg index. var argumentIndex = 0; var listChildren = argumentsList.getChildren(); - for (var i = 0, n = listChildren.length; i < n; i++) { - var child = listChildren[i]; + for (let child of listChildren) { if (child === node) { break; } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index f2403217c24..332ddffc910 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -184,8 +184,7 @@ module ts { } var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; + for (let child of children) { var shouldDiveInChildNode = // previous token is enclosed somewhere in the child (child.pos <= previousToken.pos && child.end > previousToken.end) || @@ -221,8 +220,8 @@ module ts { } var children = n.getChildren(); - for (var i = 0, len = children.length; i < len; ++i) { - var child = children[i]; + for (var i = 0, len = children.length; i < len; i++) { + let child = children[i]; if (nodeHasTokens(child)) { if (position <= child.end) { if (child.getStart(sourceFile) >= position) {