@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,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,11 +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 { sprintf } from 'sprintf-js';
|
|
8
7
|
import { getFormattedTokenName } from '@adguard/css-tokenizer';
|
|
8
|
+
import { sprintf } from 'sprintf-js';
|
|
9
9
|
import { AdblockSyntaxError } from '../../../../errors/adblock-syntax-error.js';
|
|
10
10
|
import { GREATER_THAN, PLUS, TILDE, COMMA, SPACE } from '../../../../utils/constants.js';
|
|
11
11
|
|
|
@@ -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,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
|
|
@@ -58,6 +58,8 @@ class PseudoClassSelectorHandler {
|
|
|
58
58
|
}
|
|
59
59
|
// If it's a function, parse its argument
|
|
60
60
|
if (isFunction) {
|
|
61
|
+
// Save the function token's balance level for finding the matching close parenthesis
|
|
62
|
+
const functionBalance = stream.getBalance();
|
|
61
63
|
// Advance pseudo-class selector name token
|
|
62
64
|
stream.advance();
|
|
63
65
|
// Get pseudo-class selector argument token
|
|
@@ -78,8 +80,8 @@ class PseudoClassSelectorHandler {
|
|
|
78
80
|
token = stream.getOrFail();
|
|
79
81
|
// Check if there is any argument part
|
|
80
82
|
if (token.type !== TokenType.CloseParenthesis) {
|
|
81
|
-
//
|
|
82
|
-
const balance =
|
|
83
|
+
// Use the function token's balance level to find the matching closing parenthesis
|
|
84
|
+
const balance = functionBalance;
|
|
83
85
|
// Skip leading whitespace
|
|
84
86
|
stream.skipWhitespace();
|
|
85
87
|
// Get argument token
|
|
@@ -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,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
|
|
@@ -11,24 +11,24 @@ import { SPACE, TILDE, PLUS, GREATER_THAN, DOT, ASTERISK } from '../../../utils/
|
|
|
11
11
|
import { BaseParser } from '../../base-parser.js';
|
|
12
12
|
import { CssTokenStream } from '../../css/css-token-stream.js';
|
|
13
13
|
import { defaultParserOptions } from '../../options.js';
|
|
14
|
-
import { TypeSelectorHandler } from './handlers/type-selector-handler.js';
|
|
15
|
-
import { IdSelectorHandler } from './handlers/id-selector-handler.js';
|
|
16
14
|
import { AttributeSelectorHandler } from './handlers/attribute-selector-handler.js';
|
|
17
|
-
import { PseudoClassSelectorHandler } from './handlers/pseudo-class-selector-handler.js';
|
|
18
15
|
import { ClassSelectorHandler } from './handlers/class-selector-handler.js';
|
|
19
|
-
import { CompoundSelectorHandler } from './handlers/compound-selector-handler.js';
|
|
20
16
|
import { ComplexSelectorHandler } from './handlers/complex-selector-handler.js';
|
|
17
|
+
import { CompoundSelectorHandler } from './handlers/compound-selector-handler.js';
|
|
18
|
+
import { IdSelectorHandler } from './handlers/id-selector-handler.js';
|
|
19
|
+
import { PseudoClassSelectorHandler } from './handlers/pseudo-class-selector-handler.js';
|
|
20
|
+
import { TypeSelectorHandler } from './handlers/type-selector-handler.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Class responsible for parsing selector lists.
|
|
24
24
|
*
|
|
25
25
|
* Please note that the parser will parse any selector list if it is syntactically correct.
|
|
26
|
-
* For example, it will parse this
|
|
26
|
+
* For example, it will parse this:.
|
|
27
27
|
* ```adblock
|
|
28
28
|
* div[attr1="value1"] > h1[attr2="value2"], span[attr3="value3"]
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
31
|
-
*
|
|
31
|
+
* But it didn't check if the given attribute or pseudo-class is valid or not..
|
|
32
32
|
*
|
|
33
33
|
* @see {@link https://www.w3.org/TR/selectors-4/#selector-list}'
|
|
34
34
|
*/
|
|
@@ -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
|
|
@@ -8,9 +8,9 @@ import { TokenType } from '@adguard/css-tokenizer';
|
|
|
8
8
|
import { REMOVE_PROPERTY, REMOVE_VALUE } from '../../converter/data/css.js';
|
|
9
9
|
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
10
10
|
import { CSS_MEDIA_MARKER, EMPTY } from '../../utils/constants.js';
|
|
11
|
-
import { CssTokenStream } from './css-token-stream.js';
|
|
12
|
-
import { defaultParserOptions } from '../options.js';
|
|
13
11
|
import { BaseParser } from '../base-parser.js';
|
|
12
|
+
import { defaultParserOptions } from '../options.js';
|
|
13
|
+
import { CssTokenStream } from './css-token-stream.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @file Parser for AdGuard CSS injections.
|
|
@@ -32,6 +32,7 @@ class AdgCssInjectionParser extends BaseParser {
|
|
|
32
32
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
33
33
|
*
|
|
34
34
|
* @returns Parsed AdGuard CSS injection {@link CssInjectionRuleBody}.
|
|
35
|
+
*
|
|
35
36
|
* @throws An {@link AdblockSyntaxError} if the selector list is syntactically invalid.
|
|
36
37
|
*/
|
|
37
38
|
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
@@ -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
|
|
@@ -32,13 +32,15 @@ const functionTokenPairs = new Map([
|
|
|
32
32
|
/**
|
|
33
33
|
* Helper function to tokenize and ensure balanced pairs.
|
|
34
34
|
*
|
|
35
|
-
* @param raw Raw CSS string to tokenize
|
|
36
|
-
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter
|
|
37
|
-
* @param onError Error callback which is called when a parsing error is found (optional)
|
|
38
|
-
* @param functionHandlers Custom function handlers (optional)
|
|
39
|
-
* @param tokenPairs Map of opening tokens to their corresponding closing tokens
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
35
|
+
* @param raw Raw CSS string to tokenize.
|
|
36
|
+
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter.
|
|
37
|
+
* @param onError Error callback which is called when a parsing error is found (optional).
|
|
38
|
+
* @param functionHandlers Custom function handlers (optional).
|
|
39
|
+
* @param tokenPairs Map of opening tokens to their corresponding closing tokens.
|
|
40
|
+
*
|
|
41
|
+
* @throws If the input is not balanced.
|
|
42
|
+
*
|
|
43
|
+
* @todo Consider adding a `tolerant` flag if error throwing seems too aggressive in the future.
|
|
42
44
|
*/
|
|
43
45
|
const tokenizeWithBalancedPairs = (raw, onToken, onError = () => { }, functionHandlers, tokenPairs = standardTokenPairs) => {
|
|
44
46
|
const stack = [];
|
|
@@ -69,11 +71,12 @@ const tokenizeWithBalancedPairs = (raw, onToken, onError = () => { }, functionHa
|
|
|
69
71
|
/**
|
|
70
72
|
* Tokenize and ensure balanced pairs for standard CSS.
|
|
71
73
|
*
|
|
72
|
-
* @param raw Raw CSS string to tokenize
|
|
73
|
-
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter
|
|
74
|
-
* @param onError Error callback which is called when a parsing error is found (optional)
|
|
75
|
-
* @param functionHandlers Custom function handlers (optional)
|
|
76
|
-
*
|
|
74
|
+
* @param raw Raw CSS string to tokenize.
|
|
75
|
+
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter.
|
|
76
|
+
* @param onError Error callback which is called when a parsing error is found (optional).
|
|
77
|
+
* @param functionHandlers Custom function handlers (optional).
|
|
78
|
+
*
|
|
79
|
+
* @throws If the input is not balanced.
|
|
77
80
|
*/
|
|
78
81
|
const tokenizeBalanced = (raw, onToken, onError = () => { }, functionHandlers) => {
|
|
79
82
|
tokenizeWithBalancedPairs(raw, onToken, onError, functionHandlers);
|
|
@@ -81,11 +84,12 @@ const tokenizeBalanced = (raw, onToken, onError = () => { }, functionHandlers) =
|
|
|
81
84
|
/**
|
|
82
85
|
* Tokenize and ensure balanced pairs for function calls.
|
|
83
86
|
*
|
|
84
|
-
* @param raw Raw CSS string to tokenize
|
|
85
|
-
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter
|
|
86
|
-
* @param onError Error callback which is called when a parsing error is found (optional)
|
|
87
|
-
* @param functionHandlers Custom function handlers (optional)
|
|
88
|
-
*
|
|
87
|
+
* @param raw Raw CSS string to tokenize.
|
|
88
|
+
* @param onToken Callback which will be invoked for each token, extended with a `balance` parameter.
|
|
89
|
+
* @param onError Error callback which is called when a parsing error is found (optional).
|
|
90
|
+
* @param functionHandlers Custom function handlers (optional).
|
|
91
|
+
*
|
|
92
|
+
* @throws If the input is not balanced.
|
|
89
93
|
*/
|
|
90
94
|
const tokenizeFnBalanced = (raw, onToken, onError = () => { }, functionHandlers) => {
|
|
91
95
|
tokenizeWithBalancedPairs(raw, onToken, onError, functionHandlers, functionTokenPairs);
|
|
@@ -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,16 @@
|
|
|
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 { TokenType, getFormattedTokenName, tokenizeExtended } from '@adguard/css-tokenizer';
|
|
8
8
|
import { sprintf } from 'sprintf-js';
|
|
9
|
-
import {
|
|
10
|
-
import { EMPTY } from '../../utils/constants.js';
|
|
9
|
+
import { EXT_CSS_PSEUDO_CLASSES, EXT_CSS_PSEUDO_CLASSES_STRICT, NATIVE_CSS_PSEUDO_CLASSES, LEGACY_EXT_CSS_ATTRIBUTE_PREFIX, ABP_EXT_CSS_PREFIX } from '../../converter/data/css.js';
|
|
11
10
|
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
11
|
+
import { EMPTY } from '../../utils/constants.js';
|
|
12
|
+
import { tokenizeBalanced } from './balancing.js';
|
|
12
13
|
import { ERROR_MESSAGES, END_OF_INPUT } from './constants.js';
|
|
13
|
-
import { EXT_CSS_PSEUDO_CLASSES, EXT_CSS_PSEUDO_CLASSES_STRICT, NATIVE_CSS_PSEUDO_CLASSES, LEGACY_EXT_CSS_ATTRIBUTE_PREFIX, ABP_EXT_CSS_PREFIX } from '../../converter/data/css.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @file CSS token stream.
|
|
@@ -92,6 +92,7 @@ class CssTokenStream {
|
|
|
92
92
|
* Gets the token at the specified index.
|
|
93
93
|
*
|
|
94
94
|
* @param index The index of the token to retrieve.
|
|
95
|
+
*
|
|
95
96
|
* @returns The token at the specified index or undefined if the index is out of bounds.
|
|
96
97
|
*/
|
|
97
98
|
get(index = this.index) {
|
|
@@ -101,7 +102,9 @@ class CssTokenStream {
|
|
|
101
102
|
* Gets the token at the specified index or throws if no token is found at the specified index.
|
|
102
103
|
*
|
|
103
104
|
* @param index The index of the token to retrieve.
|
|
105
|
+
*
|
|
104
106
|
* @returns The token at the specified index or undefined if the index is out of bounds.
|
|
107
|
+
*
|
|
105
108
|
* @throws If no token is found at the specified index.
|
|
106
109
|
*/
|
|
107
110
|
getOrFail(index = this.index) {
|
|
@@ -115,6 +118,7 @@ class CssTokenStream {
|
|
|
115
118
|
* Gets the source fragment of the token at the specified index.
|
|
116
119
|
*
|
|
117
120
|
* @param index The index of the token to retrieve the fragment for.
|
|
121
|
+
*
|
|
118
122
|
* @returns The source fragment of the token or an empty string if the index is out of bounds.
|
|
119
123
|
*/
|
|
120
124
|
fragment(index = this.index) {
|
|
@@ -140,6 +144,7 @@ class CssTokenStream {
|
|
|
140
144
|
* Looks ahead in the stream without changing the index.
|
|
141
145
|
*
|
|
142
146
|
* @param index The relative index to look ahead to, starting from the current index.
|
|
147
|
+
*
|
|
143
148
|
* @returns The next token or undefined if the end of the stream is reached.
|
|
144
149
|
*/
|
|
145
150
|
lookahead(index = 1) {
|
|
@@ -149,6 +154,7 @@ class CssTokenStream {
|
|
|
149
154
|
* Looks behind in the stream without changing the index.
|
|
150
155
|
*
|
|
151
156
|
* @param index The relative index to look behind to, starting from the current index.
|
|
157
|
+
*
|
|
152
158
|
* @returns The previous token or undefined if the current token is the first in the stream.
|
|
153
159
|
*/
|
|
154
160
|
lookbehind(index = 1) {
|
|
@@ -207,6 +213,7 @@ class CssTokenStream {
|
|
|
207
213
|
*
|
|
208
214
|
* @param type The type of token to skip until.
|
|
209
215
|
* @param balance The balance level of the token to skip until.
|
|
216
|
+
*
|
|
210
217
|
* @returns The number of tokens skipped.
|
|
211
218
|
*/
|
|
212
219
|
skipUntil(type, balance) {
|
|
@@ -225,6 +232,7 @@ class CssTokenStream {
|
|
|
225
232
|
*
|
|
226
233
|
* @param type The type of token to skip until.
|
|
227
234
|
* @param balance The balance level of the token to skip until.
|
|
235
|
+
*
|
|
228
236
|
* @returns An array containing the number of tokens skipped and the number of tokens skipped without leading and
|
|
229
237
|
* trailing whitespace tokens.
|
|
230
238
|
*/
|
|
@@ -268,6 +276,7 @@ class CssTokenStream {
|
|
|
268
276
|
*
|
|
269
277
|
* @param type The expected token type.
|
|
270
278
|
* @param data Optional expectation data.
|
|
279
|
+
*
|
|
271
280
|
* @throws If the end of the stream is reached or if the token type or expectation data does not match.
|
|
272
281
|
*/
|
|
273
282
|
expect(type, data) {
|
|
@@ -289,6 +298,7 @@ class CssTokenStream {
|
|
|
289
298
|
* Gets the balance level of the token at the specified index.
|
|
290
299
|
*
|
|
291
300
|
* @param index The index of the token to retrieve the balance level for.
|
|
301
|
+
*
|
|
292
302
|
* @returns The balance level of the token or 0 if the index is out of bounds.
|
|
293
303
|
*/
|
|
294
304
|
getBalance(index = this.index) {
|
|
@@ -327,6 +337,7 @@ class CssTokenStream {
|
|
|
327
337
|
* and don't need the full `CssTokenStream` functionality.
|
|
328
338
|
*
|
|
329
339
|
* @param selector CSS selector string to check.
|
|
340
|
+
*
|
|
330
341
|
* @returns True if the selector contains `:has()`, `:is()`, or `:not()`,
|
|
331
342
|
* otherwise false.
|
|
332
343
|
*/
|
|
@@ -1,17 +1,17 @@
|
|
|
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 { TokenType, getFormattedTokenName } from '@adguard/css-tokenizer';
|
|
8
8
|
import { sprintf } from 'sprintf-js';
|
|
9
|
+
import { UboPseudoName } from '../../common/ubo-selector-common.js';
|
|
9
10
|
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
10
11
|
import { EMPTY, COLON, OPEN_PARENTHESIS, CSS_NOT_PSEUDO, CLOSE_PARENTHESIS } from '../../utils/constants.js';
|
|
11
|
-
import { tokenizeFnBalanced } from './balancing.js';
|
|
12
|
-
import { defaultParserOptions } from '../options.js';
|
|
13
12
|
import { BaseParser } from '../base-parser.js';
|
|
14
|
-
import {
|
|
13
|
+
import { defaultParserOptions } from '../options.js';
|
|
14
|
+
import { tokenizeFnBalanced } from './balancing.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @file Parser for special uBO selectors.
|
|
@@ -50,6 +50,7 @@ const KNOWN_UBO_MODIFIERS = new Set([
|
|
|
50
50
|
* in the hot path of the parser.
|
|
51
51
|
*
|
|
52
52
|
* @param raw Raw selector string.
|
|
53
|
+
*
|
|
53
54
|
* @returns `true` if the selector has any uBO modifier, `false` otherwise.
|
|
54
55
|
*/
|
|
55
56
|
const hasAnyUboModifier = (raw) => {
|
|
@@ -76,7 +77,9 @@ const hasAnyUboModifier = (raw) => {
|
|
|
76
77
|
*
|
|
77
78
|
* @param name Pseudo name.
|
|
78
79
|
* @param wrapper Wrapper pseudo name (eg. `not`) (optional, defaults to `undefined`).
|
|
80
|
+
*
|
|
79
81
|
* @returns Formatted pseudo name.
|
|
82
|
+
*
|
|
80
83
|
* @example
|
|
81
84
|
* ```ts
|
|
82
85
|
* formatPseudoName('matches-path', 'not'); // => ':not(:matches-path(...))'
|
|
@@ -106,6 +109,7 @@ class UboSelectorParser extends BaseParser {
|
|
|
106
109
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
107
110
|
*
|
|
108
111
|
* @returns Parsed uBO selector {@link UboSelectorParser}.
|
|
112
|
+
*
|
|
109
113
|
* @throws An {@link AdblockSyntaxError} if the selector list is syntactically invalid.
|
|
110
114
|
*/
|
|
111
115
|
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
@@ -1,14 +1,14 @@
|
|
|
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 { RuleParser } from './rule-parser.js';
|
|
8
7
|
import { CR, LF } from '../utils/constants.js';
|
|
9
8
|
import { StringUtils } from '../utils/string.js';
|
|
10
|
-
import { defaultParserOptions } from './options.js';
|
|
11
9
|
import { BaseParser } from './base-parser.js';
|
|
10
|
+
import { defaultParserOptions } from './options.js';
|
|
11
|
+
import { RuleParser } from './rule-parser.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* `FilterListParser` is responsible for parsing a whole adblock filter list (list of rules).
|
|
@@ -21,7 +21,11 @@ class FilterListParser extends BaseParser {
|
|
|
21
21
|
* @param raw Raw input to parse.
|
|
22
22
|
* @param options Global parser options.
|
|
23
23
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
24
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* @returns AST of the source code (list of rules).
|
|
26
|
+
*
|
|
27
|
+
* @throws If one of the rules is syntactically invalid (if `tolerant` is `false`).
|
|
28
|
+
*
|
|
25
29
|
* @example
|
|
26
30
|
* ```js
|
|
27
31
|
* import { readFileSync } from 'fs';
|
|
@@ -33,7 +37,6 @@ class FilterListParser extends BaseParser {
|
|
|
33
37
|
* // Parse the filter list content, then do something with the AST
|
|
34
38
|
* const ast = FilterListParser.parse(content);
|
|
35
39
|
* ```
|
|
36
|
-
* @throws If one of the rules is syntactically invalid (if `tolerant` is `false`)
|
|
37
40
|
*/
|
|
38
41
|
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
39
42
|
// Actual position in the source code
|
package/dist/parser/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,13 +1,13 @@
|
|
|
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 { PIPE } from '../../utils/constants.js';
|
|
8
7
|
import { ListItemNodeType, ListNodeType } from '../../nodes/index.js';
|
|
9
|
-
import {
|
|
8
|
+
import { PIPE } from '../../utils/constants.js';
|
|
10
9
|
import { BaseParser } from '../base-parser.js';
|
|
10
|
+
import { defaultParserOptions } from '../options.js';
|
|
11
11
|
import { ListItemsParser } from './list-items-parser.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -25,6 +25,7 @@ class AppListParser extends BaseParser {
|
|
|
25
25
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
26
26
|
*
|
|
27
27
|
* @returns App list AST.
|
|
28
|
+
*
|
|
28
29
|
* @throws An {@link AdblockSyntaxError} if the app list is syntactically invalid.
|
|
29
30
|
* @throws An {@link Error} if the options are invalid.
|
|
30
31
|
*/
|
|
@@ -1,34 +1,36 @@
|
|
|
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 { COMMA, PIPE } from '../../utils/constants.js';
|
|
8
7
|
import { ListItemNodeType, ListNodeType } from '../../nodes/index.js';
|
|
9
|
-
import {
|
|
8
|
+
import { COMMA, PIPE } from '../../utils/constants.js';
|
|
10
9
|
import { BaseParser } from '../base-parser.js';
|
|
10
|
+
import { defaultParserOptions } from '../options.js';
|
|
11
11
|
import { ListItemsParser } from './list-items-parser.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* `DomainListParser` is responsible for parsing a domain list.
|
|
15
15
|
*
|
|
16
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_domains}
|
|
17
|
+
*
|
|
16
18
|
* @example
|
|
17
19
|
* - If the rule is `example.com,~example.net##.ads`, the domain list is `example.com,~example.net`.
|
|
18
20
|
* - If the rule is `ads.js^$script,domains=example.com|~example.org`, the domain list is `example.com|~example.org`.
|
|
19
21
|
* This parser is responsible for parsing these domain lists.
|
|
20
|
-
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_domains}
|
|
21
22
|
*/
|
|
22
23
|
class DomainListParser extends BaseParser {
|
|
23
24
|
/**
|
|
24
|
-
* Parses a domain list, eg. `example.com,example.org,~example.org
|
|
25
|
+
* Parses a domain list, eg. `example.com,example.org,~example.org`.
|
|
25
26
|
*
|
|
26
27
|
* @param raw Raw input to parse.
|
|
27
28
|
* @param options Global parser options.
|
|
28
29
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
29
|
-
* @param separator Separator character (default: comma)
|
|
30
|
+
* @param separator Separator character (default: comma).
|
|
30
31
|
*
|
|
31
32
|
* @returns Domain list AST.
|
|
33
|
+
*
|
|
32
34
|
* @throws An {@link AdblockSyntaxError} if the domain list is syntactically invalid.
|
|
33
35
|
* @throws An {@link Error} if the options are invalid.
|
|
34
36
|
*/
|
|
@@ -1,14 +1,14 @@
|
|
|
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 { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
7
8
|
import { ListItemNodeType } from '../../nodes/index.js';
|
|
8
|
-
import { defaultParserOptions } from '../options.js';
|
|
9
9
|
import { COMMA, NEGATION_MARKER } from '../../utils/constants.js';
|
|
10
10
|
import { StringUtils } from '../../utils/string.js';
|
|
11
|
-
import {
|
|
11
|
+
import { defaultParserOptions } from '../options.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Prefixes for error messages which are used for parsing of value lists.
|
|
@@ -29,15 +29,17 @@ class ListItemsParser {
|
|
|
29
29
|
* Parses a `raw` modifier value which may be represented as a list of items separated by `separator`.
|
|
30
30
|
* Needed for $app, $denyallow, $domain, $method.
|
|
31
31
|
*
|
|
32
|
+
* @template T Type of the list items.
|
|
33
|
+
*
|
|
32
34
|
* @param raw Raw input to parse.
|
|
33
35
|
* @param options Global parser options.
|
|
34
36
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
35
|
-
* @param separator Separator character (default: comma)
|
|
37
|
+
* @param separator Separator character (default: comma).
|
|
36
38
|
* @param type Type of the list items (default: {@link ListItemNodeType.Domain}).
|
|
37
|
-
* @template T Type of the list items.
|
|
38
39
|
*
|
|
39
40
|
* @returns List of parsed items.
|
|
40
|
-
*
|
|
41
|
+
*
|
|
42
|
+
* @throws An {@link AdblockSyntaxError} if the list is syntactically invalid.
|
|
41
43
|
*
|
|
42
44
|
* @example
|
|
43
45
|
* - parses an app list — `com.example.app|Example.exe`
|
|
@@ -1,15 +1,15 @@
|
|
|
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 {
|
|
7
|
+
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
8
8
|
import { OperatorValue } from '../../nodes/index.js';
|
|
9
9
|
import { UNDERSCORE, OPEN_PARENTHESIS, CLOSE_PARENTHESIS, AMPERSAND, PIPE, EXCLAMATION_MARK } from '../../utils/constants.js';
|
|
10
|
-
import {
|
|
11
|
-
import { defaultParserOptions } from '../options.js';
|
|
10
|
+
import { StringUtils } from '../../utils/string.js';
|
|
12
11
|
import { BaseParser } from '../base-parser.js';
|
|
12
|
+
import { defaultParserOptions } from '../options.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Possible token types in the logical expression.
|
|
@@ -50,10 +50,12 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
50
50
|
/**
|
|
51
51
|
* Split the expression into tokens.
|
|
52
52
|
*
|
|
53
|
-
* @param raw Source code of the expression
|
|
53
|
+
* @param raw Source code of the expression.
|
|
54
54
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
55
|
+
*
|
|
56
|
+
* @returns Token list.
|
|
57
|
+
*
|
|
58
|
+
* @throws {AdblockSyntaxError} If the expression is invalid.
|
|
57
59
|
*/
|
|
58
60
|
static tokenize(raw, baseOffset = 0) {
|
|
59
61
|
const tokens = [];
|
|
@@ -123,8 +125,10 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
123
125
|
* @param raw Raw input to parse.
|
|
124
126
|
* @param options Global parser options.
|
|
125
127
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
128
|
+
*
|
|
129
|
+
* @returns Parsed expression.
|
|
130
|
+
*
|
|
131
|
+
* @throws {AdblockSyntaxError} If the expression is invalid.
|
|
128
132
|
*/
|
|
129
133
|
// TODO: Create a separate TokenStream class
|
|
130
134
|
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
@@ -135,8 +139,9 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
135
139
|
/**
|
|
136
140
|
* Consumes a token of the expected type.
|
|
137
141
|
*
|
|
138
|
-
* @param type Expected token type
|
|
139
|
-
*
|
|
142
|
+
* @param type Expected token type.
|
|
143
|
+
*
|
|
144
|
+
* @returns The consumed token.
|
|
140
145
|
*/
|
|
141
146
|
function consume(type) {
|
|
142
147
|
const token = tokens[tokenIndex];
|
|
@@ -155,7 +160,7 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
155
160
|
/**
|
|
156
161
|
* Parses a variable.
|
|
157
162
|
*
|
|
158
|
-
* @returns Variable node
|
|
163
|
+
* @returns Variable node.
|
|
159
164
|
*/
|
|
160
165
|
function parseVariable() {
|
|
161
166
|
const token = consume(TokenType.Variable);
|
|
@@ -172,9 +177,10 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
172
177
|
/**
|
|
173
178
|
* Parses a binary expression.
|
|
174
179
|
*
|
|
175
|
-
* @param left Left-hand side of the expression
|
|
176
|
-
* @param minPrecedence Minimum precedence of the operator
|
|
177
|
-
*
|
|
180
|
+
* @param left Left-hand side of the expression.
|
|
181
|
+
* @param minPrecedence Minimum precedence of the operator.
|
|
182
|
+
*
|
|
183
|
+
* @returns Binary expression node.
|
|
178
184
|
*/
|
|
179
185
|
function parseBinaryExpression(left, minPrecedence = 0) {
|
|
180
186
|
let node = left;
|
|
@@ -210,7 +216,7 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
210
216
|
/**
|
|
211
217
|
* Parses a parenthesized expression.
|
|
212
218
|
*
|
|
213
|
-
* @returns Parenthesized expression node
|
|
219
|
+
* @returns Parenthesized expression node.
|
|
214
220
|
*/
|
|
215
221
|
function parseParenthesizedExpression() {
|
|
216
222
|
consume(TokenType.Parenthesis);
|
|
@@ -230,8 +236,9 @@ class LogicalExpressionParser extends BaseParser {
|
|
|
230
236
|
/**
|
|
231
237
|
* Parses an expression.
|
|
232
238
|
*
|
|
233
|
-
* @param minPrecedence Minimum precedence of the operator
|
|
234
|
-
*
|
|
239
|
+
* @param minPrecedence Minimum precedence of the operator.
|
|
240
|
+
*
|
|
241
|
+
* @returns Expression node.
|
|
235
242
|
*/
|
|
236
243
|
function parseExpression(minPrecedence = 0) {
|
|
237
244
|
let node;
|
|
@@ -1,13 +1,13 @@
|
|
|
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 { PIPE } from '../../utils/constants.js';
|
|
8
7
|
import { ListItemNodeType, ListNodeType } from '../../nodes/index.js';
|
|
9
|
-
import {
|
|
8
|
+
import { PIPE } from '../../utils/constants.js';
|
|
10
9
|
import { BaseParser } from '../base-parser.js';
|
|
10
|
+
import { defaultParserOptions } from '../options.js';
|
|
11
11
|
import { ListItemsParser } from './list-items-parser.js';
|
|
12
12
|
|
|
13
13
|
const METHOD_LIST_SEPARATOR = PIPE;
|
|
@@ -26,6 +26,7 @@ class MethodListParser extends BaseParser {
|
|
|
26
26
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
27
27
|
*
|
|
28
28
|
* @returns Method list AST.
|
|
29
|
+
*
|
|
29
30
|
* @throws An {@link AdblockSyntaxError} if the method list is syntactically invalid.
|
|
30
31
|
* @throws An {@link Error} if the options are invalid.
|
|
31
32
|
*/
|