mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-13 15:07:02 +03:00
Always use parentheses in unclear nesting
This commit is contained in:
@@ -86,7 +86,7 @@ function configToText(config: AdvancedSkipRule[]): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result += "if ";
|
result += "if ";
|
||||||
result += predicateToText(rule.predicate, PredicateOperator.Or);
|
result += predicateToText(rule.predicate, null);
|
||||||
|
|
||||||
switch (rule.skipOption) {
|
switch (rule.skipOption) {
|
||||||
case CategorySkipOption.Disabled:
|
case CategorySkipOption.Disabled:
|
||||||
@@ -111,15 +111,18 @@ function configToText(config: AdvancedSkipRule[]): string {
|
|||||||
return result.trim();
|
return result.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function predicateToText(predicate: AdvancedSkipPredicate, highestPrecedence: PredicateOperator): string {
|
function predicateToText(predicate: AdvancedSkipPredicate, outerPrecedence: PredicateOperator | null): string {
|
||||||
if (predicate.kind === "check") {
|
if (predicate.kind === "check") {
|
||||||
return `${predicate.attribute} ${predicate.operator} ${JSON.stringify(predicate.value)}`;
|
return `${predicate.attribute} ${predicate.operator} ${JSON.stringify(predicate.value)}`;
|
||||||
} else {
|
} else {
|
||||||
|
let text: string;
|
||||||
|
|
||||||
if (predicate.operator === PredicateOperator.And) {
|
if (predicate.operator === PredicateOperator.And) {
|
||||||
return `${predicateToText(predicate.left, PredicateOperator.And)} and ${predicateToText(predicate.right, PredicateOperator.And)}`;
|
text = `${predicateToText(predicate.left, PredicateOperator.And)} and ${predicateToText(predicate.right, PredicateOperator.And)}`;
|
||||||
} else { // Or
|
} else { // Or
|
||||||
const text = `${predicateToText(predicate.left, PredicateOperator.Or)} or ${predicateToText(predicate.right, PredicateOperator.Or)}`;
|
text = `${predicateToText(predicate.left, PredicateOperator.Or)} or ${predicateToText(predicate.right, PredicateOperator.Or)}`;
|
||||||
return highestPrecedence == PredicateOperator.And ? `(${text})` : text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return outerPrecedence !== null && outerPrecedence !== predicate.operator ? `(${text})` : text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user