ignore empty code only in global (non-targeted) sections

This commit is contained in:
tophf 2020-10-04 13:42:06 +03:00
parent 7c89f7b21d
commit cb89be8682
2 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty
/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty styleSectionGlobal
getStyleWithNoCode msg sync uuidv4 */
/* exported styleManager */
'use strict';
@ -445,7 +445,7 @@ const styleManager = (() => {
excluded = true;
}
for (const section of data.sections) {
if (styleCodeEmpty(section.code)) {
if (styleSectionGlobal(section) && styleCodeEmpty(section.code)) {
continue;
}
const match = urlMatchSection(query, section);
@ -612,15 +612,7 @@ const styleManager = (() => {
return 'sloppy';
}
// TODO: check for invalid regexps?
if (
(!section.regexps || !section.regexps.length) &&
(!section.urlPrefixes || !section.urlPrefixes.length) &&
(!section.urls || !section.urls.length) &&
(!section.domains || !section.domains.length)
) {
return true;
}
return false;
return styleSectionGlobal(section);
}
function createCompiler(compile) {

View File

@ -1,4 +1,4 @@
/* exported styleSectionsEqual styleCodeEmpty calcStyleDigest styleJSONseemsValid */
/* exported styleSectionsEqual styleCodeEmpty styleSectionGlobal calcStyleDigest styleJSONseemsValid */
'use strict';
function styleCodeEmpty(code) {
@ -14,6 +14,14 @@ function styleCodeEmpty(code) {
return false;
}
/** Checks if section is global i.e. has no targets at all */
function styleSectionGlobal(section) {
return (!section.regexps || !section.regexps.length) &&
(!section.urlPrefixes || !section.urlPrefixes.length) &&
(!section.urls || !section.urls.length) &&
(!section.domains || !section.domains.length);
}
/**
* @param {Style} a - first style object
* @param {Style} b - second style object