File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33/* @internal */
44namespace 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}
Original file line number Diff line number Diff line change 33/* @internal */
44namespace 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 ///
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments