Skip to content

Commit 224de1d

Browse files
use for-of in more places.
1 parent a6a6a0e commit 224de1d

9 files changed

Lines changed: 38 additions & 57 deletions

File tree

src/services/formatting/formatting.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ module ts.formatting {
609609
}
610610

611611
var inheritedIndentation = Constants.Unknown;
612-
for (var i = 0, len = nodes.length; i < len; ++i) {
613-
inheritedIndentation = processChildNode(nodes[i], inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true)
612+
for (let child of nodes) {
613+
inheritedIndentation = processChildNode(child, inheritedIndentation, node, listDynamicIndentation, startLine, /*isListElement*/ true)
614614
}
615615

616616
if (listEndToken !== SyntaxKind.Unknown) {
@@ -668,8 +668,7 @@ module ts.formatting {
668668
if (indentToken) {
669669
var indentNextTokenOrTrivia = true;
670670
if (currentTokenInfo.leadingTrivia) {
671-
for (var i = 0, len = currentTokenInfo.leadingTrivia.length; i < len; ++i) {
672-
var triviaItem = currentTokenInfo.leadingTrivia[i];
671+
for (let triviaItem of currentTokenInfo.leadingTrivia) {
673672
if (!rangeContainsRange(originalRange, triviaItem)) {
674673
continue;
675674
}
@@ -709,8 +708,7 @@ module ts.formatting {
709708
}
710709

711710
function processTrivia(trivia: TextRangeWithKind[], parent: Node, contextNode: Node, dynamicIndentation: DynamicIndentation): void {
712-
for (var i = 0, len = trivia.length; i < len; ++i) {
713-
var triviaItem = trivia[i];
711+
for (let triviaItem of trivia) {
714712
if (isComment(triviaItem.kind) && rangeContainsRange(originalRange, triviaItem)) {
715713
var triviaItemStart = sourceFile.getLineAndCharacterOfPosition(triviaItem.pos);
716714
processRange(triviaItem, triviaItemStart, parent, contextNode, dynamicIndentation);

src/services/formatting/ruleOperationContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module ts.formatting {
3636
return true;
3737
}
3838

39-
for (var i = 0, len = this.customContextChecks.length; i < len; i++) {
40-
if (!this.customContextChecks[i](context)) {
39+
for (let check of this.customContextChecks) {
40+
if (!check(context)) {
4141
return false;
4242
}
4343
}

src/services/formatting/rulesMap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ module ts.formatting {
7676
var bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind);
7777
var bucket = this.map[bucketIndex];
7878
if (bucket != null) {
79-
for (var i = 0, len = bucket.Rules().length; i < len; i++) {
80-
var rule = bucket.Rules()[i];
81-
if (rule.Operation.Context.InContext(context))
79+
for (let rule of bucket.Rules()) {
80+
if (rule.Operation.Context.InContext(context)) {
8281
return rule;
82+
}
8383
}
8484
}
8585
return null;

src/services/navigateTo.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ module ts.NavigateTo {
1010
cancellationToken.throwIfCancellationRequested();
1111

1212
var declarations = sourceFile.getNamedDeclarations();
13-
for (var i = 0, n = declarations.length; i < n; i++) {
14-
var declaration = declarations[i];
13+
for (let declaration of declarations) {
1514
var name = getDeclarationName(declaration);
1615
if (name !== undefined) {
1716

@@ -58,8 +57,8 @@ module ts.NavigateTo {
5857
Debug.assert(matches.length > 0);
5958

6059
// This is a case sensitive match, only if all the submatches were case sensitive.
61-
for (var i = 0, n = matches.length; i < n; i++) {
62-
if (!matches[i].isCaseSensitive) {
60+
for (let match of matches) {
61+
if (!match.isCaseSensitive) {
6362
return false;
6463
}
6564
}
@@ -167,8 +166,8 @@ module ts.NavigateTo {
167166
Debug.assert(matches.length > 0);
168167
var bestMatchKind = PatternMatchKind.camelCase;
169168

170-
for (var i = 0, n = matches.length; i < n; i++) {
171-
var kind = matches[i].kind;
169+
for (let match of matches) {
170+
var kind = match.kind;
172171
if (kind < bestMatchKind) {
173172
bestMatchKind = kind;
174173
}

src/services/navigationBar.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ module ts.NavigationBar {
150150
function addTopLevelNodes(nodes: Node[], topLevelNodes: Node[]): void {
151151
nodes = sortNodes(nodes);
152152

153-
for (var i = 0, n = nodes.length; i < n; i++) {
154-
var node = nodes[i];
153+
for (let node of nodes) {
155154
switch (node.kind) {
156155
case SyntaxKind.ClassDeclaration:
157156
case SyntaxKind.EnumDeclaration:
@@ -204,8 +203,7 @@ module ts.NavigationBar {
204203

205204
var keyToItem: Map<NavigationBarItem> = {};
206205

207-
for (var i = 0, n = nodes.length; i < n; i++) {
208-
var child = nodes[i];
206+
for (let child of nodes) {
209207
var item = createItem(child);
210208
if (item !== undefined) {
211209
if (item.text.length > 0) {
@@ -238,12 +236,8 @@ module ts.NavigationBar {
238236

239237
// Next, recursively merge or add any children in the source as appropriate.
240238
outer:
241-
for (var i = 0, n = source.childItems.length; i < n; i++) {
242-
var sourceChild = source.childItems[i];
243-
244-
for (var j = 0, m = target.childItems.length; j < m; j++) {
245-
var targetChild = target.childItems[j];
246-
239+
for (let sourceChild of source.childItems) {
240+
for (let targetChild of target.childItems) {
247241
if (targetChild.text === sourceChild.text && targetChild.kind === sourceChild.kind) {
248242
// Found a match. merge them.
249243
merge(targetChild, sourceChild);

src/services/patternMatcher.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ module ts {
221221
// word part. That way we don't match something like 'Class' when the user types 'a'.
222222
// But we would match 'FooAttribute' (since 'Attribute' starts with 'a').
223223
var wordSpans = getWordSpans(candidate);
224-
for (var i = 0, n = wordSpans.length; i < n; i++) {
225-
var span = wordSpans[i]
224+
for (let span of wordSpans) {
226225
if (partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ true)) {
227226
return createPatternMatch(PatternMatchKind.substring, punctuationStripped,
228227
/*isCaseSensitive:*/ partStartsWith(candidate, span, chunk.text, /*ignoreCase:*/ false));
@@ -339,9 +338,7 @@ module ts {
339338
var subWordTextChunks = segment.subWordTextChunks;
340339
var matches: PatternMatch[] = undefined;
341340

342-
for (var i = 0, n = subWordTextChunks.length; i < n; i++) {
343-
var subWordTextChunk = subWordTextChunks[i];
344-
341+
for (let subWordTextChunk of subWordTextChunks) {
345342
// Try to match the candidate with this word
346343
var result = matchTextChunk(candidate, subWordTextChunk, /*punctuationStripped:*/ true);
347344
if (!result) {

src/services/services.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ module ts {
196196
var list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, NodeFlags.Synthetic, this);
197197
list._children = [];
198198
var pos = nodes.pos;
199-
for (var i = 0, len = nodes.length; i < len; i++) {
200-
var node = nodes[i];
199+
for (let node of nodes) {
201200
if (pos < node.pos) {
202201
pos = this.addSyntheticNodes(list._children, pos, node.pos);
203202
}
@@ -255,8 +254,7 @@ module ts {
255254

256255
public getFirstToken(sourceFile?: SourceFile): Node {
257256
var children = this.getChildren();
258-
for (var i = 0; i < children.length; i++) {
259-
var child = children[i];
257+
for (let child of children) {
260258
if (child.kind < SyntaxKind.FirstNode) {
261259
return child;
262260
}
@@ -1523,8 +1521,8 @@ module ts {
15231521

15241522
// Initialize the list with the root file names
15251523
var rootFileNames = host.getScriptFileNames();
1526-
for (var i = 0, n = rootFileNames.length; i < n; i++) {
1527-
this.createEntry(rootFileNames[i]);
1524+
for (let fileName of rootFileNames) {
1525+
this.createEntry(fileName);
15281526
}
15291527

15301528
// store the compilation settings
@@ -2252,8 +2250,8 @@ module ts {
22522250
// not part of the new program.
22532251
if (program) {
22542252
var oldSourceFiles = program.getSourceFiles();
2255-
for (var i = 0, n = oldSourceFiles.length; i < n; i++) {
2256-
var fileName = oldSourceFiles[i].fileName;
2253+
for (let oldSourceFile of oldSourceFiles) {
2254+
var fileName = oldSourceFile.fileName;
22572255
if (!newProgram.getSourceFile(fileName) || changesInCompilationSettingsAffectSyntax) {
22582256
documentRegistry.releaseDocument(fileName, oldSettings);
22592257
}
@@ -2329,8 +2327,8 @@ module ts {
23292327
}
23302328

23312329
// If any file is not up-to-date, then the whole program is not up-to-date
2332-
for (var i = 0, n = rootFileNames.length; i < n; i++) {
2333-
if (!sourceFileUpToDate(program.getSourceFile(rootFileNames[i]))) {
2330+
for (let fileName of rootFileNames) {
2331+
if (!sourceFileUpToDate(program.getSourceFile(fileName))) {
23342332
return false;
23352333
}
23362334
}
@@ -4314,8 +4312,8 @@ module ts {
43144312

43154313
var declarations = symbol.getDeclarations();
43164314
if (declarations) {
4317-
for (var i = 0, n = declarations.length; i < n; i++) {
4318-
var container = getContainerNode(declarations[i]);
4315+
for (let declaration of declarations) {
4316+
var container = getContainerNode(declaration);
43194317

43204318
if (!container) {
43214319
return undefined;
@@ -4831,8 +4829,8 @@ module ts {
48314829
// Remember the last meaning
48324830
var lastIterationMeaning = meaning;
48334831

4834-
for (var i = 0, n = declarations.length; i < n; i++) {
4835-
var declarationMeaning = getMeaningFromDeclaration(declarations[i]);
4832+
for (let declaration of declarations) {
4833+
var declarationMeaning = getMeaningFromDeclaration(declaration);
48364834

48374835
if (declarationMeaning & meaning) {
48384836
meaning |= declarationMeaning;
@@ -5401,8 +5399,7 @@ module ts {
54015399
// Ignore nodes that don't intersect the original span to classify.
54025400
if (textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) {
54035401
var children = element.getChildren();
5404-
for (var i = 0, n = children.length; i < n; i++) {
5405-
var child = children[i];
5402+
for (let child of children) {
54065403
if (isToken(child)) {
54075404
classifyToken(child);
54085405
}
@@ -5435,9 +5432,7 @@ module ts {
54355432
var parentElement = token.parent;
54365433

54375434
var childNodes = parentElement.getChildren(sourceFile);
5438-
for (var i = 0, n = childNodes.length; i < n; i++) {
5439-
var current = childNodes[i];
5440-
5435+
for (let current of childNodes) {
54415436
if (current.kind === matchKind) {
54425437
var range1 = createTextSpan(token.getStart(sourceFile), token.getWidth(sourceFile));
54435438
var range2 = createTextSpan(current.getStart(sourceFile), current.getWidth(sourceFile));

src/services/signatureHelp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ module ts.SignatureHelp {
318318
// arg index.
319319
var argumentIndex = 0;
320320
var listChildren = argumentsList.getChildren();
321-
for (var i = 0, n = listChildren.length; i < n; i++) {
322-
var child = listChildren[i];
321+
for (let child of listChildren) {
323322
if (child === node) {
324323
break;
325324
}

src/services/utilities.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ module ts {
184184
}
185185

186186
var children = n.getChildren();
187-
for (var i = 0, len = children.length; i < len; ++i) {
188-
var child = children[i];
187+
for (let child of children) {
189188
var shouldDiveInChildNode =
190189
// previous token is enclosed somewhere in the child
191190
(child.pos <= previousToken.pos && child.end > previousToken.end) ||
@@ -221,8 +220,8 @@ module ts {
221220
}
222221

223222
var children = n.getChildren();
224-
for (var i = 0, len = children.length; i < len; ++i) {
225-
var child = children[i];
223+
for (var i = 0, len = children.length; i < len; i++) {
224+
let child = children[i];
226225
if (nodeHasTokens(child)) {
227226
if (position <= child.end) {
228227
if (child.getStart(sourceFile) >= position) {

0 commit comments

Comments
 (0)