Skip to content

Commit 697c4d3

Browse files
author
Andy
authored
Add debugName property to Rule (#18289)
1 parent 73eff81 commit 697c4d3

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

src/services/formatting/rule.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
/* @internal */
44
namespace ts.formatting {
55
export class Rule {
6+
// Used for debugging to identify each rule based on the property name it's assigned to.
7+
public debugName?: string;
68
constructor(
7-
public Descriptor: RuleDescriptor,
8-
public Operation: RuleOperation,
9-
public Flag: RuleFlags = RuleFlags.None) {
10-
}
11-
12-
public toString() {
13-
return "[desc=" + this.Descriptor + "," +
14-
"operation=" + this.Operation + "," +
15-
"flag=" + this.Flag + "]";
9+
readonly Descriptor: RuleDescriptor,
10+
readonly Operation: RuleOperation,
11+
readonly Flag: RuleFlags = RuleFlags.None) {
1612
}
1713
}
1814
}

src/services/formatting/rules.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
/* @internal */
44
namespace ts.formatting {
55
export class Rules {
6-
public getRuleName(rule: Rule) {
7-
const o: ts.MapLike<any> = <any>this;
8-
for (const name in o) {
9-
if (o[name] === rule) {
10-
return name;
11-
}
12-
}
13-
throw new Error("Unknown rule");
14-
}
15-
16-
[name: string]: any;
17-
186
public IgnoreBeforeComment: Rule;
197
public IgnoreAfterLineComment: Rule;
208

@@ -569,6 +557,16 @@ namespace ts.formatting {
569557
this.SpaceAfterSemicolon,
570558
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
571559
];
560+
561+
if (Debug.isDebugging) {
562+
const o: ts.MapLike<any> = <any>this;
563+
for (const name in o) {
564+
const rule = o[name];
565+
if (rule instanceof Rule) {
566+
rule.debugName = name;
567+
}
568+
}
569+
}
572570
}
573571

574572
///

src/services/formatting/rulesProvider.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,10 @@ namespace ts.formatting {
99

1010
constructor() {
1111
this.globalRules = new Rules();
12-
const activeRules = this.globalRules.HighPriorityCommonRules.slice(0).concat(this.globalRules.UserConfigurableRules).concat(this.globalRules.LowPriorityCommonRules);
12+
const activeRules = this.globalRules.HighPriorityCommonRules.concat(this.globalRules.UserConfigurableRules).concat(this.globalRules.LowPriorityCommonRules);
1313
this.rulesMap = RulesMap.create(activeRules);
1414
}
1515

16-
public getRuleName(rule: Rule): string {
17-
return this.globalRules.getRuleName(rule);
18-
}
19-
20-
public getRuleByName(name: string): Rule {
21-
return this.globalRules[name];
22-
}
23-
2416
public getRulesMap() {
2517
return this.rulesMap;
2618
}

0 commit comments

Comments
 (0)