@adguard/agtree 3.4.3 → 4.0.1
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/dist/ast-utils/clone.js +2 -2
- package/dist/ast-utils/modifiers.js +2 -2
- package/dist/ast-utils/network-rules.js +2 -2
- package/dist/ast-utils/scriptlets.js +2 -2
- package/dist/common/abp-snippet-injection-body-common.js +2 -2
- package/dist/common/agent-common.js +2 -2
- package/dist/common/ubo-html-filtering-body-common.js +40 -0
- package/dist/common/ubo-selector-common.js +2 -2
- package/dist/compatibility-tables/base.js +2 -2
- package/dist/compatibility-tables/compatibility-table-data.js +2 -2
- package/dist/compatibility-tables/modifiers.js +2 -2
- package/dist/compatibility-tables/platforms.js +2 -2
- package/dist/compatibility-tables/redirects.js +2 -2
- package/dist/compatibility-tables/schemas/base.js +2 -2
- package/dist/compatibility-tables/schemas/modifier.js +2 -2
- package/dist/compatibility-tables/schemas/platform.js +2 -2
- package/dist/compatibility-tables/schemas/redirect.js +2 -2
- package/dist/compatibility-tables/schemas/resource-type.js +2 -2
- package/dist/compatibility-tables/schemas/scriptlet.js +2 -2
- package/dist/compatibility-tables/scriptlets.js +2 -2
- package/dist/compatibility-tables/utils/platform-helpers.js +2 -2
- package/dist/compatibility-tables/utils/resource-type-helpers.js +2 -2
- package/dist/compatibility-tables/utils/zod-camelcase.js +2 -2
- package/dist/converter/base-interfaces/base-converter.js +2 -2
- package/dist/converter/base-interfaces/conversion-result.js +2 -2
- package/dist/converter/base-interfaces/rule-converter-base.js +2 -2
- package/dist/converter/comment/index.js +2 -2
- package/dist/converter/cosmetic/css.js +2 -2
- package/dist/converter/cosmetic/element-hiding.js +2 -2
- package/dist/converter/cosmetic/header-removal.js +24 -42
- package/dist/converter/cosmetic/html.js +580 -438
- package/dist/converter/cosmetic/index.js +3 -2
- package/dist/converter/cosmetic/rule-modifiers/adg.js +2 -2
- package/dist/converter/cosmetic/rule-modifiers/ubo.js +2 -2
- package/dist/converter/cosmetic/scriptlet.js +2 -2
- package/dist/converter/css/index.js +3 -2
- package/dist/converter/data/css.js +32 -54
- package/dist/converter/filter-list.js +2 -2
- package/dist/converter/index.js +2 -2
- package/dist/converter/misc/network-rule-modifier.js +2 -2
- package/dist/converter/network/index.js +2 -2
- package/dist/converter/raw-filter-list.js +2 -2
- package/dist/converter/raw-rule.js +6 -3
- package/dist/converter/rule.js +2 -2
- package/dist/errors/adblock-syntax-error.js +2 -2
- package/dist/errors/binary-schema-mismatch-error.js +2 -2
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/rule-conversion-error.js +2 -2
- package/dist/generator/base-generator.js +2 -2
- package/dist/generator/comment/agent-comment-generator.js +2 -2
- package/dist/generator/comment/agent-generator.js +2 -2
- package/dist/generator/comment/comment-rule-generator.js +2 -2
- package/dist/generator/comment/config-comment-generator.js +2 -2
- package/dist/generator/comment/hint-comment-generator.js +2 -2
- package/dist/generator/comment/hint-generator.js +2 -2
- package/dist/generator/comment/metadata-comment-generator.js +2 -2
- package/dist/generator/comment/pre-processor-comment-generator.js +2 -2
- package/dist/generator/comment/simple-comment-generator.js +2 -2
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +21 -6
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +2 -2
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +2 -2
- package/dist/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.js +38 -0
- package/dist/generator/cosmetic/html-filtering-body/html-filtering-body-generator.js +32 -0
- package/dist/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.js +65 -0
- package/dist/generator/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-generator.js +2 -2
- package/dist/generator/cosmetic/selector/attribute-selector-generator.js +42 -0
- package/dist/generator/cosmetic/selector/class-selector-generator.js +26 -0
- package/dist/generator/cosmetic/selector/complex-selector-generator.js +71 -0
- package/dist/generator/cosmetic/selector/id-selector-generator.js +26 -0
- package/dist/generator/cosmetic/selector/pseudo-class-selector-generator.js +35 -0
- package/dist/generator/cosmetic/selector/selector-combinator-generator.js +30 -0
- package/dist/generator/cosmetic/selector/selector-list-generator.js +41 -0
- package/dist/generator/cosmetic/selector/type-selector-generator.js +25 -0
- package/dist/generator/css/adg-css-injection-generator.js +5 -6
- package/dist/generator/filterlist-generator.js +2 -2
- package/dist/generator/index.js +2 -2
- package/dist/generator/misc/domain-list-generator.js +2 -2
- package/dist/generator/misc/list-items-generator.js +2 -2
- package/dist/generator/misc/logical-expression-generator.js +2 -2
- package/dist/generator/misc/modifier-generator.js +2 -2
- package/dist/generator/misc/modifier-list-generator.js +2 -2
- package/dist/generator/misc/parameter-list-generator.js +2 -2
- package/dist/generator/misc/value-generator.js +2 -2
- package/dist/generator/network/host-rule-generator.js +2 -2
- package/dist/generator/network/network-rule-generator.js +2 -2
- package/dist/generator/rule-generator.js +2 -2
- package/dist/index.js +4 -14
- package/dist/nodes/index.js +2 -2
- package/dist/package.json.js +3 -3
- package/dist/parser/base-parser.js +2 -2
- package/dist/parser/comment/agent-comment-parser.js +2 -2
- package/dist/parser/comment/agent-parser.js +2 -2
- package/dist/parser/comment/comment-parser.js +2 -2
- package/dist/parser/comment/config-comment-parser.js +2 -2
- package/dist/parser/comment/hint-comment-parser.js +2 -2
- package/dist/parser/comment/hint-parser.js +2 -2
- package/dist/parser/comment/metadata-comment-parser.js +2 -2
- package/dist/parser/comment/preprocessor-parser.js +2 -2
- package/dist/parser/comment/simple-comment-parser.js +2 -2
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +10 -21
- package/dist/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.js +49 -0
- package/dist/parser/cosmetic/html-filtering-body/html-filtering-body-parser.js +70 -0
- package/dist/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.js +180 -0
- package/dist/parser/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-parser.js +2 -2
- package/dist/parser/cosmetic/selector/handlers/attribute-selector-handler.js +206 -0
- package/dist/parser/cosmetic/selector/handlers/class-selector-handler.js +48 -0
- package/dist/parser/cosmetic/selector/handlers/complex-selector-handler.js +67 -0
- package/dist/parser/cosmetic/selector/handlers/compound-selector-handler.js +97 -0
- package/dist/parser/cosmetic/selector/handlers/id-selector-handler.js +42 -0
- package/dist/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.js +128 -0
- package/dist/parser/cosmetic/selector/handlers/type-selector-handler.js +58 -0
- package/dist/parser/cosmetic/selector/selector-list-parser.js +164 -0
- package/dist/parser/css/adg-css-injection-parser.js +4 -5
- package/dist/parser/css/balancing.js +2 -2
- package/dist/parser/css/constants.js +2 -2
- package/dist/parser/css/css-token-stream.js +41 -4
- package/dist/parser/css/ubo-selector-parser.js +2 -2
- package/dist/parser/filterlist-parser.js +2 -2
- package/dist/parser/index.js +2 -2
- package/dist/parser/misc/app-list-parser.js +2 -2
- package/dist/parser/misc/domain-list-parser.js +2 -2
- package/dist/parser/misc/list-items-parser.js +2 -2
- package/dist/parser/misc/logical-expression-parser.js +2 -2
- package/dist/parser/misc/method-list-parser.js +2 -2
- package/dist/parser/misc/modifier-list.js +2 -2
- package/dist/parser/misc/modifier-parser.js +2 -2
- package/dist/parser/misc/parameter-list-parser.js +2 -2
- package/dist/parser/misc/stealth-option-list-parser.js +2 -2
- package/dist/parser/misc/ubo-parameter-list-parser.js +2 -2
- package/dist/parser/misc/value-parser.js +2 -2
- package/dist/parser/network/host-rule-parser.js +2 -2
- package/dist/parser/network/network-rule-parser.js +2 -2
- package/dist/parser/options.js +3 -2
- package/dist/parser/rule-parser.js +2 -2
- package/dist/types/common/ubo-html-filtering-body-common.d.ts +12 -0
- package/dist/types/compatibility-tables/compatibility-table-data.d.ts +3 -3
- package/dist/types/compatibility-tables/schemas/redirect.d.ts +1 -1
- package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +2 -2
- package/dist/types/converter/cosmetic/html.d.ts +167 -42
- package/dist/types/converter/data/css.d.ts +18 -6
- package/dist/types/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/html-filtering-body/html-filtering-body-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.d.ts +30 -0
- package/dist/types/generator/cosmetic/selector/attribute-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/class-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/complex-selector-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/selector/id-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/pseudo-class-selector-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/selector-combinator-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/selector/selector-list-generator.d.ts +17 -0
- package/dist/types/generator/cosmetic/selector/type-selector-generator.d.ts +15 -0
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +1 -1
- package/dist/types/index.d.ts +3 -13
- package/dist/types/nodes/index.d.ts +159 -3
- package/dist/types/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.d.ts +35 -0
- package/dist/types/parser/cosmetic/html-filtering-body/html-filtering-body-parser.d.ts +39 -0
- package/dist/types/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.d.ts +63 -0
- package/dist/types/parser/cosmetic/selector/context.d.ts +42 -0
- package/dist/types/parser/cosmetic/selector/handlers/attribute-selector-handler.d.ts +35 -0
- package/dist/types/parser/cosmetic/selector/handlers/class-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/complex-selector-handler.d.ts +20 -0
- package/dist/types/parser/cosmetic/selector/handlers/compound-selector-handler.d.ts +25 -0
- package/dist/types/parser/cosmetic/selector/handlers/id-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/handlers/type-selector-handler.d.ts +15 -0
- package/dist/types/parser/cosmetic/selector/selector-list-parser.d.ts +38 -0
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +0 -2
- package/dist/types/parser/css/css-token-stream.d.ts +18 -0
- package/dist/types/parser/network/network-rule-parser.d.ts +1 -1
- package/dist/types/parser/options.d.ts +5 -0
- package/dist/types/utils/constants.d.ts +1 -0
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/utils/quotes.d.ts +44 -0
- package/dist/types/utils/regexp.d.ts +24 -0
- package/dist/utils/adblockers.js +2 -2
- package/dist/utils/bit-count.js +2 -2
- package/dist/utils/categorizer.js +2 -2
- package/dist/utils/clone.js +2 -2
- package/dist/utils/constants.js +6 -9
- package/dist/utils/cosmetic-rule-separator.js +2 -2
- package/dist/utils/deep-freeze.js +2 -2
- package/dist/utils/domain.js +2 -2
- package/dist/utils/error.js +2 -2
- package/dist/utils/index.js +2 -8
- package/dist/utils/logical-expression.js +2 -2
- package/dist/utils/multi-value-map.js +2 -2
- package/dist/utils/noop-modifier.js +2 -2
- package/dist/utils/position-provider.js +2 -2
- package/dist/utils/quotes.js +163 -10
- package/dist/utils/regexp.js +31 -2
- package/dist/utils/string.js +2 -2
- package/dist/utils/type-guards.js +3 -13
- package/dist/validator/constants.js +2 -2
- package/dist/validator/helpers.js +2 -2
- package/dist/validator/index.js +2 -2
- package/dist/validator/value.js +2 -2
- package/dist/version.js +2 -2
- package/package.json +6 -14
- package/dist/deserializer/base-deserializer.js +0 -29
- package/dist/deserializer/comment/agent-comment-deserializer.js +0 -79
- package/dist/deserializer/comment/agent-deserializer.js +0 -65
- package/dist/deserializer/comment/comment-rule-deserializer.js +0 -54
- package/dist/deserializer/comment/config-comment-deserializer.js +0 -111
- package/dist/deserializer/comment/hint-comment-deserializer.js +0 -72
- package/dist/deserializer/comment/hint-deserializer.js +0 -85
- package/dist/deserializer/comment/metadata-comment-deserializer.js +0 -69
- package/dist/deserializer/comment/pre-processor-comment-deserializer.js +0 -112
- package/dist/deserializer/comment/simple-comment-deserializer.js +0 -65
- package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +0 -131
- package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +0 -56
- package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +0 -48
- package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +0 -39
- package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +0 -40
- package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +0 -54
- package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +0 -38
- package/dist/deserializer/empty-rule-deserializer.js +0 -48
- package/dist/deserializer/filterlist-deserializer.js +0 -85
- package/dist/deserializer/index.js +0 -8
- package/dist/deserializer/invalid-rule-deserializer.js +0 -50
- package/dist/deserializer/invalid-rule-error-node-deserializer.js +0 -50
- package/dist/deserializer/misc/domain-list-deserializer.js +0 -64
- package/dist/deserializer/misc/list-item-deserializer.js +0 -69
- package/dist/deserializer/misc/list-items-deserializer.js +0 -30
- package/dist/deserializer/misc/logical-expression-deserializer.js +0 -196
- package/dist/deserializer/misc/modifier-deserializer.js +0 -87
- package/dist/deserializer/misc/modifier-list-deserializer.js +0 -61
- package/dist/deserializer/misc/parameter-list-deserializer.js +0 -64
- package/dist/deserializer/misc/value-deserializer.js +0 -50
- package/dist/deserializer/network/host-rule-deserializer.js +0 -67
- package/dist/deserializer/network/hostname-list-deserializer.js +0 -56
- package/dist/deserializer/network/network-rule-deserializer.js +0 -65
- package/dist/deserializer/rule-deserializer.js +0 -65
- package/dist/deserializer/syntax-deserialization-map.js +0 -21
- package/dist/marshalling-utils/comment/agent-comment-common.js +0 -21
- package/dist/marshalling-utils/comment/agent-common.js +0 -40
- package/dist/marshalling-utils/comment/config-comment-common.js +0 -54
- package/dist/marshalling-utils/comment/hint-comment-common.js +0 -22
- package/dist/marshalling-utils/comment/hint-common.js +0 -56
- package/dist/marshalling-utils/comment/metadata-comment-common.js +0 -41
- package/dist/marshalling-utils/comment/pre-processor-comment-common.js +0 -59
- package/dist/marshalling-utils/comment/simple-comment-common.js +0 -22
- package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +0 -61
- package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +0 -66
- package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +0 -24
- package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +0 -21
- package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +0 -114
- package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +0 -46
- package/dist/marshalling-utils/empty-rule-common.js +0 -20
- package/dist/marshalling-utils/filter-list-common.js +0 -21
- package/dist/marshalling-utils/invalid-rule-common.js +0 -21
- package/dist/marshalling-utils/invalid-rule-error-node-common.js +0 -22
- package/dist/marshalling-utils/misc/binary-type-common.js +0 -54
- package/dist/marshalling-utils/misc/domain-list-common.js +0 -36
- package/dist/marshalling-utils/misc/host-rule-common.js +0 -24
- package/dist/marshalling-utils/misc/hostname-list-common.js +0 -21
- package/dist/marshalling-utils/misc/list-item-common.js +0 -22
- package/dist/marshalling-utils/misc/logical-expression-common.js +0 -83
- package/dist/marshalling-utils/misc/modifier-common.js +0 -231
- package/dist/marshalling-utils/misc/modifier-list-common.js +0 -21
- package/dist/marshalling-utils/misc/parameter-list-common.js +0 -21
- package/dist/marshalling-utils/misc/value-common.js +0 -22
- package/dist/marshalling-utils/network/network-rule-common.js +0 -24
- package/dist/marshalling-utils/syntax-serialization-map.js +0 -30
- package/dist/serializer/base-serializer.js +0 -29
- package/dist/serializer/comment/agent-comment-serializer.js +0 -74
- package/dist/serializer/comment/agent-serializer.js +0 -59
- package/dist/serializer/comment/comment-rule-serializer.js +0 -105
- package/dist/serializer/comment/config-comment-serializer.js +0 -82
- package/dist/serializer/comment/hint-comment-serializer.js +0 -65
- package/dist/serializer/comment/hint-serializer.js +0 -54
- package/dist/serializer/comment/metadata-comment-serializer.js +0 -73
- package/dist/serializer/comment/pre-processor-comment-serializer.js +0 -71
- package/dist/serializer/comment/simple-comment-serializer.js +0 -52
- package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +0 -50
- package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +0 -36
- package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +0 -120
- package/dist/serializer/cosmetic/css-injection-body-serializer.js +0 -51
- package/dist/serializer/cosmetic/element-hiding-body-serializer.js +0 -40
- package/dist/serializer/empty-rule-serializer.js +0 -37
- package/dist/serializer/filterlist-serializer.js +0 -45
- package/dist/serializer/index.js +0 -7
- package/dist/serializer/invalid-rule-error-node-serializer.js +0 -41
- package/dist/serializer/invalid-rule-serializer.js +0 -40
- package/dist/serializer/misc/domain-list-serializer.js +0 -64
- package/dist/serializer/misc/list-item-serializer.js +0 -58
- package/dist/serializer/misc/list-items-serializer.js +0 -29
- package/dist/serializer/misc/logical-expression-serializer.js +0 -136
- package/dist/serializer/misc/modifier-list-serializer.js +0 -58
- package/dist/serializer/misc/modifier-serializer.js +0 -49
- package/dist/serializer/misc/parameter-list-serializer.js +0 -52
- package/dist/serializer/misc/value-serializer.js +0 -50
- package/dist/serializer/network/host-rule-serializer.js +0 -70
- package/dist/serializer/network/hostname-list-serializer.js +0 -53
- package/dist/serializer/network/network-rule-serializer.js +0 -54
- package/dist/serializer/rule-serializer.js +0 -61
- package/dist/types/deserializer/base-deserializer.d.ts +0 -15
- package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +0 -34
- package/dist/types/deserializer/comment/agent-deserializer.d.ts +0 -25
- package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +0 -27
- package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +0 -24
- package/dist/types/deserializer/comment/hint-deserializer.d.ts +0 -26
- package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +0 -26
- package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +0 -29
- package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +0 -26
- package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +0 -15
- package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +0 -16
- package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +0 -17
- package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +0 -18
- package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +0 -19
- package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +0 -17
- package/dist/types/deserializer/empty-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/filterlist-deserializer.d.ts +0 -34
- package/dist/types/deserializer/index.d.ts +0 -2
- package/dist/types/deserializer/invalid-rule-deserializer.d.ts +0 -16
- package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +0 -16
- package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +0 -15
- package/dist/types/deserializer/misc/list-item-deserializer.d.ts +0 -19
- package/dist/types/deserializer/misc/list-items-deserializer.d.ts +0 -16
- package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +0 -55
- package/dist/types/deserializer/misc/modifier-deserializer.d.ts +0 -18
- package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +0 -20
- package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +0 -18
- package/dist/types/deserializer/misc/value-deserializer.d.ts +0 -17
- package/dist/types/deserializer/network/host-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +0 -15
- package/dist/types/deserializer/network/network-rule-deserializer.d.ts +0 -18
- package/dist/types/deserializer/rule-deserializer.d.ts +0 -17
- package/dist/types/deserializer/syntax-deserialization-map.d.ts +0 -2
- package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +0 -14
- package/dist/types/marshalling-utils/comment/agent-common.d.ts +0 -20
- package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +0 -42
- package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +0 -15
- package/dist/types/marshalling-utils/comment/hint-common.d.ts +0 -33
- package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +0 -21
- package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +0 -37
- package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +0 -15
- package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +0 -23
- package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +0 -9
- package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +0 -17
- package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +0 -14
- package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +0 -9
- package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +0 -28
- package/dist/types/marshalling-utils/empty-rule-common.d.ts +0 -13
- package/dist/types/marshalling-utils/filter-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/invalid-rule-common.d.ts +0 -14
- package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +0 -15
- package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +0 -57
- package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +0 -24
- package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +0 -18
- package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/list-item-common.d.ts +0 -15
- package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +0 -47
- package/dist/types/marshalling-utils/misc/modifier-common.d.ts +0 -41
- package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +0 -14
- package/dist/types/marshalling-utils/misc/value-common.d.ts +0 -15
- package/dist/types/marshalling-utils/network/network-rule-common.d.ts +0 -18
- package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +0 -2
- package/dist/types/serializer/base-serializer.d.ts +0 -15
- package/dist/types/serializer/comment/agent-comment-serializer.d.ts +0 -34
- package/dist/types/serializer/comment/agent-serializer.d.ts +0 -15
- package/dist/types/serializer/comment/comment-rule-serializer.d.ts +0 -68
- package/dist/types/serializer/comment/config-comment-serializer.d.ts +0 -25
- package/dist/types/serializer/comment/hint-comment-serializer.d.ts +0 -23
- package/dist/types/serializer/comment/hint-serializer.d.ts +0 -24
- package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +0 -25
- package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +0 -28
- package/dist/types/serializer/comment/simple-comment-serializer.d.ts +0 -24
- package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +0 -17
- package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +0 -25
- package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +0 -19
- package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +0 -15
- package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +0 -15
- package/dist/types/serializer/empty-rule-serializer.d.ts +0 -15
- package/dist/types/serializer/filterlist-serializer.d.ts +0 -15
- package/dist/types/serializer/index.d.ts +0 -1
- package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +0 -15
- package/dist/types/serializer/invalid-rule-serializer.d.ts +0 -15
- package/dist/types/serializer/misc/domain-list-serializer.d.ts +0 -21
- package/dist/types/serializer/misc/list-item-serializer.d.ts +0 -16
- package/dist/types/serializer/misc/list-items-serializer.d.ts +0 -15
- package/dist/types/serializer/misc/logical-expression-serializer.d.ts +0 -52
- package/dist/types/serializer/misc/modifier-list-serializer.d.ts +0 -20
- package/dist/types/serializer/misc/modifier-serializer.d.ts +0 -18
- package/dist/types/serializer/misc/parameter-list-serializer.d.ts +0 -17
- package/dist/types/serializer/misc/value-serializer.d.ts +0 -17
- package/dist/types/serializer/network/host-rule-serializer.d.ts +0 -30
- package/dist/types/serializer/network/hostname-list-serializer.d.ts +0 -15
- package/dist/types/serializer/network/network-rule-serializer.d.ts +0 -18
- package/dist/types/serializer/rule-serializer.d.ts +0 -17
- package/dist/types/utils/binary-schema-version.d.ts +0 -9
- package/dist/types/utils/byte-buffer.d.ts +0 -54
- package/dist/types/utils/input-byte-buffer.d.ts +0 -146
- package/dist/types/utils/is-chromium.d.ts +0 -7
- package/dist/types/utils/output-byte-buffer.d.ts +0 -132
- package/dist/types/utils/storage-interface.d.ts +0 -23
- package/dist/types/utils/text-decoder-polyfill.d.ts +0 -14
- package/dist/types/utils/text-encoder-polyfill.d.ts +0 -18
- package/dist/utils/binary-schema-version.js +0 -17
- package/dist/utils/byte-buffer.js +0 -91
- package/dist/utils/input-byte-buffer.js +0 -266
- package/dist/utils/is-chromium.js +0 -20
- package/dist/utils/output-byte-buffer.js +0 -231
- package/dist/utils/text-decoder-polyfill.js +0 -107
- package/dist/utils/text-encoder-polyfill.js +0 -78
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-generator.d.ts +0 -0
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-generator.d.ts +0 -0
- /package/dist/types/generator/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-generator.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/abp-snippet-injection-body-parser.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/adg-scriptlet-injection-body-parser.d.ts +0 -0
- /package/dist/types/parser/cosmetic/{body → scriptlet-body}/ubo-scriptlet-injection-body-parser.d.ts +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { getFormattedTokenName } from '@adguard/css-tokenizer';
|
|
8
|
+
import { sprintf } from 'sprintf-js';
|
|
9
|
+
import { AdblockSyntaxError } from '../../../../errors/adblock-syntax-error.js';
|
|
10
|
+
import { CompoundSelectorHandler } from './compound-selector-handler.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Handles complex selector parsing in selector list.
|
|
14
|
+
*/
|
|
15
|
+
class ComplexSelectorHandler {
|
|
16
|
+
/**
|
|
17
|
+
* Finishes the current complex selector by:
|
|
18
|
+
* 1. Finishing current compound selector node via {@link CompoundSelectorHandler},
|
|
19
|
+
* 2. Validating current complex selector node,
|
|
20
|
+
* 3. Appending current complex selector node to the selector list node,
|
|
21
|
+
* If `isEof` is `false`:
|
|
22
|
+
* 4. Constructing next complex selector node.
|
|
23
|
+
*
|
|
24
|
+
* @param context Selector list parser context.
|
|
25
|
+
* @param isEof Indicates whether the end of the file has been reached.
|
|
26
|
+
*
|
|
27
|
+
* @throws If the current compound / complex selector has no simple selectors / compound selectors.
|
|
28
|
+
*/
|
|
29
|
+
static handle(context, isEof = true) {
|
|
30
|
+
const { raw, options, baseOffset, stream, token, result, complexSelector, } = context;
|
|
31
|
+
// Get current complex selector end token
|
|
32
|
+
const currentEndToken = stream.lookbehindForNonWs();
|
|
33
|
+
// Finish current compound selector node
|
|
34
|
+
CompoundSelectorHandler.handle(context);
|
|
35
|
+
// Throw error if current complex selector node has no compound selector nodes (empty)
|
|
36
|
+
if (!currentEndToken || complexSelector.children.length === 0) {
|
|
37
|
+
throw new AdblockSyntaxError(sprintf("Unexpected token '%s' with value '%s'", getFormattedTokenName(token.type), raw.slice(token.start, token.end)), baseOffset + token.start, baseOffset + token.end);
|
|
38
|
+
}
|
|
39
|
+
// Include current complex selector node end location if needed
|
|
40
|
+
if (options.isLocIncluded) {
|
|
41
|
+
complexSelector.end = baseOffset + currentEndToken.end;
|
|
42
|
+
}
|
|
43
|
+
// Append current complex selector node to selector list node
|
|
44
|
+
result.children.push(complexSelector);
|
|
45
|
+
// If EOF is reached, just return, as we don't need to construct a next complex selector node
|
|
46
|
+
if (isEof) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Get next complex selector node start token
|
|
50
|
+
const nextStartToken = stream.getOrFail();
|
|
51
|
+
// Construct next complex selector node
|
|
52
|
+
const nextComplexSelector = {
|
|
53
|
+
type: 'ComplexSelector',
|
|
54
|
+
children: [],
|
|
55
|
+
};
|
|
56
|
+
// Include next complex selector node start location if needed
|
|
57
|
+
if (options.isLocIncluded) {
|
|
58
|
+
nextComplexSelector.start = baseOffset + nextStartToken.start;
|
|
59
|
+
}
|
|
60
|
+
// Update context with new complex selector
|
|
61
|
+
context.complexSelector = nextComplexSelector;
|
|
62
|
+
// Reset type selector set tracker for new selector
|
|
63
|
+
context.isTypeSelectorSet = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { ComplexSelectorHandler };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { sprintf } from 'sprintf-js';
|
|
8
|
+
import { getFormattedTokenName } from '@adguard/css-tokenizer';
|
|
9
|
+
import { AdblockSyntaxError } from '../../../../errors/adblock-syntax-error.js';
|
|
10
|
+
import { GREATER_THAN, PLUS, TILDE, COMMA, SPACE } from '../../../../utils/constants.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Handles compound selector parsing in selector list.
|
|
14
|
+
*/
|
|
15
|
+
class CompoundSelectorHandler {
|
|
16
|
+
/**
|
|
17
|
+
* Set of allowed symbols between selectors (combinators + comma, except <space> combinator).
|
|
18
|
+
*
|
|
19
|
+
* @see {@link SelectorCombinatorValue}
|
|
20
|
+
*/
|
|
21
|
+
static ALLOWED_SYMBOLS_BETWEEN_SELECTORS = new Set([
|
|
22
|
+
// div > span
|
|
23
|
+
GREATER_THAN,
|
|
24
|
+
// div + div
|
|
25
|
+
PLUS,
|
|
26
|
+
// div ~ div
|
|
27
|
+
TILDE,
|
|
28
|
+
// div, span
|
|
29
|
+
COMMA,
|
|
30
|
+
]);
|
|
31
|
+
/**
|
|
32
|
+
* Finishes the current compound selector by:
|
|
33
|
+
* 1. Validating current compound selector node,
|
|
34
|
+
* 2. Constructing selector combinator node (if provided),
|
|
35
|
+
* 3. Appending selector combinator node to the complex selector (if provided).
|
|
36
|
+
*
|
|
37
|
+
* @param context Selector list parser context.
|
|
38
|
+
* @param combinator Optional combinator string.
|
|
39
|
+
*
|
|
40
|
+
* @throws If the current compound selector has no simple selectors.
|
|
41
|
+
*/
|
|
42
|
+
static handle(context, combinator) {
|
|
43
|
+
const { raw, options, baseOffset, stream, token, complexSelector, } = context;
|
|
44
|
+
// Get current compound selector end token
|
|
45
|
+
const currentEndToken = stream.lookbehindForNonWs();
|
|
46
|
+
// Throw error if current compound selector has no simple selectors (empty)
|
|
47
|
+
if (
|
|
48
|
+
// Combinator shouldn't be the first token in the complex selector
|
|
49
|
+
!currentEndToken
|
|
50
|
+
|| complexSelector.children.length === 0
|
|
51
|
+
// And the last token in the complex selector shouldn't be a combinator
|
|
52
|
+
|| complexSelector.children[complexSelector.children.length - 1].type === 'SelectorCombinator') {
|
|
53
|
+
throw new AdblockSyntaxError(sprintf("Unexpected token '%s' with value '%s'", getFormattedTokenName(token.type), raw.slice(token.start, token.end)), baseOffset + token.start, baseOffset + token.end);
|
|
54
|
+
}
|
|
55
|
+
// Handle edge case for descendant combinator
|
|
56
|
+
if (combinator === SPACE) {
|
|
57
|
+
// Skip whitespaces before checking next token
|
|
58
|
+
stream.skipWhitespace();
|
|
59
|
+
// EOF - just skip, we shouldn't consider it as descendant combinator
|
|
60
|
+
if (!stream.get()) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Combinator or Comma - just skip, we shouldn't consider it as descendant combinator
|
|
64
|
+
if (CompoundSelectorHandler.ALLOWED_SYMBOLS_BETWEEN_SELECTORS.has(stream.fragment())) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Advance selector combinator token
|
|
70
|
+
stream.advance();
|
|
71
|
+
// Skip whitespaces after selector combinator token
|
|
72
|
+
stream.skipWhitespace();
|
|
73
|
+
}
|
|
74
|
+
// If no combinator is provided, just return, as we don't need to create and append selector combinator node
|
|
75
|
+
if (!combinator) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Next compound selector token should be defined
|
|
79
|
+
stream.getOrFail();
|
|
80
|
+
// Construct selector combinator node
|
|
81
|
+
const result = {
|
|
82
|
+
type: 'SelectorCombinator',
|
|
83
|
+
value: combinator,
|
|
84
|
+
};
|
|
85
|
+
// Include selector combinator node locations if needed
|
|
86
|
+
if (options.isLocIncluded) {
|
|
87
|
+
result.start = baseOffset + token.start;
|
|
88
|
+
result.end = baseOffset + token.start + combinator.length;
|
|
89
|
+
}
|
|
90
|
+
// Append selector combinator node to the current complex selector node
|
|
91
|
+
complexSelector.children.push(result);
|
|
92
|
+
// Reset type selector set tracker for next compound selector
|
|
93
|
+
context.isTypeSelectorSet = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { CompoundSelectorHandler };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Handles ID selector parsing in selector list.
|
|
9
|
+
*/
|
|
10
|
+
class IdSelectorHandler {
|
|
11
|
+
/**
|
|
12
|
+
* Handles ID selector parsing by creating an ID selector node
|
|
13
|
+
* and appending it to the current complex selector node.
|
|
14
|
+
*
|
|
15
|
+
* @param context Selector list parser context.
|
|
16
|
+
*
|
|
17
|
+
* @throws If the ID selector is syntactically incorrect.
|
|
18
|
+
*/
|
|
19
|
+
static handle(context) {
|
|
20
|
+
const { raw, options, baseOffset, stream, complexSelector, } = context;
|
|
21
|
+
// Get ID selector token
|
|
22
|
+
const token = stream.getOrFail();
|
|
23
|
+
// Extract ID selector value (`start + 1` - without hashmark)
|
|
24
|
+
const value = raw.slice(token.start + 1, token.end);
|
|
25
|
+
// Construct ID selector node
|
|
26
|
+
const result = {
|
|
27
|
+
type: 'IdSelector',
|
|
28
|
+
value,
|
|
29
|
+
};
|
|
30
|
+
// Include ID selector node locations if needed
|
|
31
|
+
if (options.isLocIncluded) {
|
|
32
|
+
result.start = baseOffset + token.start;
|
|
33
|
+
result.end = baseOffset + token.end;
|
|
34
|
+
}
|
|
35
|
+
// Append ID selector node to the current complex selector node
|
|
36
|
+
complexSelector.children.push(result);
|
|
37
|
+
// Advance ID selector token
|
|
38
|
+
stream.advance();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { IdSelectorHandler };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { TokenType, getFormattedTokenName } from '@adguard/css-tokenizer';
|
|
8
|
+
import { sprintf } from 'sprintf-js';
|
|
9
|
+
import { AdblockSyntaxError } from '../../../../errors/adblock-syntax-error.js';
|
|
10
|
+
import { EMPTY } from '../../../../utils/constants.js';
|
|
11
|
+
import { ValueParser } from '../../../misc/value-parser.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Handles pseudo-class selector parsing in selector list.
|
|
15
|
+
*/
|
|
16
|
+
class PseudoClassSelectorHandler {
|
|
17
|
+
/**
|
|
18
|
+
* Handles pseudo-class selector parsing by creating a pseudo-class selector node
|
|
19
|
+
* and appending it to the current complex selector node.
|
|
20
|
+
*
|
|
21
|
+
* @param context Selector list parser context.
|
|
22
|
+
*
|
|
23
|
+
* @throws If the pseudo-class selector is syntactically incorrect.
|
|
24
|
+
*/
|
|
25
|
+
static handle(context) {
|
|
26
|
+
const { raw, options, baseOffset, stream, complexSelector, } = context;
|
|
27
|
+
// Get colon token
|
|
28
|
+
let token = stream.getOrFail();
|
|
29
|
+
// Save pseudo-class selector node start position
|
|
30
|
+
const { start } = token;
|
|
31
|
+
// Advance colon token
|
|
32
|
+
stream.advance();
|
|
33
|
+
// Get pseudo-class selector name token
|
|
34
|
+
token = stream.getOrFail();
|
|
35
|
+
// It should be a function or identifier
|
|
36
|
+
const isFunction = token.type === TokenType.Function;
|
|
37
|
+
if (!isFunction && token.type !== TokenType.Ident) {
|
|
38
|
+
throw new AdblockSyntaxError(sprintf(
|
|
39
|
+
// eslint-disable-next-line max-len
|
|
40
|
+
`Expected '${getFormattedTokenName(TokenType.Ident)}' or '${getFormattedTokenName(TokenType.Function)}' as pseudo-class selector name, but got '%s' with value '%s'`, getFormattedTokenName(token.type), stream.fragment()), baseOffset + token.start, baseOffset + token.end);
|
|
41
|
+
}
|
|
42
|
+
// Extract pseudo-class selector name raw value
|
|
43
|
+
let nameRaw;
|
|
44
|
+
if (!isFunction) {
|
|
45
|
+
nameRaw = raw.slice(token.start, token.end);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
nameRaw = raw.slice(token.start, token.end - 1); // Exclude '('
|
|
49
|
+
}
|
|
50
|
+
// Construct pseudo-class selector node
|
|
51
|
+
const result = {
|
|
52
|
+
type: 'PseudoClassSelector',
|
|
53
|
+
name: ValueParser.parse(nameRaw, options, baseOffset + token.start),
|
|
54
|
+
};
|
|
55
|
+
// Include pseudo-class selector node start location if needed
|
|
56
|
+
if (options.isLocIncluded) {
|
|
57
|
+
result.start = baseOffset + start;
|
|
58
|
+
}
|
|
59
|
+
// If it's a function, parse its argument
|
|
60
|
+
if (isFunction) {
|
|
61
|
+
// Advance pseudo-class selector name token
|
|
62
|
+
stream.advance();
|
|
63
|
+
// Get pseudo-class selector argument token
|
|
64
|
+
token = stream.getOrFail();
|
|
65
|
+
// Construct empty pseudo-class selector argument node by default
|
|
66
|
+
result.argument = {
|
|
67
|
+
type: 'Value',
|
|
68
|
+
value: EMPTY,
|
|
69
|
+
};
|
|
70
|
+
// Include pseudo-class selector argument node location if needed
|
|
71
|
+
if (options.isLocIncluded) {
|
|
72
|
+
result.argument.start = baseOffset + token.start;
|
|
73
|
+
result.argument.end = baseOffset + token.start;
|
|
74
|
+
}
|
|
75
|
+
// Skip whitespaces after opening parenthesis
|
|
76
|
+
stream.skipWhitespace();
|
|
77
|
+
// Get pseudo-class selector argument or closing parenthesis token
|
|
78
|
+
token = stream.getOrFail();
|
|
79
|
+
// Check if there is any argument part
|
|
80
|
+
if (token.type !== TokenType.CloseParenthesis) {
|
|
81
|
+
// Save the balance level to find the matching closing parenthesis
|
|
82
|
+
const balance = stream.getBalance();
|
|
83
|
+
// Skip leading whitespace
|
|
84
|
+
stream.skipWhitespace();
|
|
85
|
+
// Get argument token
|
|
86
|
+
token = stream.getOrFail();
|
|
87
|
+
// Save pseudo-class selector argument start position
|
|
88
|
+
const argumentStart = token.start;
|
|
89
|
+
// Track last non-whitespace token to handle trailing whitespace
|
|
90
|
+
let lastNonWsToken;
|
|
91
|
+
// Skip to the closing parenthesis at the matching balance level
|
|
92
|
+
while (stream.get()?.balance !== balance - 1) {
|
|
93
|
+
const currentToken = stream.get();
|
|
94
|
+
if (currentToken && currentToken.type !== TokenType.Whitespace) {
|
|
95
|
+
lastNonWsToken = currentToken;
|
|
96
|
+
}
|
|
97
|
+
stream.advance();
|
|
98
|
+
}
|
|
99
|
+
// Get closing parenthesis token
|
|
100
|
+
token = stream.getOrFail();
|
|
101
|
+
// Save pseudo-class selector argument end position (after last non-whitespace token)
|
|
102
|
+
const argumentEnd = lastNonWsToken ? lastNonWsToken.end : token.start;
|
|
103
|
+
// Extract pseudo-class selector argument raw value (trimmed)
|
|
104
|
+
// TODO: Consider parsing inner selectors (like :not(.class))
|
|
105
|
+
const argumentRaw = raw.slice(argumentStart, argumentEnd);
|
|
106
|
+
// Specify pseudo-class selector argument node value
|
|
107
|
+
result.argument.value = argumentRaw;
|
|
108
|
+
// Include pseudo-class selector argument node location if needed
|
|
109
|
+
if (options.isLocIncluded) {
|
|
110
|
+
result.argument.start = baseOffset + argumentStart;
|
|
111
|
+
result.argument.end = baseOffset + argumentStart + argumentRaw.length;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Expect close parenthesis token
|
|
115
|
+
stream.expect(TokenType.CloseParenthesis);
|
|
116
|
+
}
|
|
117
|
+
// Include pseudo-class selector end location if needed
|
|
118
|
+
if (options.isLocIncluded) {
|
|
119
|
+
result.end = baseOffset + token.end;
|
|
120
|
+
}
|
|
121
|
+
// Append pseudo-class selector node to the current complex selector node
|
|
122
|
+
complexSelector.children.push(result);
|
|
123
|
+
// Advance pseudo-class selector name token (if ident) or closing parenthesis token (if function)
|
|
124
|
+
stream.advance();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { PseudoClassSelectorHandler };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { AdblockSyntaxError } from '../../../../errors/adblock-syntax-error.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handles type selector parsing in selector list.
|
|
11
|
+
*/
|
|
12
|
+
class TypeSelectorHandler {
|
|
13
|
+
/**
|
|
14
|
+
* Handles type selector parsing by creating a type selector node
|
|
15
|
+
* and appending it to the current complex selector node.
|
|
16
|
+
*
|
|
17
|
+
* @param context Selector list parser context.
|
|
18
|
+
*
|
|
19
|
+
* @throws If the type selector is syntactically incorrect.
|
|
20
|
+
*/
|
|
21
|
+
static handle(context) {
|
|
22
|
+
const { options, baseOffset, stream, complexSelector, isTypeSelectorSet, } = context;
|
|
23
|
+
// Get type selector token
|
|
24
|
+
const token = stream.getOrFail();
|
|
25
|
+
// Throw error if type selector is already set
|
|
26
|
+
if (isTypeSelectorSet) {
|
|
27
|
+
throw new AdblockSyntaxError('Type selector is already set for the compound selector', baseOffset + token.start, baseOffset + token.end);
|
|
28
|
+
}
|
|
29
|
+
// Throw error if type selector isn't first in the given compound selector
|
|
30
|
+
if (
|
|
31
|
+
// It should be first on current complex selector
|
|
32
|
+
complexSelector.children.length !== 0
|
|
33
|
+
// Or should be first on current compound selector (after combinator)
|
|
34
|
+
&& complexSelector.children[complexSelector.children.length - 1].type !== 'SelectorCombinator') {
|
|
35
|
+
throw new AdblockSyntaxError('Type selector must be first in the compound selector', baseOffset + token.start, baseOffset + token.end);
|
|
36
|
+
}
|
|
37
|
+
// Extract type selector value
|
|
38
|
+
const value = stream.fragment();
|
|
39
|
+
// Construct type selector node
|
|
40
|
+
const result = {
|
|
41
|
+
type: 'TypeSelector',
|
|
42
|
+
value,
|
|
43
|
+
};
|
|
44
|
+
// Include type selector node locations if needed
|
|
45
|
+
if (options.isLocIncluded) {
|
|
46
|
+
result.start = baseOffset + token.start;
|
|
47
|
+
result.end = baseOffset + token.start + value.length;
|
|
48
|
+
}
|
|
49
|
+
// Append type selector node to the current complex selector node
|
|
50
|
+
complexSelector.children.push(result);
|
|
51
|
+
// Advance type selector token
|
|
52
|
+
stream.advance();
|
|
53
|
+
// Mark that type name is set
|
|
54
|
+
context.isTypeSelectorSet = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { TypeSelectorHandler };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
3
|
+
* (c) 2026 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { getFormattedTokenName, TokenType } from '@adguard/css-tokenizer';
|
|
8
|
+
import { sprintf } from 'sprintf-js';
|
|
9
|
+
import { AdblockSyntaxError } from '../../../errors/adblock-syntax-error.js';
|
|
10
|
+
import { SPACE, TILDE, PLUS, GREATER_THAN, DOT, ASTERISK } from '../../../utils/constants.js';
|
|
11
|
+
import { BaseParser } from '../../base-parser.js';
|
|
12
|
+
import { CssTokenStream } from '../../css/css-token-stream.js';
|
|
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
|
+
import { AttributeSelectorHandler } from './handlers/attribute-selector-handler.js';
|
|
17
|
+
import { PseudoClassSelectorHandler } from './handlers/pseudo-class-selector-handler.js';
|
|
18
|
+
import { ClassSelectorHandler } from './handlers/class-selector-handler.js';
|
|
19
|
+
import { CompoundSelectorHandler } from './handlers/compound-selector-handler.js';
|
|
20
|
+
import { ComplexSelectorHandler } from './handlers/complex-selector-handler.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Class responsible for parsing selector lists.
|
|
24
|
+
*
|
|
25
|
+
* Please note that the parser will parse any selector list if it is syntactically correct.
|
|
26
|
+
* For example, it will parse this:
|
|
27
|
+
* ```adblock
|
|
28
|
+
* div[attr1="value1"] > h1[attr2="value2"], span[attr3="value3"]
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* but it didn't check if the given attribute or pseudo-class is valid or not.
|
|
32
|
+
*
|
|
33
|
+
* @see {@link https://www.w3.org/TR/selectors-4/#selector-list}'
|
|
34
|
+
*/
|
|
35
|
+
class SelectorListParser extends BaseParser {
|
|
36
|
+
/**
|
|
37
|
+
* Common error messages used in the parser for unexpected tokens.
|
|
38
|
+
*/
|
|
39
|
+
static UNEXPECTED_TOKEN_WITH_VALUE_ERROR = "Unexpected token '%s' with value '%s'";
|
|
40
|
+
/**
|
|
41
|
+
* Parses a selector list.
|
|
42
|
+
*
|
|
43
|
+
* @param raw Raw input to parse.
|
|
44
|
+
* @param options Global parser options.
|
|
45
|
+
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
46
|
+
*
|
|
47
|
+
* @returns Node of the parsed selector list.
|
|
48
|
+
*
|
|
49
|
+
* @throws If the selector list is syntactically incorrect.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```
|
|
53
|
+
* div[attr1="value1"] > h1[attr2="value2"], span[attr3="value3"]
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
57
|
+
// Construct the stream
|
|
58
|
+
const stream = new CssTokenStream(raw, baseOffset);
|
|
59
|
+
// Skip whitespaces before first token
|
|
60
|
+
stream.skipWhitespace();
|
|
61
|
+
// Construct selector list parser context
|
|
62
|
+
const context = {
|
|
63
|
+
raw,
|
|
64
|
+
options,
|
|
65
|
+
baseOffset,
|
|
66
|
+
stream,
|
|
67
|
+
// Get first token
|
|
68
|
+
token: stream.getOrFail(),
|
|
69
|
+
// Construct selector list node
|
|
70
|
+
result: {
|
|
71
|
+
type: 'SelectorList',
|
|
72
|
+
children: [],
|
|
73
|
+
},
|
|
74
|
+
// Construct first complex selector node
|
|
75
|
+
complexSelector: {
|
|
76
|
+
type: 'ComplexSelector',
|
|
77
|
+
children: [],
|
|
78
|
+
},
|
|
79
|
+
// Track if type selector set in the current compound selector
|
|
80
|
+
isTypeSelectorSet: false,
|
|
81
|
+
};
|
|
82
|
+
// Include locations for (if needed):
|
|
83
|
+
// - start and end for the selector list node
|
|
84
|
+
// - start for the first complex selector node
|
|
85
|
+
if (options.isLocIncluded) {
|
|
86
|
+
context.result.start = baseOffset;
|
|
87
|
+
context.result.end = baseOffset + raw.length;
|
|
88
|
+
context.complexSelector.start = baseOffset + context.token.start;
|
|
89
|
+
}
|
|
90
|
+
// Traverse the stream
|
|
91
|
+
while (!stream.isEof()) {
|
|
92
|
+
// Get next token
|
|
93
|
+
context.token = stream.getOrFail();
|
|
94
|
+
switch (context.token.type) {
|
|
95
|
+
// Tag selector
|
|
96
|
+
case TokenType.Ident: {
|
|
97
|
+
TypeSelectorHandler.handle(context);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
// ID selector
|
|
101
|
+
case TokenType.Hash: {
|
|
102
|
+
IdSelectorHandler.handle(context);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
// Attribute selector
|
|
106
|
+
case TokenType.OpenSquareBracket: {
|
|
107
|
+
AttributeSelectorHandler.handle(context);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
// Pseudo-class selector
|
|
111
|
+
case TokenType.Colon: {
|
|
112
|
+
PseudoClassSelectorHandler.handle(context);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
// Universal type selector ('*'), Class selector ('.'), Combinators ('>', '+', '~')
|
|
116
|
+
case TokenType.Delim: {
|
|
117
|
+
// Get delimiter value
|
|
118
|
+
const delimiter = stream.fragment();
|
|
119
|
+
switch (delimiter) {
|
|
120
|
+
// Universal type selector ('*')
|
|
121
|
+
case ASTERISK: {
|
|
122
|
+
TypeSelectorHandler.handle(context);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
// Class selector ('.)
|
|
126
|
+
case DOT: {
|
|
127
|
+
ClassSelectorHandler.handle(context);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
// Combinators ('>', '+', '~')
|
|
131
|
+
case GREATER_THAN:
|
|
132
|
+
case PLUS:
|
|
133
|
+
case TILDE: {
|
|
134
|
+
CompoundSelectorHandler.handle(context, delimiter);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default: {
|
|
138
|
+
throw new AdblockSyntaxError(sprintf(SelectorListParser.UNEXPECTED_TOKEN_WITH_VALUE_ERROR, getFormattedTokenName(context.token.type), delimiter), baseOffset + context.token.start, baseOffset + context.token.end);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
// End of current compound selector (whitespace combinator - descendant)
|
|
144
|
+
case TokenType.Whitespace: {
|
|
145
|
+
CompoundSelectorHandler.handle(context, SPACE);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
// End of current complex selector
|
|
149
|
+
case TokenType.Comma: {
|
|
150
|
+
ComplexSelectorHandler.handle(context, false);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
default: {
|
|
154
|
+
throw new AdblockSyntaxError(sprintf(SelectorListParser.UNEXPECTED_TOKEN_WITH_VALUE_ERROR, getFormattedTokenName(context.token.type), stream.fragment()), baseOffset + context.token.start, baseOffset + context.token.end);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Finish last complex selector
|
|
159
|
+
ComplexSelectorHandler.handle(context);
|
|
160
|
+
return context.result;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { SelectorListParser };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree
|
|
3
|
-
* (c)
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
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 } from '@adguard/css-tokenizer';
|
|
8
|
+
import { REMOVE_PROPERTY, REMOVE_VALUE } from '../../converter/data/css.js';
|
|
8
9
|
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
9
10
|
import { CSS_MEDIA_MARKER, EMPTY } from '../../utils/constants.js';
|
|
10
11
|
import { CssTokenStream } from './css-token-stream.js';
|
|
@@ -14,8 +15,6 @@ import { BaseParser } from '../base-parser.js';
|
|
|
14
15
|
/**
|
|
15
16
|
* @file Parser for AdGuard CSS injections.
|
|
16
17
|
*/
|
|
17
|
-
const REMOVE_PROPERTY = 'remove';
|
|
18
|
-
const REMOVE_VALUE = 'true';
|
|
19
18
|
const ERROR_MESSAGES = {
|
|
20
19
|
MEDIA_QUERY_LIST_IS_EMPTY: 'Media query list is empty',
|
|
21
20
|
SELECTOR_LIST_IS_EMPTY: 'Selector list is empty',
|
|
@@ -205,4 +204,4 @@ class AdgCssInjectionParser extends BaseParser {
|
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
export { AdgCssInjectionParser, ERROR_MESSAGES
|
|
207
|
+
export { AdgCssInjectionParser, ERROR_MESSAGES };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree
|
|
3
|
-
* (c)
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
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
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* AGTree
|
|
3
|
-
* (c)
|
|
2
|
+
* AGTree v4.0.1 (build date: Thu, 19 Feb 2026 05:13:05 GMT)
|
|
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
|
*/
|