From fd98f193630931101cc1eee277dff7dc0af5d21d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 13 Mar 2015 14:15:20 -0700 Subject: [PATCH] Use 'let' in the services layer. --- src/services/formatting/rules.ts | 12 ++++---- src/services/formatting/rulesMap.ts | 36 ++++++++++++------------ src/services/formatting/rulesProvider.ts | 6 ++-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 7eb5232af18..7d3509ef495 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -18,8 +18,8 @@ module ts.formatting { export class Rules { public getRuleName(rule: Rule) { - var o: ts.Map = this; - for (var name in o) { + let o: ts.Map = this; + for (let name in o) { if (o[name] === rule) { return name; } @@ -139,7 +139,7 @@ module ts.formatting { // Lambda expressions public SpaceAfterArrow: Rule; - // Optional parameters and var args + // Optional parameters and let args public NoSpaceAfterEllipsis: Rule; public NoSpaceAfterOptionalParameters: Rule; @@ -330,7 +330,7 @@ module ts.formatting { // Lambda expressions this.SpaceAfterArrow = new Rule(RuleDescriptor.create3(SyntaxKind.EqualsGreaterThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); - // Optional parameters and var args + // Optional parameters and let args this.NoSpaceAfterEllipsis = new Rule(RuleDescriptor.create1(SyntaxKind.DotDotDotToken, SyntaxKind.Identifier), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.NoSpaceAfterOptionalParameters = new Rule(RuleDescriptor.create3(SyntaxKind.QuestionToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CommaToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBinaryOpContext), RuleAction.Delete)); @@ -462,7 +462,7 @@ module ts.formatting { // equal in import a = module('a'); case SyntaxKind.ImportEqualsDeclaration: - // equal in var a = 0; + // equal in let a = 0; case SyntaxKind.VariableDeclaration: // equal in p = 0; case SyntaxKind.Parameter: @@ -470,7 +470,7 @@ module ts.formatting { case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; - // "in" keyword in for (var x in []) { } + // "in" keyword in for (let x in []) { } case SyntaxKind.ForInStatement: return context.currentTokenSpan.kind === SyntaxKind.InKeyword || context.nextTokenSpan.kind === SyntaxKind.InKeyword; // Technically, "of" is not a binary operator, but format it the same way as "in" diff --git a/src/services/formatting/rulesMap.ts b/src/services/formatting/rulesMap.ts index 634ec61de9c..b43e91424f8 100644 --- a/src/services/formatting/rulesMap.ts +++ b/src/services/formatting/rulesMap.ts @@ -26,7 +26,7 @@ module ts.formatting { } static create(rules: Rule[]): RulesMap { - var result = new RulesMap(); + let result = new RulesMap(); result.Initialize(rules); return result; } @@ -36,7 +36,7 @@ module ts.formatting { this.map = new Array(this.mapRowLength * this.mapRowLength);//new Array(this.mapRowLength * this.mapRowLength); // This array is used only during construction of the rulesbucket in the map - var rulesBucketConstructionStateList: RulesBucketConstructionState[] = new Array(this.map.length);//new Array(this.map.length); + let rulesBucketConstructionStateList: RulesBucketConstructionState[] = new Array(this.map.length);//new Array(this.map.length); this.FillRules(rules, rulesBucketConstructionStateList); return this.map; @@ -49,20 +49,20 @@ module ts.formatting { } private GetRuleBucketIndex(row: number, column: number): number { - var rulesBucketIndex = (row * this.mapRowLength) + column; + let rulesBucketIndex = (row * this.mapRowLength) + column; //Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array."); return rulesBucketIndex; } private FillRule(rule: Rule, rulesBucketConstructionStateList: RulesBucketConstructionState[]): void { - var specificRule = rule.Descriptor.LeftTokenRange != Shared.TokenRange.Any && + let specificRule = rule.Descriptor.LeftTokenRange != Shared.TokenRange.Any && rule.Descriptor.RightTokenRange != Shared.TokenRange.Any; rule.Descriptor.LeftTokenRange.GetTokens().forEach((left) => { rule.Descriptor.RightTokenRange.GetTokens().forEach((right) => { - var rulesBucketIndex = this.GetRuleBucketIndex(left, right); + let rulesBucketIndex = this.GetRuleBucketIndex(left, right); - var rulesBucket = this.map[rulesBucketIndex]; + let rulesBucket = this.map[rulesBucketIndex]; if (rulesBucket == undefined) { rulesBucket = this.map[rulesBucketIndex] = new RulesBucket(); } @@ -73,8 +73,8 @@ module ts.formatting { } public GetRule(context: FormattingContext): Rule { - var bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind); - var bucket = this.map[bucketIndex]; + let bucketIndex = this.GetRuleBucketIndex(context.currentTokenSpan.kind, context.nextTokenSpan.kind); + let bucket = this.map[bucketIndex]; if (bucket != null) { for (let rule of bucket.Rules()) { if (rule.Operation.Context.InContext(context)) { @@ -86,8 +86,8 @@ module ts.formatting { } } - var MaskBitSize = 5; - var Mask = 0x1f; + let MaskBitSize = 5; + let Mask = 0x1f; export enum RulesPosition { IgnoreRulesSpecific = 0, @@ -121,10 +121,10 @@ module ts.formatting { } public GetInsertionIndex(maskPosition: RulesPosition): number { - var index = 0; + let index = 0; - var pos = 0; - var indexBitmap = this.rulesInsertionIndexBitmap; + let pos = 0; + let indexBitmap = this.rulesInsertionIndexBitmap; while (pos <= maskPosition) { index += (indexBitmap & Mask); @@ -136,11 +136,11 @@ module ts.formatting { } public IncreaseInsertionIndex(maskPosition: RulesPosition): void { - var value = (this.rulesInsertionIndexBitmap >> maskPosition) & Mask; + let value = (this.rulesInsertionIndexBitmap >> maskPosition) & Mask; value++; Debug.assert((value & Mask) == value, "Adding more rules into the sub-bucket than allowed. Maximum allowed is 32 rules."); - var temp = this.rulesInsertionIndexBitmap & ~(Mask << maskPosition); + let temp = this.rulesInsertionIndexBitmap & ~(Mask << maskPosition); temp |= value << maskPosition; this.rulesInsertionIndexBitmap = temp; @@ -159,7 +159,7 @@ module ts.formatting { } public AddRule(rule: Rule, specificTokens: boolean, constructionState: RulesBucketConstructionState[], rulesBucketIndex: number): void { - var position: RulesPosition; + let position: RulesPosition; if (rule.Operation.Action == RuleAction.Ignore) { position = specificTokens ? @@ -177,11 +177,11 @@ module ts.formatting { RulesPosition.NoContextRulesAny; } - var state = constructionState[rulesBucketIndex]; + let state = constructionState[rulesBucketIndex]; if (state === undefined) { state = constructionState[rulesBucketIndex] = new RulesBucketConstructionState(); } - var index = state.GetInsertionIndex(position); + let index = state.GetInsertionIndex(position); this.rules.splice(index, 0, rule); state.IncreaseInsertionIndex(position); } diff --git a/src/services/formatting/rulesProvider.ts b/src/services/formatting/rulesProvider.ts index 25b6f1ba772..5f63db8630b 100644 --- a/src/services/formatting/rulesProvider.ts +++ b/src/services/formatting/rulesProvider.ts @@ -40,8 +40,8 @@ module ts.formatting { public ensureUpToDate(options: ts.FormatCodeOptions) { if (this.options == null || !ts.compareDataObjects(this.options, options)) { - var activeRules = this.createActiveRules(options); - var rulesMap = RulesMap.create(activeRules); + let activeRules = this.createActiveRules(options); + let rulesMap = RulesMap.create(activeRules); this.activeRules = activeRules; this.rulesMap = rulesMap; @@ -50,7 +50,7 @@ module ts.formatting { } private createActiveRules(options: ts.FormatCodeOptions): Rule[] { - var rules = this.globalRules.HighPriorityCommonRules.slice(0); + let rules = this.globalRules.HighPriorityCommonRules.slice(0); if (options.InsertSpaceAfterCommaDelimiter) { rules.push(this.globalRules.SpaceAfterComma);