@adguard/agtree 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/ast-utils/clone.js +12 -8
- package/dist/ast-utils/modifiers.js +13 -11
- package/dist/ast-utils/network-rules.js +10 -9
- package/dist/ast-utils/scriptlets.js +20 -18
- package/dist/common/abp-snippet-injection-body-common.js +1 -1
- package/dist/common/agent-common.js +1 -1
- package/dist/common/ubo-html-filtering-body-common.js +1 -1
- package/dist/common/ubo-selector-common.js +1 -1
- package/dist/compatibility-tables/base.js +7 -6
- package/dist/compatibility-tables/compatibility-table-data.js +1 -1
- package/dist/compatibility-tables/modifiers.js +4 -3
- package/dist/compatibility-tables/platforms.js +1 -1
- package/dist/compatibility-tables/redirects.js +4 -4
- package/dist/compatibility-tables/schemas/base.js +2 -2
- package/dist/compatibility-tables/schemas/modifier.js +4 -4
- package/dist/compatibility-tables/schemas/platform.js +3 -2
- package/dist/compatibility-tables/schemas/redirect.js +1 -1
- package/dist/compatibility-tables/schemas/resource-type.js +1 -1
- package/dist/compatibility-tables/schemas/scriptlet.js +1 -1
- package/dist/compatibility-tables/scriptlets.js +2 -2
- package/dist/compatibility-tables/utils/platform-helpers.js +6 -4
- package/dist/compatibility-tables/utils/resource-type-helpers.js +1 -1
- package/dist/compatibility-tables/utils/zod-camelcase.js +3 -3
- package/dist/converter/base-interfaces/base-converter.js +22 -16
- package/dist/converter/base-interfaces/conversion-result.js +15 -11
- package/dist/converter/base-interfaces/rule-converter-base.js +19 -13
- package/dist/converter/comment/index.js +11 -9
- package/dist/converter/cosmetic/css.js +12 -10
- package/dist/converter/cosmetic/element-hiding.js +12 -10
- package/dist/converter/cosmetic/header-removal.js +16 -13
- package/dist/converter/cosmetic/html.js +18 -18
- package/dist/converter/cosmetic/index.js +28 -24
- package/dist/converter/cosmetic/rule-modifiers/adg.js +15 -12
- package/dist/converter/cosmetic/rule-modifiers/ubo.js +22 -19
- package/dist/converter/cosmetic/scriptlet.js +26 -22
- package/dist/converter/css/index.js +13 -11
- package/dist/converter/data/css.js +8 -8
- package/dist/converter/filter-list.js +12 -10
- package/dist/converter/index.js +1 -1
- package/dist/converter/misc/network-rule-modifier.js +20 -16
- package/dist/converter/network/index.js +16 -12
- package/dist/converter/raw-filter-list.js +12 -10
- package/dist/converter/raw-rule.js +14 -12
- package/dist/converter/rule.js +17 -13
- package/dist/errors/adblock-syntax-error.js +1 -1
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/rule-conversion-error.js +2 -2
- package/dist/generator/base-generator.js +1 -1
- package/dist/generator/comment/agent-comment-generator.js +4 -3
- package/dist/generator/comment/agent-generator.js +5 -4
- package/dist/generator/comment/comment-rule-generator.js +6 -5
- package/dist/generator/comment/config-comment-generator.js +5 -4
- package/dist/generator/comment/hint-comment-generator.js +5 -4
- package/dist/generator/comment/hint-generator.js +4 -3
- package/dist/generator/comment/metadata-comment-generator.js +3 -2
- package/dist/generator/comment/pre-processor-comment-generator.js +6 -5
- package/dist/generator/comment/simple-comment-generator.js +3 -2
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +13 -11
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +5 -4
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +7 -5
- package/dist/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.js +3 -3
- package/dist/generator/cosmetic/html-filtering-body/html-filtering-body-generator.js +1 -1
- package/dist/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.js +2 -2
- package/dist/generator/cosmetic/scriptlet-body/abp-snippet-injection-body-generator.js +7 -5
- package/dist/generator/cosmetic/scriptlet-body/adg-scriptlet-injection-body-generator.js +7 -5
- package/dist/generator/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-generator.js +8 -6
- package/dist/generator/cosmetic/selector/attribute-selector-generator.js +2 -2
- package/dist/generator/cosmetic/selector/class-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/complex-selector-generator.js +4 -4
- package/dist/generator/cosmetic/selector/id-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/pseudo-class-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/selector-combinator-generator.js +1 -1
- package/dist/generator/cosmetic/selector/selector-list-generator.js +1 -1
- package/dist/generator/cosmetic/selector/type-selector-generator.js +1 -1
- package/dist/generator/css/adg-css-injection-generator.js +5 -1
- package/dist/generator/filterlist-generator.js +5 -4
- package/dist/generator/index.js +1 -1
- package/dist/generator/misc/domain-list-generator.js +1 -1
- package/dist/generator/misc/list-items-generator.js +5 -3
- package/dist/generator/misc/logical-expression-generator.js +5 -4
- package/dist/generator/misc/modifier-generator.js +4 -3
- package/dist/generator/misc/modifier-list-generator.js +5 -4
- package/dist/generator/misc/parameter-list-generator.js +6 -5
- package/dist/generator/misc/value-generator.js +2 -1
- package/dist/generator/network/host-rule-generator.js +2 -1
- package/dist/generator/network/network-rule-generator.js +2 -1
- package/dist/generator/rule-generator.js +6 -4
- package/dist/index.js +1 -2
- package/dist/nodes/index.js +1 -1
- package/dist/package.json.js +2 -2
- package/dist/parser/base-parser.js +1 -1
- package/dist/parser/comment/agent-comment-parser.js +11 -9
- package/dist/parser/comment/agent-parser.js +12 -9
- package/dist/parser/comment/comment-parser.js +8 -7
- package/dist/parser/comment/config-comment-parser.js +9 -6
- package/dist/parser/comment/hint-comment-parser.js +17 -12
- package/dist/parser/comment/hint-parser.js +10 -7
- package/dist/parser/comment/metadata-comment-parser.js +9 -7
- package/dist/parser/comment/preprocessor-parser.js +14 -11
- package/dist/parser/comment/simple-comment-parser.js +5 -2
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +29 -25
- package/dist/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.js +3 -3
- package/dist/parser/cosmetic/html-filtering-body/html-filtering-body-parser.js +4 -4
- package/dist/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.js +7 -7
- package/dist/parser/cosmetic/scriptlet-body/abp-snippet-injection-body-parser.js +12 -9
- package/dist/parser/cosmetic/scriptlet-body/adg-scriptlet-injection-body-parser.js +12 -9
- package/dist/parser/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-parser.js +11 -8
- package/dist/parser/cosmetic/selector/handlers/attribute-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/class-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/complex-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/compound-selector-handler.js +2 -2
- package/dist/parser/cosmetic/selector/handlers/id-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.js +5 -3
- package/dist/parser/cosmetic/selector/handlers/type-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/selector-list-parser.js +7 -7
- package/dist/parser/css/adg-css-injection-parser.js +4 -3
- package/dist/parser/css/balancing.js +22 -18
- package/dist/parser/css/constants.js +1 -1
- package/dist/parser/css/css-token-stream.js +15 -4
- package/dist/parser/css/ubo-selector-parser.js +8 -4
- package/dist/parser/filterlist-parser.js +8 -5
- package/dist/parser/index.js +1 -1
- package/dist/parser/misc/app-list-parser.js +4 -3
- package/dist/parser/misc/domain-list-parser.js +8 -6
- package/dist/parser/misc/list-items-parser.js +8 -6
- package/dist/parser/misc/logical-expression-parser.js +25 -18
- package/dist/parser/misc/method-list-parser.js +4 -3
- package/dist/parser/misc/modifier-list.js +3 -3
- package/dist/parser/misc/modifier-parser.js +5 -4
- package/dist/parser/misc/parameter-list-parser.js +6 -5
- package/dist/parser/misc/stealth-option-list-parser.js +4 -3
- package/dist/parser/misc/ubo-parameter-list-parser.js +10 -9
- package/dist/parser/misc/value-parser.js +2 -2
- package/dist/parser/network/host-rule-parser.js +15 -7
- package/dist/parser/network/network-rule-parser.js +11 -9
- package/dist/parser/options.js +1 -1
- package/dist/parser/rule-parser.js +11 -7
- package/dist/types/ast-utils/clone.d.ts +12 -8
- package/dist/types/ast-utils/filter-list.d.ts +5 -4
- package/dist/types/ast-utils/modifiers.d.ts +11 -9
- package/dist/types/ast-utils/network-rules.d.ts +8 -7
- package/dist/types/ast-utils/scriptlets.d.ts +19 -17
- package/dist/types/compatibility-tables/base.d.ts +6 -5
- package/dist/types/compatibility-tables/redirects.d.ts +1 -1
- package/dist/types/compatibility-tables/schemas/platform.d.ts +1 -0
- package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +5 -3
- package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +3 -3
- package/dist/types/converter/base-interfaces/base-converter.d.ts +21 -15
- package/dist/types/converter/base-interfaces/conversion-result.d.ts +20 -16
- package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +19 -13
- package/dist/types/converter/comment/index.d.ts +9 -7
- package/dist/types/converter/cosmetic/css.d.ts +9 -7
- package/dist/types/converter/cosmetic/element-hiding.d.ts +9 -7
- package/dist/types/converter/cosmetic/header-removal.d.ts +10 -7
- package/dist/types/converter/cosmetic/html.d.ts +9 -9
- package/dist/types/converter/cosmetic/index.d.ts +14 -10
- package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +9 -6
- package/dist/types/converter/cosmetic/rule-modifiers/ubo.d.ts +9 -6
- package/dist/types/converter/cosmetic/scriptlet.d.ts +14 -10
- package/dist/types/converter/css/index.d.ts +9 -7
- package/dist/types/converter/data/css.d.ts +1 -1
- package/dist/types/converter/filter-list.d.ts +10 -8
- package/dist/types/converter/index.d.ts +1 -1
- package/dist/types/converter/misc/network-rule-modifier.d.ts +13 -9
- package/dist/types/converter/network/index.d.ts +15 -11
- package/dist/types/converter/raw-filter-list.d.ts +8 -6
- package/dist/types/converter/raw-rule.d.ts +8 -6
- package/dist/types/converter/rule.d.ts +14 -10
- package/dist/types/errors/not-implemented-error.d.ts +1 -1
- package/dist/types/errors/rule-conversion-error.d.ts +1 -1
- package/dist/types/generator/comment/agent-comment-generator.d.ts +3 -2
- package/dist/types/generator/comment/agent-generator.d.ts +4 -3
- package/dist/types/generator/comment/comment-rule-generator.d.ts +3 -2
- package/dist/types/generator/comment/config-comment-generator.d.ts +4 -3
- package/dist/types/generator/comment/hint-comment-generator.d.ts +4 -3
- package/dist/types/generator/comment/hint-generator.d.ts +3 -2
- package/dist/types/generator/comment/metadata-comment-generator.d.ts +1 -0
- package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +3 -2
- package/dist/types/generator/comment/simple-comment-generator.d.ts +2 -1
- package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +7 -5
- package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +3 -2
- package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +4 -2
- package/dist/types/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.d.ts +1 -1
- package/dist/types/generator/cosmetic/html-filtering-body/html-filtering-body-generator.d.ts +1 -1
- package/dist/types/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.d.ts +2 -2
- package/dist/types/generator/cosmetic/scriptlet-body/abp-snippet-injection-body-generator.d.ts +5 -3
- package/dist/types/generator/cosmetic/scriptlet-body/adg-scriptlet-injection-body-generator.d.ts +5 -3
- package/dist/types/generator/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-generator.d.ts +7 -5
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +4 -0
- package/dist/types/generator/css/ubo-selector-generator.d.ts +4 -3
- package/dist/types/generator/filterlist-generator.d.ts +3 -2
- package/dist/types/generator/misc/list-items-generator.d.ts +4 -2
- package/dist/types/generator/misc/logical-expression-generator.d.ts +4 -3
- package/dist/types/generator/misc/modifier-generator.d.ts +3 -2
- package/dist/types/generator/misc/modifier-list-generator.d.ts +4 -3
- package/dist/types/generator/misc/parameter-list-generator.d.ts +5 -4
- package/dist/types/generator/misc/value-generator.d.ts +1 -0
- package/dist/types/generator/network/host-rule-generator.d.ts +1 -0
- package/dist/types/generator/network/network-rule-generator.d.ts +1 -0
- package/dist/types/generator/rule-generator.d.ts +5 -3
- package/dist/types/index.d.ts +1 -2
- package/dist/types/nodes/index.d.ts +55 -54
- package/dist/types/parser/comment/agent-comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/agent-parser.d.ts +7 -4
- package/dist/types/parser/comment/comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/config-comment-parser.d.ts +5 -2
- package/dist/types/parser/comment/hint-comment-parser.d.ts +11 -6
- package/dist/types/parser/comment/hint-parser.d.ts +6 -3
- package/dist/types/parser/comment/metadata-comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/preprocessor-parser.d.ts +9 -6
- package/dist/types/parser/comment/simple-comment-parser.d.ts +3 -0
- package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +9 -6
- package/dist/types/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.d.ts +3 -3
- package/dist/types/parser/cosmetic/html-filtering-body/html-filtering-body-parser.d.ts +4 -4
- package/dist/types/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.d.ts +4 -4
- package/dist/types/parser/cosmetic/scriptlet-body/abp-snippet-injection-body-parser.d.ts +8 -5
- package/dist/types/parser/cosmetic/scriptlet-body/adg-scriptlet-injection-body-parser.d.ts +9 -6
- package/dist/types/parser/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-parser.d.ts +8 -5
- package/dist/types/parser/cosmetic/selector/context.d.ts +2 -2
- package/dist/types/parser/cosmetic/selector/selector-list-parser.d.ts +2 -2
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +1 -0
- package/dist/types/parser/css/balancing.d.ts +17 -12
- package/dist/types/parser/css/css-token-stream.d.ts +11 -0
- package/dist/types/parser/css/ubo-selector-parser.d.ts +3 -0
- package/dist/types/parser/filterlist-parser.d.ts +5 -2
- package/dist/types/parser/misc/app-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/domain-list-parser.d.ts +5 -3
- package/dist/types/parser/misc/list-items-parser.d.ts +5 -3
- package/dist/types/parser/misc/logical-expression-parser.d.ts +9 -5
- package/dist/types/parser/misc/method-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/modifier-list.d.ts +2 -1
- package/dist/types/parser/misc/modifier-parser.d.ts +2 -1
- package/dist/types/parser/misc/parameter-list-parser.d.ts +3 -2
- package/dist/types/parser/misc/stealth-option-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +2 -1
- package/dist/types/parser/misc/value-parser.d.ts +1 -1
- package/dist/types/parser/network/host-rule-parser.d.ts +10 -2
- package/dist/types/parser/network/network-rule-parser.d.ts +5 -3
- package/dist/types/parser/options.d.ts +1 -1
- package/dist/types/parser/rule-parser.d.ts +6 -2
- package/dist/types/tokenizer/tokenizer.d.ts +2 -2
- package/dist/types/utils/adblockers.d.ts +9 -6
- package/dist/types/utils/clone.d.ts +4 -3
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/cosmetic-rule-separator.d.ts +13 -10
- package/dist/types/utils/deep-freeze.d.ts +4 -4
- package/dist/types/utils/domain.d.ts +3 -2
- package/dist/types/utils/logical-expression.d.ts +9 -5
- package/dist/types/utils/multi-value-map.d.ts +3 -3
- package/dist/types/utils/position-provider.d.ts +3 -2
- package/dist/types/utils/quotes.d.ts +48 -42
- package/dist/types/utils/regexp.d.ts +24 -17
- package/dist/types/utils/string.d.ts +135 -103
- package/dist/types/utils/type-guards.d.ts +1 -0
- package/dist/types/validator/helpers.d.ts +1 -1
- package/dist/types/validator/index.d.ts +3 -3
- package/dist/types/version.d.ts +1 -1
- package/dist/utils/adblockers.js +10 -7
- package/dist/utils/bit-count.js +1 -1
- package/dist/utils/categorizer.js +2 -2
- package/dist/utils/clone.js +5 -4
- package/dist/utils/constants.js +2 -2
- package/dist/utils/cosmetic-rule-separator.js +15 -11
- package/dist/utils/deep-freeze.js +5 -5
- package/dist/utils/domain.js +4 -3
- package/dist/utils/error.js +3 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/logical-expression.js +10 -6
- package/dist/utils/multi-value-map.js +4 -4
- package/dist/utils/noop-modifier.js +1 -1
- package/dist/utils/position-provider.js +2 -1
- package/dist/utils/quotes.js +49 -43
- package/dist/utils/regexp.js +25 -18
- package/dist/utils/string.js +136 -104
- package/dist/utils/type-guards.js +2 -1
- package/dist/validator/constants.js +1 -1
- package/dist/validator/helpers.js +1 -1
- package/dist/validator/index.js +8 -8
- package/dist/validator/value.js +6 -6
- package/dist/version.js +2 -2
- package/package.json +3 -1
- package/dist/errors/binary-schema-mismatch-error.js +0 -37
- package/dist/types/errors/binary-schema-mismatch-error.d.ts +0 -23
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import { ListNodeType, ListItemNodeType } from '../../../nodes/index.js';
|
|
8
7
|
import { createModifierNode } from '../../../ast-utils/modifiers.js';
|
|
9
|
-
import {
|
|
8
|
+
import { ListNodeType, ListItemNodeType } from '../../../nodes/index.js';
|
|
9
|
+
import '../../../utils/adblockers.js';
|
|
10
10
|
import { ADG_PATH_MODIFIER, ADG_URL_MODIFIER, COMMA_DOMAIN_LIST_SEPARATOR, ADG_DOMAINS_MODIFIER, PIPE_MODIFIER_SEPARATOR, ADG_APP_MODIFIER, UBO_MATCHES_PATH_OPERATOR, OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, ESCAPE_CHARACTER } from '../../../utils/constants.js';
|
|
11
11
|
import { StringUtils } from '../../../utils/string.js';
|
|
12
|
-
import { MultiValueMap } from '../../../utils/multi-value-map.js';
|
|
13
|
-
import { clone } from '../../../utils/clone.js';
|
|
14
|
-
import { createConversionResult } from '../../base-interfaces/conversion-result.js';
|
|
15
|
-
import '../../../utils/adblockers.js';
|
|
16
12
|
import 'json5';
|
|
17
|
-
import 'sprintf-js';
|
|
18
13
|
import '@adguard/css-tokenizer';
|
|
19
|
-
import
|
|
20
|
-
import '../../../parser/css/balancing.js';
|
|
14
|
+
import 'sprintf-js';
|
|
21
15
|
import '../../data/css.js';
|
|
22
|
-
import '
|
|
16
|
+
import '../../../parser/css/balancing.js';
|
|
17
|
+
import { DomainListParser } from '../../../parser/misc/domain-list-parser.js';
|
|
23
18
|
import 'is-ip';
|
|
19
|
+
import 'tldts';
|
|
20
|
+
import { clone } from '../../../utils/clone.js';
|
|
21
|
+
import { MultiValueMap } from '../../../utils/multi-value-map.js';
|
|
22
|
+
import { RegExpUtils } from '../../../utils/regexp.js';
|
|
23
|
+
import { createConversionResult } from '../../base-interfaces/conversion-result.js';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @file Cosmetic rule modifier converter from ADG to uBO
|
|
26
|
+
* @file Cosmetic rule modifier converter from ADG to uBO.
|
|
27
27
|
*/
|
|
28
28
|
/**
|
|
29
29
|
* Regular expression pattern for matching the main page
|
|
30
|
-
* https://github.com/gorhill/uBlock/wiki/Procedural-cosmetic-filters#subjectmatches-patharg
|
|
30
|
+
* https://github.com/gorhill/uBlock/wiki/Procedural-cosmetic-filters#subjectmatches-patharg.
|
|
31
31
|
*/
|
|
32
32
|
const UBO_MAIN_PAGE_MATCHER = '/^/$/';
|
|
33
33
|
/**
|
|
34
|
-
* Special characters in modifier regexps that should be escaped
|
|
34
|
+
* Special characters in modifier regexps that should be escaped.
|
|
35
35
|
*/
|
|
36
36
|
const SPECIAL_MODIFIER_REGEX_CHARS = new Set([
|
|
37
37
|
OPEN_SQUARE_BRACKET,
|
|
@@ -40,18 +40,21 @@ const SPECIAL_MODIFIER_REGEX_CHARS = new Set([
|
|
|
40
40
|
ESCAPE_CHARACTER,
|
|
41
41
|
]);
|
|
42
42
|
/**
|
|
43
|
-
* Helper class for converting cosmetic rule modifiers from ADG to uBO
|
|
43
|
+
* Helper class for converting cosmetic rule modifiers from ADG to uBO.
|
|
44
44
|
*/
|
|
45
45
|
class UboCosmeticRuleModifierConverter {
|
|
46
46
|
/**
|
|
47
47
|
* Converts a ADG cosmetic rule modifier list to uBO, if possible.
|
|
48
48
|
*
|
|
49
|
-
* @
|
|
49
|
+
* @see {@link https://github.com/gorhill/uBlock/wiki/Procedural-cosmetic-filters#cosmetic-filter-operators}
|
|
50
|
+
*
|
|
51
|
+
* @param modifierList Cosmetic rule modifier list node to convert.
|
|
52
|
+
*
|
|
50
53
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
51
54
|
* the converted node, and its `isConverted` flag indicates whether the original node was converted.
|
|
52
|
-
* If the node was not converted, the result will contain the original node with the same object reference
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
+
* If the node was not converted, the result will contain the original node with the same object reference.
|
|
56
|
+
*
|
|
57
|
+
* @throws If the modifier list cannot be converted.
|
|
55
58
|
*/
|
|
56
59
|
static convertFromAdg(modifierList) {
|
|
57
60
|
const conversionMap = new MultiValueMap();
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import { CosmeticRuleSeparator } from '../../nodes/index.js';
|
|
8
|
-
import { RuleConverterBase } from '../base-interfaces/rule-converter-base.js';
|
|
9
|
-
import { AdblockSyntax } from '../../utils/adblockers.js';
|
|
10
|
-
import { QuoteUtils, QuoteType } from '../../utils/quotes.js';
|
|
11
|
-
import { EMPTY, ADG_DOMAINS_MODIFIER, PIPE_MODIFIER_SEPARATOR, SPACE } from '../../utils/constants.js';
|
|
12
|
-
import { getScriptletName, setScriptletName, transformAllScriptletArguments, setScriptletQuoteType, transformNthScriptletArgument } from '../../ast-utils/scriptlets.js';
|
|
13
|
-
import { RuleConversionError } from '../../errors/rule-conversion-error.js';
|
|
14
|
-
import { createNodeConversionResult } from '../base-interfaces/conversion-result.js';
|
|
15
7
|
import { cloneScriptletRuleNode, cloneDomainListNode, cloneModifierListNode } from '../../ast-utils/clone.js';
|
|
8
|
+
import { getScriptletName, setScriptletName, transformAllScriptletArguments, setScriptletQuoteType, transformNthScriptletArgument } from '../../ast-utils/scriptlets.js';
|
|
16
9
|
import '../../compatibility-tables/modifiers.js';
|
|
17
10
|
import '../../compatibility-tables/redirects.js';
|
|
18
11
|
import { scriptletsCompatibilityTable } from '../../compatibility-tables/scriptlets.js';
|
|
@@ -25,18 +18,25 @@ import '../../compatibility-tables/schemas/platform.js';
|
|
|
25
18
|
import '../../compatibility-tables/utils/platform-helpers.js';
|
|
26
19
|
import '../../compatibility-tables/schemas/resource-type.js';
|
|
27
20
|
import '../../compatibility-tables/utils/resource-type-helpers.js';
|
|
21
|
+
import { RuleConversionError } from '../../errors/rule-conversion-error.js';
|
|
22
|
+
import { CosmeticRuleSeparator } from '../../nodes/index.js';
|
|
23
|
+
import { AdblockSyntax } from '../../utils/adblockers.js';
|
|
24
|
+
import { EMPTY, ADG_DOMAINS_MODIFIER, PIPE_MODIFIER_SEPARATOR, SPACE } from '../../utils/constants.js';
|
|
28
25
|
import { isUndefined, isNull } from '../../utils/type-guards.js';
|
|
29
26
|
import 'json5';
|
|
30
|
-
import 'sprintf-js';
|
|
31
27
|
import '@adguard/css-tokenizer';
|
|
32
|
-
import
|
|
33
|
-
import '../../parser/css/balancing.js';
|
|
28
|
+
import 'sprintf-js';
|
|
34
29
|
import '../data/css.js';
|
|
35
|
-
import '
|
|
30
|
+
import '../../parser/css/balancing.js';
|
|
31
|
+
import { DomainListParser } from '../../parser/misc/domain-list-parser.js';
|
|
32
|
+
import { QuoteUtils, QuoteType } from '../../utils/quotes.js';
|
|
36
33
|
import 'is-ip';
|
|
34
|
+
import 'tldts';
|
|
35
|
+
import { createNodeConversionResult } from '../base-interfaces/conversion-result.js';
|
|
36
|
+
import { RuleConverterBase } from '../base-interfaces/rule-converter-base.js';
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @file Scriptlet injection rule converter
|
|
39
|
+
* @file Scriptlet injection rule converter.
|
|
40
40
|
*/
|
|
41
41
|
const ABP_SCRIPTLET_PREFIX = 'abp-';
|
|
42
42
|
const UBO_SCRIPTLET_PREFIX = 'ubo-';
|
|
@@ -68,19 +68,21 @@ const REMOVE_ATTR_CLASS_APPLYING = new Set([
|
|
|
68
68
|
'complete',
|
|
69
69
|
]);
|
|
70
70
|
/**
|
|
71
|
-
* Scriptlet injection rule converter class
|
|
71
|
+
* Scriptlet injection rule converter class.
|
|
72
72
|
*
|
|
73
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
73
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
74
74
|
*/
|
|
75
75
|
class ScriptletRuleConverter extends RuleConverterBase {
|
|
76
76
|
/**
|
|
77
77
|
* Converts a scriptlet injection rule to AdGuard format, if possible.
|
|
78
78
|
*
|
|
79
|
-
* @param rule Rule node to convert
|
|
79
|
+
* @param rule Rule node to convert.
|
|
80
|
+
*
|
|
80
81
|
* @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
|
|
81
82
|
* the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
|
|
82
|
-
* If the rule was not converted, the result array will contain the original node with the same object reference
|
|
83
|
-
*
|
|
83
|
+
* If the rule was not converted, the result array will contain the original node with the same object reference.
|
|
84
|
+
*
|
|
85
|
+
* @throws If the rule is invalid or cannot be converted.
|
|
84
86
|
*/
|
|
85
87
|
static convertToAdg(rule) {
|
|
86
88
|
// Ignore AdGuard rules
|
|
@@ -226,11 +228,13 @@ class ScriptletRuleConverter extends RuleConverterBase {
|
|
|
226
228
|
/**
|
|
227
229
|
* Converts a scriptlet injection rule to uBlock format, if possible.
|
|
228
230
|
*
|
|
229
|
-
* @param rule Rule node to convert
|
|
231
|
+
* @param rule Rule node to convert.
|
|
232
|
+
*
|
|
230
233
|
* @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
|
|
231
234
|
* the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
|
|
232
|
-
* If the rule was not converted, the result array will contain the original node with the same object reference
|
|
233
|
-
*
|
|
235
|
+
* If the rule was not converted, the result array will contain the original node with the same object reference.
|
|
236
|
+
*
|
|
237
|
+
* @throws If the rule is invalid or cannot be converted.
|
|
234
238
|
*/
|
|
235
239
|
static convertToUbo(rule) {
|
|
236
240
|
// Ignore uBlock rules
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
7
|
import { getFormattedTokenName, TokenType } from '@adguard/css-tokenizer';
|
|
8
8
|
import { sprintf } from 'sprintf-js';
|
|
9
|
-
import { EQUALS, COLON, CLOSE_PARENTHESIS, OPEN_PARENTHESIS, COMMA, EMPTY } from '../../utils/constants.js';
|
|
10
|
-
import { LEGACY_EXT_CSS_ATTRIBUTE_PREFIX, ABP_EXT_CSS_PREFIX } from '../data/css.js';
|
|
11
|
-
import { BaseConverter } from '../base-interfaces/base-converter.js';
|
|
12
|
-
import { createConversionResult } from '../base-interfaces/conversion-result.js';
|
|
13
9
|
import { CssTokenStream } from '../../parser/css/css-token-stream.js';
|
|
10
|
+
import { EQUALS, COLON, CLOSE_PARENTHESIS, OPEN_PARENTHESIS, COMMA, EMPTY } from '../../utils/constants.js';
|
|
14
11
|
import '../../utils/adblockers.js';
|
|
15
12
|
import 'tldts';
|
|
16
13
|
import 'glob-to-regexp';
|
|
17
14
|
import { QuoteUtils } from '../../utils/quotes.js';
|
|
18
15
|
import 'json5';
|
|
16
|
+
import { LEGACY_EXT_CSS_ATTRIBUTE_PREFIX, ABP_EXT_CSS_PREFIX } from '../data/css.js';
|
|
19
17
|
import '../../parser/css/balancing.js';
|
|
18
|
+
import { BaseConverter } from '../base-interfaces/base-converter.js';
|
|
19
|
+
import { createConversionResult } from '../base-interfaces/conversion-result.js';
|
|
20
20
|
|
|
21
21
|
const ERROR_MESSAGES = {
|
|
22
22
|
// eslint-disable-next-line max-len
|
|
@@ -40,19 +40,21 @@ const PSEUDO_ELEMENT_NAMES = new Set([
|
|
|
40
40
|
PseudoElements.Before,
|
|
41
41
|
]);
|
|
42
42
|
/**
|
|
43
|
-
* CSS selector converter
|
|
43
|
+
* CSS selector converter.
|
|
44
44
|
*
|
|
45
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
45
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
46
46
|
*/
|
|
47
47
|
class CssSelectorConverter extends BaseConverter {
|
|
48
48
|
/**
|
|
49
|
-
* Converts Extended CSS elements to AdGuard-compatible ones
|
|
49
|
+
* Converts Extended CSS elements to AdGuard-compatible ones.
|
|
50
|
+
*
|
|
51
|
+
* @param selectorList Selector list to convert.
|
|
50
52
|
*
|
|
51
|
-
* @param selectorList Selector list to convert
|
|
52
53
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
53
54
|
* the converted node, and its `isConverted` flag indicates whether the original node was converted.
|
|
54
|
-
* If the node was not converted, the result will contain the original node with the same object reference
|
|
55
|
-
*
|
|
55
|
+
* If the node was not converted, the result will contain the original node with the same object reference.
|
|
56
|
+
*
|
|
57
|
+
* @throws If the rule is invalid or incompatible.
|
|
56
58
|
*/
|
|
57
59
|
static convertToAdg(selectorList) {
|
|
58
60
|
const stream = selectorList instanceof CssTokenStream
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
8
|
* @file Known CSS elements and attributes.
|
|
9
|
-
* TODO: Implement a compatibility table for Extended CSS
|
|
9
|
+
* TODO: Implement a compatibility table for Extended CSS.
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* Legacy Extended CSS attribute prefix.
|
|
@@ -33,18 +33,18 @@ const ABP_EXT_CSS_PREFIX = '-abp';
|
|
|
33
33
|
*/
|
|
34
34
|
const NATIVE_CSS_PSEUDO_CLASSES = new Set([
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
37
|
-
* https://github.com/AdguardTeam/ExtendedCss#extended-css-has
|
|
36
|
+
* Https://developer.mozilla.org/en-US/docs/Web/CSS/:has
|
|
37
|
+
* https://github.com/AdguardTeam/ExtendedCss#extended-css-has.
|
|
38
38
|
*/
|
|
39
39
|
'has',
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* https://github.com/AdguardTeam/ExtendedCss#extended-css-is
|
|
41
|
+
* Https://developer.mozilla.org/en-US/docs/Web/CSS/:is
|
|
42
|
+
* https://github.com/AdguardTeam/ExtendedCss#extended-css-is.
|
|
43
43
|
*/
|
|
44
44
|
'is',
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
* https://github.com/AdguardTeam/ExtendedCss#extended-css-not
|
|
46
|
+
* Https://developer.mozilla.org/en-US/docs/Web/CSS/:not
|
|
47
|
+
* https://github.com/AdguardTeam/ExtendedCss#extended-css-not.
|
|
48
48
|
*/
|
|
49
49
|
'not',
|
|
50
50
|
]);
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import { RuleConverter } from './rule.js';
|
|
8
7
|
import { clone } from '../utils/clone.js';
|
|
9
8
|
import { MultiValueMap } from '../utils/multi-value-map.js';
|
|
10
|
-
import { createConversionResult } from './base-interfaces/conversion-result.js';
|
|
11
9
|
import { BaseConverter } from './base-interfaces/base-converter.js';
|
|
10
|
+
import { createConversionResult } from './base-interfaces/conversion-result.js';
|
|
11
|
+
import { RuleConverter } from './rule.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* @file Adblock filter list converter
|
|
14
|
+
* @file Adblock filter list converter.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
|
-
* Adblock filter list converter class
|
|
17
|
+
* Adblock filter list converter class.
|
|
18
18
|
*
|
|
19
19
|
* This class just provides an extra layer on top of the {@link RuleConverter}
|
|
20
20
|
* and can be used to convert entire filter lists.
|
|
21
21
|
*
|
|
22
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
22
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
23
23
|
* @todo Implement tolerant mode, which will allow to convert a filter list
|
|
24
|
-
* even if some of its rules are invalid
|
|
24
|
+
* even if some of its rules are invalid.
|
|
25
25
|
*/
|
|
26
26
|
class FilterListConverter extends BaseConverter {
|
|
27
27
|
/**
|
|
28
28
|
* Converts an adblock filter list to AdGuard format, if possible.
|
|
29
29
|
*
|
|
30
|
-
* @param filterListNode Filter list node to convert
|
|
30
|
+
* @param filterListNode Filter list node to convert.
|
|
31
31
|
* @param tolerant Indicates whether the converter should be tolerant to invalid rules. If enabled and a rule is
|
|
32
32
|
* invalid, it will be left as is. If disabled and a rule is invalid, the whole filter list will be failed.
|
|
33
33
|
* Defaults to `true`.
|
|
34
|
+
*
|
|
34
35
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
35
36
|
* the converted node, and its `isConverted` flag indicates whether the original node was converted.
|
|
36
|
-
* If the node was not converted, the result will contain the original node with the same object reference
|
|
37
|
-
*
|
|
37
|
+
* If the node was not converted, the result will contain the original node with the same object reference.
|
|
38
|
+
*
|
|
39
|
+
* @throws If the filter list is invalid or cannot be converted (if the tolerant mode is disabled).
|
|
38
40
|
*/
|
|
39
41
|
static convertToAdg(filterListNode, tolerant = true) {
|
|
40
42
|
// Prepare a map to store the converted rules by their index in the filter list
|
package/dist/converter/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import { SEMICOLON, SPACE } from '../../utils/constants.js';
|
|
8
|
-
import { createModifierNode } from '../../ast-utils/modifiers.js';
|
|
9
|
-
import { BaseConverter } from '../base-interfaces/base-converter.js';
|
|
10
|
-
import { RuleConversionError } from '../../errors/rule-conversion-error.js';
|
|
11
|
-
import { MultiValueMap } from '../../utils/multi-value-map.js';
|
|
12
|
-
import { createConversionResult } from '../base-interfaces/conversion-result.js';
|
|
13
7
|
import { cloneModifierListNode } from '../../ast-utils/clone.js';
|
|
8
|
+
import { createModifierNode } from '../../ast-utils/modifiers.js';
|
|
14
9
|
import { modifiersCompatibilityTable } from '../../compatibility-tables/modifiers.js';
|
|
15
10
|
import { redirectsCompatibilityTable } from '../../compatibility-tables/redirects.js';
|
|
16
11
|
import '../../compatibility-tables/scriptlets.js';
|
|
@@ -23,7 +18,12 @@ import '../../compatibility-tables/schemas/platform.js';
|
|
|
23
18
|
import '../../compatibility-tables/utils/platform-helpers.js';
|
|
24
19
|
import '../../compatibility-tables/schemas/resource-type.js';
|
|
25
20
|
import { isValidResourceType } from '../../compatibility-tables/utils/resource-type-helpers.js';
|
|
21
|
+
import { RuleConversionError } from '../../errors/rule-conversion-error.js';
|
|
22
|
+
import { SEMICOLON, SPACE } from '../../utils/constants.js';
|
|
23
|
+
import { MultiValueMap } from '../../utils/multi-value-map.js';
|
|
26
24
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
25
|
+
import { BaseConverter } from '../base-interfaces/base-converter.js';
|
|
26
|
+
import { createConversionResult } from '../base-interfaces/conversion-result.js';
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @file Network rule modifier list converter.
|
|
@@ -85,18 +85,20 @@ const ADG_CONVERSION_MAP = new Map([
|
|
|
85
85
|
/**
|
|
86
86
|
* Helper class for converting network rule modifier lists.
|
|
87
87
|
*
|
|
88
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
88
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
89
89
|
*/
|
|
90
90
|
class NetworkRuleModifierListConverter extends BaseConverter {
|
|
91
91
|
/**
|
|
92
92
|
* Converts a network rule modifier list to AdGuard format, if possible.
|
|
93
93
|
*
|
|
94
|
-
* @param modifierList Network rule modifier list node to convert
|
|
95
|
-
* @param isException If `true`, the rule is an exception rule
|
|
94
|
+
* @param modifierList Network rule modifier list node to convert.
|
|
95
|
+
* @param isException If `true`, the rule is an exception rule.
|
|
96
|
+
*
|
|
96
97
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
97
98
|
* the converted node, and its `isConverted` flag indicates whether the original node was converted.
|
|
98
|
-
* If the node was not converted, the result will contain the original node with the same object reference
|
|
99
|
-
*
|
|
99
|
+
* If the node was not converted, the result will contain the original node with the same object reference.
|
|
100
|
+
*
|
|
101
|
+
* @throws If the conversion is not possible.
|
|
100
102
|
*/
|
|
101
103
|
static convertToAdg(modifierList, isException = false) {
|
|
102
104
|
const conversionMap = new MultiValueMap();
|
|
@@ -197,12 +199,14 @@ class NetworkRuleModifierListConverter extends BaseConverter {
|
|
|
197
199
|
/**
|
|
198
200
|
* Converts a network rule modifier list to uBlock format, if possible.
|
|
199
201
|
*
|
|
200
|
-
* @param modifierList Network rule modifier list node to convert
|
|
201
|
-
* @param isException If `true`, the rule is an exception rule
|
|
202
|
+
* @param modifierList Network rule modifier list node to convert.
|
|
203
|
+
* @param isException If `true`, the rule is an exception rule.
|
|
204
|
+
*
|
|
202
205
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
203
206
|
* the converted node, and its `isConverted` flag indicates whether the original node was converted.
|
|
204
|
-
* If the node was not converted, the result will contain the original node with the same object reference
|
|
205
|
-
*
|
|
207
|
+
* If the node was not converted, the result will contain the original node with the same object reference.
|
|
208
|
+
*
|
|
209
|
+
* @throws If the conversion is not possible.
|
|
206
210
|
*/
|
|
207
211
|
// TODO: Optimize
|
|
208
212
|
static convertToUbo(modifierList, isException = false) {
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
7
|
import { NetworkRuleType, RuleCategory } from '../../nodes/index.js';
|
|
8
|
-
import { NetworkRuleModifierListConverter } from '../misc/network-rule-modifier.js';
|
|
9
|
-
import { RuleConverterBase } from '../base-interfaces/rule-converter-base.js';
|
|
10
8
|
import { createNodeConversionResult } from '../base-interfaces/conversion-result.js';
|
|
9
|
+
import { RuleConverterBase } from '../base-interfaces/rule-converter-base.js';
|
|
10
|
+
import { NetworkRuleModifierListConverter } from '../misc/network-rule-modifier.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @file Network rule converter
|
|
13
|
+
* @file Network rule converter.
|
|
14
14
|
*/
|
|
15
15
|
/**
|
|
16
|
-
* Network rule converter class (also known as "basic rule converter")
|
|
16
|
+
* Network rule converter class (also known as "basic rule converter").
|
|
17
17
|
*
|
|
18
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
18
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
19
19
|
*/
|
|
20
20
|
class NetworkRuleConverter extends RuleConverterBase {
|
|
21
21
|
/**
|
|
22
22
|
* Converts a network rule to AdGuard format, if possible.
|
|
23
23
|
*
|
|
24
|
-
* @param rule Rule node to convert
|
|
24
|
+
* @param rule Rule node to convert.
|
|
25
|
+
*
|
|
25
26
|
* @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
|
|
26
27
|
* the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
|
|
27
|
-
* If the rule was not converted, the result array will contain the original node with the same object reference
|
|
28
|
-
*
|
|
28
|
+
* If the rule was not converted, the result array will contain the original node with the same object reference.
|
|
29
|
+
*
|
|
30
|
+
* @throws If the rule is invalid or cannot be converted.
|
|
29
31
|
*/
|
|
30
32
|
static convertToAdg(rule) {
|
|
31
33
|
// TODO: add support for host rules
|
|
@@ -59,11 +61,13 @@ class NetworkRuleConverter extends RuleConverterBase {
|
|
|
59
61
|
/**
|
|
60
62
|
* Converts a network rule to uBlock format, if possible.
|
|
61
63
|
*
|
|
62
|
-
* @param rule Rule node to convert
|
|
64
|
+
* @param rule Rule node to convert.
|
|
65
|
+
*
|
|
63
66
|
* @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
|
|
64
67
|
* the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
|
|
65
|
-
* If the rule was not converted, the result array will contain the original node with the same object reference
|
|
66
|
-
*
|
|
68
|
+
* If the rule was not converted, the result array will contain the original node with the same object reference.
|
|
69
|
+
*
|
|
70
|
+
* @throws If the rule is invalid or cannot be converted.
|
|
67
71
|
*/
|
|
68
72
|
static convertToUbo(rule) {
|
|
69
73
|
// TODO: add support for host rules
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import { BaseConverter } from './base-interfaces/base-converter.js';
|
|
7
|
+
import { FilterListGenerator } from '../generator/filterlist-generator.js';
|
|
9
8
|
import { FilterListParser } from '../parser/filterlist-parser.js';
|
|
10
|
-
import { FilterListConverter } from './filter-list.js';
|
|
11
9
|
import { defaultParserOptions } from '../parser/options.js';
|
|
12
|
-
import {
|
|
10
|
+
import { BaseConverter } from './base-interfaces/base-converter.js';
|
|
11
|
+
import { createConversionResult } from './base-interfaces/conversion-result.js';
|
|
12
|
+
import { FilterListConverter } from './filter-list.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @file Filter list converter for raw filter lists
|
|
15
|
+
* @file Filter list converter for raw filter lists.
|
|
16
16
|
*
|
|
17
17
|
* Technically, this is a wrapper around `FilterListConverter` that works with nodes instead of strings.
|
|
18
18
|
*/
|
|
@@ -23,20 +23,22 @@ import { FilterListGenerator } from '../generator/filterlist-generator.js';
|
|
|
23
23
|
* This class just provides an extra layer on top of the {@link FilterListConverter} and calls the parser/serializer
|
|
24
24
|
* before/after the conversion internally.
|
|
25
25
|
*
|
|
26
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
26
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
27
27
|
*/
|
|
28
28
|
class RawFilterListConverter extends BaseConverter {
|
|
29
29
|
/**
|
|
30
30
|
* Converts an adblock filter list text to AdGuard format, if possible.
|
|
31
31
|
*
|
|
32
|
-
* @param rawFilterList Raw filter list text to convert
|
|
32
|
+
* @param rawFilterList Raw filter list text to convert.
|
|
33
33
|
* @param tolerant Indicates whether the converter should be tolerant to invalid rules. If enabled and a rule is
|
|
34
34
|
* invalid, it will be left as is. If disabled and a rule is invalid, the whole filter list will be failed.
|
|
35
35
|
* Defaults to `true`.
|
|
36
|
+
*
|
|
36
37
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
37
38
|
* the array of converted filter list text, and its `isConverted` flag indicates whether the original rule was
|
|
38
|
-
* converted. If the rule was not converted, the original filter list text will be returned
|
|
39
|
-
*
|
|
39
|
+
* converted. If the rule was not converted, the original filter list text will be returned.
|
|
40
|
+
*
|
|
41
|
+
* @throws If the filter list is invalid or cannot be converted (if the tolerant mode is disabled).
|
|
40
42
|
*/
|
|
41
43
|
static convertToAdg(rawFilterList, tolerant = true) {
|
|
42
44
|
const conversionResult = FilterListConverter.convertToAdg(FilterListParser.parse(rawFilterList, {
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree v4.0.
|
|
2
|
+
* AGTree v4.0.2 (build date: Tue, 17 Mar 2026 23:34:38 GMT)
|
|
3
3
|
* (c) 2026 Adguard Software Ltd.
|
|
4
4
|
* Released under the MIT license
|
|
5
5
|
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
6
|
*/
|
|
7
|
-
import { createConversionResult } from './base-interfaces/conversion-result.js';
|
|
8
|
-
import { RuleParser } from '../parser/rule-parser.js';
|
|
9
|
-
import { RuleConverter } from './rule.js';
|
|
10
|
-
import { BaseConverter } from './base-interfaces/base-converter.js';
|
|
11
7
|
import { RuleGenerator } from '../generator/rule-generator.js';
|
|
12
8
|
import '../utils/adblockers.js';
|
|
13
9
|
import 'tldts';
|
|
14
10
|
import 'glob-to-regexp';
|
|
15
|
-
import 'sprintf-js';
|
|
16
11
|
import '@adguard/css-tokenizer';
|
|
12
|
+
import 'sprintf-js';
|
|
17
13
|
import 'json5';
|
|
18
|
-
import '../parser/css/balancing.js';
|
|
19
14
|
import './data/css.js';
|
|
15
|
+
import '../parser/css/balancing.js';
|
|
16
|
+
import { RuleParser } from '../parser/rule-parser.js';
|
|
17
|
+
import { BaseConverter } from './base-interfaces/base-converter.js';
|
|
18
|
+
import { createConversionResult } from './base-interfaces/conversion-result.js';
|
|
19
|
+
import { RuleConverter } from './rule.js';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* @file Rule converter for raw rules
|
|
22
|
+
* @file Rule converter for raw rules.
|
|
23
23
|
*
|
|
24
24
|
* Technically, this is a wrapper around `RuleConverter` that works with nodes instead of strings.
|
|
25
25
|
*/
|
|
@@ -30,17 +30,19 @@ import './data/css.js';
|
|
|
30
30
|
* This class just provides an extra layer on top of the {@link RuleConverter} and calls the parser/serializer
|
|
31
31
|
* before/after the conversion internally.
|
|
32
32
|
*
|
|
33
|
-
* @todo Implement `convertToUbo` and `convertToAbp
|
|
33
|
+
* @todo Implement `convertToUbo` and `convertToAbp`.
|
|
34
34
|
*/
|
|
35
35
|
class RawRuleConverter extends BaseConverter {
|
|
36
36
|
/**
|
|
37
37
|
* Converts an adblock filtering rule to AdGuard format, if possible.
|
|
38
38
|
*
|
|
39
|
-
* @param rawRule Raw rule text to convert
|
|
39
|
+
* @param rawRule Raw rule text to convert.
|
|
40
|
+
*
|
|
40
41
|
* @returns An object which follows the {@link ConversionResult} interface. Its `result` property contains
|
|
41
42
|
* the array of converted rule texts, and its `isConverted` flag indicates whether the original rule was converted.
|
|
42
|
-
* If the rule was not converted, the original rule text will be returned
|
|
43
|
-
*
|
|
43
|
+
* If the rule was not converted, the original rule text will be returned.
|
|
44
|
+
*
|
|
45
|
+
* @throws If the rule is invalid or cannot be converted.
|
|
44
46
|
*/
|
|
45
47
|
static convertToAdg(rawRule) {
|
|
46
48
|
const conversionResult = RuleConverter.convertToAdg(RuleParser.parse(rawRule));
|