diff --git a/src/services/formatting/rule.ts b/src/services/formatting/rule.ts index 543295f364..10987c745c 100644 --- a/src/services/formatting/rule.ts +++ b/src/services/formatting/rule.ts @@ -3,16 +3,12 @@ /* @internal */ namespace ts.formatting { export class Rule { + // Used for debugging to identify each rule based on the property name it's assigned to. + public debugName?: string; constructor( - public Descriptor: RuleDescriptor, - public Operation: RuleOperation, - public Flag: RuleFlags = RuleFlags.None) { - } - - public toString() { - return "[desc=" + this.Descriptor + "," + - "operation=" + this.Operation + "," + - "flag=" + this.Flag + "]"; + readonly Descriptor: RuleDescriptor, + readonly Operation: RuleOperation, + readonly Flag: RuleFlags = RuleFlags.None) { } } } \ No newline at end of file diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 2daf8d9d28..07c2804ee8 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -3,18 +3,6 @@ /* @internal */ namespace ts.formatting { export class Rules { - public getRuleName(rule: Rule) { - const o: ts.MapLike = this; - for (const name in o) { - if (o[name] === rule) { - return name; - } - } - throw new Error("Unknown rule"); - } - - [name: string]: any; - public IgnoreBeforeComment: Rule; public IgnoreAfterLineComment: Rule; @@ -569,6 +557,16 @@ namespace ts.formatting { this.SpaceAfterSemicolon, this.SpaceBetweenStatements, this.SpaceAfterTryFinally ]; + + if (Debug.isDebugging) { + const o: ts.MapLike = this; + for (const name in o) { + const rule = o[name]; + if (rule instanceof Rule) { + rule.debugName = name; + } + } + } } /// diff --git a/src/services/formatting/rulesProvider.ts b/src/services/formatting/rulesProvider.ts index 790bce054b..1dd7acbdc6 100644 --- a/src/services/formatting/rulesProvider.ts +++ b/src/services/formatting/rulesProvider.ts @@ -9,18 +9,10 @@ namespace ts.formatting { constructor() { this.globalRules = new Rules(); - const activeRules = this.globalRules.HighPriorityCommonRules.slice(0).concat(this.globalRules.UserConfigurableRules).concat(this.globalRules.LowPriorityCommonRules); + const activeRules = this.globalRules.HighPriorityCommonRules.concat(this.globalRules.UserConfigurableRules).concat(this.globalRules.LowPriorityCommonRules); this.rulesMap = RulesMap.create(activeRules); } - public getRuleName(rule: Rule): string { - return this.globalRules.getRuleName(rule); - } - - public getRuleByName(name: string): Rule { - return this.globalRules[name]; - } - public getRulesMap() { return this.rulesMap; }