Skip to content

Commit

Permalink
Rewrite logical expressions for ESLint (#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjethani committed Aug 3, 2021
1 parent 3ca5e68 commit 6ef74fc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
3 changes: 1 addition & 2 deletions platform/nodejs/eslintrc.json
Expand Up @@ -19,8 +19,7 @@
"ObjectExpression": "off",
"ignoreComments": true,
"ignoredNodes": [
"AssignmentExpression:has(Literal)",
"LogicalExpression"
"AssignmentExpression:has(Literal)"
]
}
],
Expand Down
41 changes: 25 additions & 16 deletions src/js/static-filtering-parser.js
Expand Up @@ -2437,22 +2437,7 @@ const NetOptionsIterator = class {
descriptor = netOptionTokenDescriptors.get(token);
}
// Validate option according to context
if (
descriptor === undefined ||
ltok !== lopt &&
hasNoBits(descriptor, OPTCanNegate) ||
this.exception &&
hasBits(descriptor, OPTBlockOnly) ||
this.exception === false &&
hasBits(descriptor, OPTAllowOnly) ||
assigned &&
hasNoBits(descriptor, OPTMayAssign | OPTMustAssign) ||
assigned === false &&
hasBits(descriptor, OPTMustAssign) && (
this.exception === false ||
hasNoBits(descriptor, OPTAllowMayAssign)
)
) {
if ( !this.optionIsValidInContext(descriptor, ltok !== lopt, assigned) ) {
descriptor = OPTTokenInvalid;
}
// Keep track of which options are present: any given option can
Expand Down Expand Up @@ -2665,6 +2650,30 @@ const NetOptionsIterator = class {
this.readPtr = i + 6;
return this;
}

optionIsValidInContext(descriptor, negated, assigned) {
if ( descriptor === undefined ) {
return false;
}
if ( negated && hasNoBits(descriptor, OPTCanNegate) ) {
return false;
}
if ( this.exception && hasBits(descriptor, OPTBlockOnly) ) {
return false;
}
if ( this.exception === false && hasBits(descriptor, OPTAllowOnly) ) {
return false;
}
if ( assigned && hasNoBits(descriptor, OPTMayAssign | OPTMustAssign) ) {
return false;
}
if ( assigned === false && hasBits(descriptor, OPTMustAssign) ) {
if ( this.exception === false || hasNoBits(descriptor, OPTAllowMayAssign) ) {
return false;
}
}
return true;
}
};

/******************************************************************************/
Expand Down
15 changes: 7 additions & 8 deletions src/js/static-net-filtering.js
Expand Up @@ -3268,14 +3268,13 @@ const FilterParser = class {
}

isJustOrigin() {
return this.optionUnitBits === this.DOMAIN_BIT &&
this.isRegex === false && (
this.pattern === '*' || (
this.anchor === 0b010 &&
/^(?:http[s*]?:(?:\/\/)?)$/.test(this.pattern)
)
) &&
this.domainOpt.indexOf('~') === -1;
if ( this.optionUnitBits !== this.DOMAIN_BIT ) { return false; }
if ( this.isRegex ) { return false; }
if ( this.domainOpt.includes('~') ) { return false; }
if ( this.pattern === '*' ) { return true; }
if ( this.anchor !== 0b010 ) { return false; }
if ( /^(?:http[s*]?:(?:\/\/)?)$/.test(this.pattern) ) { return true; }
return false;
}

domainIsEntity(s) {
Expand Down

0 comments on commit 6ef74fc

Please sign in to comment.