Add debugName
property to Rule
(#18289)
This commit is contained in:
parent
73eff819b5
commit
697c4d3353
|
@ -3,16 +3,12 @@
|
||||||
/* @internal */
|
/* @internal */
|
||||||
namespace ts.formatting {
|
namespace ts.formatting {
|
||||||
export class Rule {
|
export class Rule {
|
||||||
|
// Used for debugging to identify each rule based on the property name it's assigned to.
|
||||||
|
public debugName?: string;
|
||||||
constructor(
|
constructor(
|
||||||
public Descriptor: RuleDescriptor,
|
readonly Descriptor: RuleDescriptor,
|
||||||
public Operation: RuleOperation,
|
readonly Operation: RuleOperation,
|
||||||
public Flag: RuleFlags = RuleFlags.None) {
|
readonly Flag: RuleFlags = RuleFlags.None) {
|
||||||
}
|
|
||||||
|
|
||||||
public toString() {
|
|
||||||
return "[desc=" + this.Descriptor + "," +
|
|
||||||
"operation=" + this.Operation + "," +
|
|
||||||
"flag=" + this.Flag + "]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,18 +3,6 @@
|
||||||
/* @internal */
|
/* @internal */
|
||||||
namespace ts.formatting {
|
namespace ts.formatting {
|
||||||
export class Rules {
|
export class Rules {
|
||||||
public getRuleName(rule: Rule) {
|
|
||||||
const o: ts.MapLike<any> = <any>this;
|
|
||||||
for (const name in o) {
|
|
||||||
if (o[name] === rule) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error("Unknown rule");
|
|
||||||
}
|
|
||||||
|
|
||||||
[name: string]: any;
|
|
||||||
|
|
||||||
public IgnoreBeforeComment: Rule;
|
public IgnoreBeforeComment: Rule;
|
||||||
public IgnoreAfterLineComment: Rule;
|
public IgnoreAfterLineComment: Rule;
|
||||||
|
|
||||||
|
@ -569,6 +557,16 @@ namespace ts.formatting {
|
||||||
this.SpaceAfterSemicolon,
|
this.SpaceAfterSemicolon,
|
||||||
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (Debug.isDebugging) {
|
||||||
|
const o: ts.MapLike<any> = <any>this;
|
||||||
|
for (const name in o) {
|
||||||
|
const rule = o[name];
|
||||||
|
if (rule instanceof Rule) {
|
||||||
|
rule.debugName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
@ -9,18 +9,10 @@ namespace ts.formatting {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.globalRules = new Rules();
|
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);
|
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() {
|
public getRulesMap() {
|
||||||
return this.rulesMap;
|
return this.rulesMap;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue