@adguard/agtree 2.2.0 → 3.0.0-alpha.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 +1 -1
- package/dist/ast-utils/clone.js +61 -0
- package/dist/ast-utils/modifiers.js +53 -0
- package/dist/ast-utils/network-rules.js +41 -0
- package/dist/ast-utils/scriptlets.js +87 -0
- package/dist/common/abp-snippet-injection-body-common.js +23 -0
- package/dist/common/agent-common.js +56 -0
- package/dist/common/ubo-selector-common.js +17 -0
- package/dist/compatibility-tables/base.js +262 -0
- package/dist/compatibility-tables/compatibility-table-data.js +11 -0
- package/dist/compatibility-tables/modifiers.js +55 -0
- package/dist/compatibility-tables/platforms.js +76 -0
- package/dist/compatibility-tables/redirects.js +100 -0
- package/dist/compatibility-tables/schemas/base.js +111 -0
- package/dist/compatibility-tables/schemas/modifier.js +129 -0
- package/dist/compatibility-tables/schemas/platform.js +69 -0
- package/dist/compatibility-tables/schemas/redirect.js +29 -0
- package/dist/compatibility-tables/schemas/resource-type.js +36 -0
- package/dist/compatibility-tables/schemas/scriptlet.js +79 -0
- package/dist/compatibility-tables/scriptlets.js +28 -0
- package/dist/compatibility-tables/utils/platform-helpers.js +105 -0
- package/dist/compatibility-tables/utils/resource-type-helpers.js +61 -0
- package/dist/compatibility-tables/utils/zod-camelcase.js +25 -0
- package/dist/converter/base-interfaces/base-converter.js +59 -0
- package/dist/converter/base-interfaces/conversion-result.js +38 -0
- package/dist/converter/base-interfaces/rule-converter-base.js +60 -0
- package/dist/converter/comment/index.js +54 -0
- package/dist/converter/cosmetic/css.js +69 -0
- package/dist/converter/cosmetic/element-hiding.js +62 -0
- package/dist/converter/cosmetic/header-removal.js +123 -0
- package/dist/converter/cosmetic/html.js +379 -0
- package/dist/converter/cosmetic/index.js +118 -0
- package/dist/converter/cosmetic/rule-modifiers/adg.js +79 -0
- package/dist/converter/cosmetic/scriptlet.js +354 -0
- package/dist/converter/css/index.js +188 -0
- package/dist/converter/data/css.js +126 -0
- package/dist/converter/filter-list.js +88 -0
- package/dist/converter/index.js +8 -0
- package/dist/converter/misc/network-rule-modifier.js +311 -0
- package/dist/converter/network/index.js +99 -0
- package/dist/converter/raw-filter-list.js +56 -0
- package/dist/converter/rule.js +81 -0
- package/dist/deserializer/base-deserializer.js +29 -0
- package/dist/deserializer/comment/agent-comment-deserializer.js +79 -0
- package/dist/deserializer/comment/agent-deserializer.js +65 -0
- package/dist/deserializer/comment/comment-rule-deserializer.js +54 -0
- package/dist/deserializer/comment/config-comment-deserializer.js +111 -0
- package/dist/deserializer/comment/hint-comment-deserializer.js +72 -0
- package/dist/deserializer/comment/hint-deserializer.js +85 -0
- package/dist/deserializer/comment/metadata-comment-deserializer.js +69 -0
- package/dist/deserializer/comment/pre-processor-comment-deserializer.js +112 -0
- package/dist/deserializer/comment/simple-comment-deserializer.js +65 -0
- package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +131 -0
- package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +56 -0
- package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +48 -0
- package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +39 -0
- package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +40 -0
- package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +54 -0
- package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
- package/dist/deserializer/empty-rule-deserializer.js +48 -0
- package/dist/deserializer/filterlist-deserializer.js +85 -0
- package/dist/deserializer/index.js +8 -0
- package/dist/deserializer/invalid-rule-deserializer.js +50 -0
- package/dist/deserializer/invalid-rule-error-node-deserializer.js +50 -0
- package/dist/deserializer/misc/domain-list-deserializer.js +64 -0
- package/dist/deserializer/misc/list-item-deserializer.js +69 -0
- package/dist/deserializer/misc/list-items-deserializer.js +30 -0
- package/dist/deserializer/misc/logical-expression-deserializer.js +196 -0
- package/dist/deserializer/misc/modifier-deserializer.js +87 -0
- package/dist/deserializer/misc/modifier-list-deserializer.js +61 -0
- package/dist/deserializer/misc/parameter-list-deserializer.js +64 -0
- package/dist/deserializer/misc/value-deserializer.js +50 -0
- package/dist/deserializer/network/host-rule-deserializer.js +67 -0
- package/dist/deserializer/network/hostname-list-deserializer.js +56 -0
- package/dist/deserializer/network/network-rule-deserializer.js +65 -0
- package/dist/deserializer/rule-deserializer.js +65 -0
- package/dist/deserializer/syntax-deserialization-map.js +21 -0
- package/dist/errors/adblock-syntax-error.js +39 -0
- package/dist/errors/binary-schema-mismatch-error.js +37 -0
- package/dist/errors/not-implemented-error.js +31 -0
- package/dist/errors/rule-conversion-error.js +26 -0
- package/dist/generator/base-generator.js +27 -0
- package/dist/generator/comment/agent-comment-generator.js +31 -0
- package/dist/generator/comment/agent-generator.js +36 -0
- package/dist/generator/comment/comment-rule-generator.js +47 -0
- package/dist/generator/comment/config-comment-generator.js +45 -0
- package/dist/generator/comment/hint-comment-generator.js +28 -0
- package/dist/generator/comment/hint-generator.js +33 -0
- package/dist/generator/comment/metadata-comment-generator.js +33 -0
- package/dist/generator/comment/pre-processor-comment-generator.js +48 -0
- package/dist/generator/comment/simple-comment-generator.js +29 -0
- package/dist/generator/cosmetic/body/abp-snippet-injection-body-generator.js +38 -0
- package/dist/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +43 -0
- package/dist/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +45 -0
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +94 -0
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +54 -0
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +42 -0
- package/dist/generator/css/adg-css-injection-generator.js +42 -0
- package/dist/generator/filterlist-generator.js +67 -0
- package/dist/generator/index.js +9 -0
- package/dist/generator/misc/domain-list-generator.js +26 -0
- package/dist/generator/misc/list-items-generator.js +39 -0
- package/dist/generator/misc/logical-expression-generator.js +48 -0
- package/dist/generator/misc/modifier-generator.js +34 -0
- package/dist/generator/misc/modifier-list-generator.js +29 -0
- package/dist/generator/misc/parameter-list-generator.js +41 -0
- package/dist/generator/misc/value-generator.js +24 -0
- package/dist/generator/network/host-rule-generator.js +39 -0
- package/dist/generator/network/network-rule-generator.js +38 -0
- package/dist/generator/rule-generator.js +65 -0
- package/dist/index.js +70 -0
- package/dist/marshalling-utils/comment/agent-comment-common.js +21 -0
- package/dist/marshalling-utils/comment/agent-common.js +40 -0
- package/dist/marshalling-utils/comment/config-comment-common.js +54 -0
- package/dist/marshalling-utils/comment/hint-comment-common.js +22 -0
- package/dist/marshalling-utils/comment/hint-common.js +56 -0
- package/dist/marshalling-utils/comment/metadata-comment-common.js +41 -0
- package/dist/marshalling-utils/comment/pre-processor-comment-common.js +59 -0
- package/dist/marshalling-utils/comment/simple-comment-common.js +22 -0
- package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +61 -0
- package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +66 -0
- package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +24 -0
- package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +21 -0
- package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +114 -0
- package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +48 -0
- package/dist/marshalling-utils/empty-rule-common.js +20 -0
- package/dist/marshalling-utils/filter-list-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-error-node-common.js +22 -0
- package/dist/marshalling-utils/misc/binary-type-common.js +66 -0
- package/dist/marshalling-utils/misc/domain-list-common.js +36 -0
- package/dist/marshalling-utils/misc/host-rule-common.js +25 -0
- package/dist/marshalling-utils/misc/hostname-list-common.js +21 -0
- package/dist/marshalling-utils/misc/list-item-common.js +22 -0
- package/dist/marshalling-utils/misc/logical-expression-common.js +83 -0
- package/dist/marshalling-utils/misc/modifier-common.js +231 -0
- package/dist/marshalling-utils/misc/modifier-list-common.js +21 -0
- package/dist/marshalling-utils/misc/parameter-list-common.js +21 -0
- package/dist/marshalling-utils/misc/value-common.js +22 -0
- package/dist/marshalling-utils/network/network-rule-common.js +25 -0
- package/dist/marshalling-utils/syntax-serialization-map.js +30 -0
- package/dist/nodes/index.js +168 -0
- package/dist/package.json.js +9 -0
- package/dist/parser/base-parser.js +30 -0
- package/dist/parser/comment/agent-comment-parser.js +119 -0
- package/dist/parser/comment/agent-parser.js +110 -0
- package/dist/parser/comment/comment-parser.js +108 -0
- package/dist/parser/comment/config-comment-parser.js +137 -0
- package/dist/parser/comment/hint-comment-parser.js +117 -0
- package/dist/parser/comment/hint-parser.js +129 -0
- package/dist/parser/comment/metadata-comment-parser.js +129 -0
- package/dist/parser/comment/preprocessor-parser.js +199 -0
- package/dist/parser/comment/simple-comment-parser.js +106 -0
- package/dist/parser/cosmetic/body/abp-snippet-injection-body-parser.js +79 -0
- package/dist/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +149 -0
- package/dist/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +110 -0
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +453 -0
- package/dist/parser/css/adg-css-injection-parser.js +208 -0
- package/dist/parser/css/balancing.js +94 -0
- package/dist/parser/css/constants.js +18 -0
- package/dist/parser/css/css-token-stream.js +343 -0
- package/dist/parser/css/ubo-selector-parser.js +369 -0
- package/dist/parser/filterlist-parser.js +102 -0
- package/dist/parser/index.js +12 -0
- package/dist/parser/misc/app-list-parser.js +45 -0
- package/dist/parser/misc/domain-list-parser.js +52 -0
- package/dist/parser/misc/list-items-parser.js +116 -0
- package/dist/parser/misc/logical-expression-parser.js +279 -0
- package/dist/parser/misc/method-list-parser.js +46 -0
- package/dist/parser/misc/modifier-list.js +70 -0
- package/dist/parser/misc/modifier-parser.js +89 -0
- package/dist/parser/misc/parameter-list-parser.js +75 -0
- package/dist/parser/misc/stealth-option-list-parser.js +46 -0
- package/dist/parser/misc/ubo-parameter-list-parser.js +149 -0
- package/dist/parser/misc/value-parser.js +37 -0
- package/dist/parser/network/host-rule-parser.js +130 -0
- package/dist/parser/network/network-rule-parser.js +117 -0
- package/dist/parser/options.js +23 -0
- package/dist/parser/rule-parser.js +192 -0
- package/dist/serializer/base-serializer.js +29 -0
- package/dist/serializer/comment/agent-comment-serializer.js +74 -0
- package/dist/serializer/comment/agent-serializer.js +59 -0
- package/dist/serializer/comment/comment-rule-serializer.js +105 -0
- package/dist/serializer/comment/config-comment-serializer.js +82 -0
- package/dist/serializer/comment/hint-comment-serializer.js +65 -0
- package/dist/serializer/comment/hint-serializer.js +54 -0
- package/dist/serializer/comment/metadata-comment-serializer.js +73 -0
- package/dist/serializer/comment/pre-processor-comment-serializer.js +71 -0
- package/dist/serializer/comment/simple-comment-serializer.js +52 -0
- package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +50 -0
- package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +120 -0
- package/dist/serializer/cosmetic/css-injection-body-serializer.js +51 -0
- package/dist/serializer/cosmetic/element-hiding-body-serializer.js +40 -0
- package/dist/serializer/empty-rule-serializer.js +37 -0
- package/dist/serializer/filterlist-serializer.js +45 -0
- package/dist/serializer/index.js +7 -0
- package/dist/serializer/invalid-rule-error-node-serializer.js +41 -0
- package/dist/serializer/invalid-rule-serializer.js +40 -0
- package/dist/serializer/misc/domain-list-serializer.js +64 -0
- package/dist/serializer/misc/list-item-serializer.js +58 -0
- package/dist/serializer/misc/list-items-serializer.js +29 -0
- package/dist/serializer/misc/logical-expression-serializer.js +136 -0
- package/dist/serializer/misc/modifier-list-serializer.js +58 -0
- package/dist/serializer/misc/modifier-serializer.js +49 -0
- package/dist/serializer/misc/parameter-list-serializer.js +52 -0
- package/dist/serializer/misc/value-serializer.js +50 -0
- package/dist/serializer/network/host-rule-serializer.js +70 -0
- package/dist/serializer/network/hostname-list-serializer.js +53 -0
- package/dist/serializer/network/network-rule-serializer.js +54 -0
- package/dist/serializer/rule-serializer.js +61 -0
- package/dist/types/ast-utils/clone.d.ts +26 -0
- package/dist/types/ast-utils/filter-list.d.ts +11 -0
- package/dist/types/ast-utils/modifiers.d.ts +20 -0
- package/dist/types/ast-utils/network-rules.d.ts +15 -0
- package/dist/types/ast-utils/scriptlets.d.ts +52 -0
- package/dist/types/common/abp-snippet-injection-body-common.d.ts +15 -0
- package/dist/types/common/agent-common.d.ts +10 -0
- package/dist/types/common/ubo-selector-common.d.ts +10 -0
- package/dist/types/compatibility-tables/base.d.ts +157 -0
- package/dist/types/compatibility-tables/compatibility-table-data.d.ts +68 -0
- package/dist/types/compatibility-tables/index.d.ts +13 -0
- package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
- package/dist/types/compatibility-tables/platforms.d.ts +49 -0
- package/dist/types/compatibility-tables/redirects.d.ts +33 -0
- package/dist/types/compatibility-tables/schemas/base.d.ts +124 -0
- package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
- package/dist/types/compatibility-tables/schemas/modifier.d.ts +36 -0
- package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
- package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
- package/dist/types/compatibility-tables/schemas/resource-type.d.ts +41 -0
- package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
- package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
- package/dist/types/compatibility-tables/types.d.ts +34 -0
- package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
- package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
- package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
- package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
- package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
- package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
- package/dist/types/converter/comment/index.d.ts +23 -0
- package/dist/types/converter/cosmetic/css.d.ts +23 -0
- package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
- package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
- package/dist/types/converter/cosmetic/html.d.ts +54 -0
- package/dist/types/converter/cosmetic/index.d.ts +33 -0
- package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
- package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
- package/dist/types/converter/css/index.d.ts +40 -0
- package/dist/types/converter/data/css.d.ts +48 -0
- package/dist/types/converter/filter-list.d.ts +31 -0
- package/dist/types/converter/index.d.ts +5 -0
- package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
- package/dist/types/converter/network/index.d.ts +33 -0
- package/dist/types/converter/raw-filter-list.d.ts +31 -0
- package/dist/types/converter/raw-rule.d.ts +28 -0
- package/dist/types/converter/rule.d.ts +37 -0
- package/dist/types/deserializer/base-deserializer.d.ts +15 -0
- package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
- package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
- package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
- package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
- package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
- package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +15 -0
- package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +16 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +19 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/empty-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/filterlist-deserializer.d.ts +34 -0
- package/dist/types/deserializer/index.d.ts +2 -0
- package/dist/types/deserializer/invalid-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/misc/list-item-deserializer.d.ts +19 -0
- package/dist/types/deserializer/misc/list-items-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
- package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
- package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
- package/dist/types/deserializer/network/host-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
- package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
- package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
- package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
- package/dist/types/errors/not-implemented-error.d.ts +14 -0
- package/dist/types/errors/rule-conversion-error.d.ts +14 -0
- package/dist/types/generator/base-generator.d.ts +12 -0
- package/dist/types/generator/comment/agent-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/agent-generator.d.ts +15 -0
- package/dist/types/generator/comment/comment-rule-generator.d.ts +14 -0
- package/dist/types/generator/comment/config-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-generator.d.ts +14 -0
- package/dist/types/generator/comment/index.d.ts +1 -0
- package/dist/types/generator/comment/metadata-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/simple-comment-generator.d.ts +14 -0
- package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +20 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +28 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +18 -0
- package/dist/types/generator/cosmetic/index.d.ts +1 -0
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +15 -0
- package/dist/types/generator/css/ubo-selector-generator.d.ts +14 -0
- package/dist/types/generator/filterlist-generator.d.ts +18 -0
- package/dist/types/generator/index.d.ts +3 -0
- package/dist/types/generator/misc/domain-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/list-items-generator.d.ts +25 -0
- package/dist/types/generator/misc/logical-expression-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-list-generator.d.ts +14 -0
- package/dist/types/generator/misc/parameter-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/value-generator.d.ts +14 -0
- package/dist/types/generator/network/host-rule-generator.d.ts +14 -0
- package/dist/types/generator/network/index.d.ts +2 -0
- package/dist/types/generator/network/network-rule-generator.d.ts +14 -0
- package/dist/types/generator/rule-generator.d.ts +24 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +14 -0
- package/dist/types/marshalling-utils/comment/agent-common.d.ts +20 -0
- package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +42 -0
- package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/comment/hint-common.d.ts +33 -0
- package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +21 -0
- package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +37 -0
- package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +23 -0
- package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +17 -0
- package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +14 -0
- package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +28 -0
- package/dist/types/marshalling-utils/empty-rule-common.d.ts +13 -0
- package/dist/types/marshalling-utils/filter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +57 -0
- package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +24 -0
- package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/list-item-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +47 -0
- package/dist/types/marshalling-utils/misc/modifier-common.d.ts +41 -0
- package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/value-common.d.ts +15 -0
- package/dist/types/marshalling-utils/network/network-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
- package/dist/types/nodes/index.d.ts +1183 -0
- package/dist/types/parser/base-parser.d.ts +16 -0
- package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
- package/dist/types/parser/comment/agent-parser.d.ts +33 -0
- package/dist/types/parser/comment/comment-parser.d.ts +76 -0
- package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
- package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
- package/dist/types/parser/comment/hint-parser.d.ts +30 -0
- package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
- package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
- package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
- package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
- package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
- package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
- package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
- package/dist/types/parser/css/balancing.d.ts +36 -0
- package/dist/types/parser/css/constants.d.ts +10 -0
- package/dist/types/parser/css/css-token-stream.d.ts +210 -0
- package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
- package/dist/types/parser/filterlist-parser.d.ts +29 -0
- package/dist/types/parser/index.d.ts +6 -0
- package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
- package/dist/types/parser/misc/list-items-parser.d.ts +37 -0
- package/dist/types/parser/misc/logical-expression-parser.d.ts +42 -0
- package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/modifier-list.d.ts +24 -0
- package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
- package/dist/types/parser/misc/parameter-list-parser.d.ts +17 -0
- package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +21 -0
- package/dist/types/parser/misc/value-parser.d.ts +18 -0
- package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
- package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
- package/dist/types/parser/options.d.ts +41 -0
- package/dist/types/parser/rule-parser.d.ts +78 -0
- package/dist/types/serializer/base-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
- package/dist/types/serializer/comment/agent-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
- package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
- package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
- package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
- package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
- package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +17 -0
- package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +19 -0
- package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +15 -0
- package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +15 -0
- package/dist/types/serializer/empty-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/filterlist-serializer.d.ts +15 -0
- package/dist/types/serializer/index.d.ts +1 -0
- package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +15 -0
- package/dist/types/serializer/invalid-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
- package/dist/types/serializer/misc/list-item-serializer.d.ts +16 -0
- package/dist/types/serializer/misc/list-items-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/logical-expression-serializer.d.ts +52 -0
- package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
- package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
- package/dist/types/serializer/misc/parameter-list-serializer.d.ts +17 -0
- package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
- package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
- package/dist/types/serializer/network/hostname-list-serializer.d.ts +15 -0
- package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
- package/dist/types/serializer/rule-serializer.d.ts +17 -0
- package/dist/types/utils/adblockers.d.ts +49 -0
- package/dist/types/utils/binary-schema-version.d.ts +9 -0
- package/dist/types/utils/byte-buffer.d.ts +54 -0
- package/dist/types/utils/categorizer.d.ts +14 -0
- package/dist/types/utils/clone.d.ts +15 -0
- package/dist/types/utils/constants.d.ts +188 -0
- package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
- package/dist/types/utils/deep-freeze.d.ts +13 -0
- package/dist/types/utils/domain.d.ts +29 -0
- package/dist/types/utils/error.d.ts +8 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/dist/types/utils/input-byte-buffer.d.ts +146 -0
- package/dist/types/utils/is-chromium.d.ts +7 -0
- package/dist/types/utils/logical-expression.d.ts +45 -0
- package/dist/types/utils/multi-value-map.d.ts +16 -0
- package/dist/types/utils/output-byte-buffer.d.ts +132 -0
- package/dist/types/utils/position-provider.d.ts +46 -0
- package/dist/types/utils/quotes.d.ts +94 -0
- package/dist/types/utils/regexp.d.ts +54 -0
- package/dist/types/utils/storage-interface.d.ts +23 -0
- package/dist/types/utils/string.d.ts +280 -0
- package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
- package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
- package/dist/types/utils/type-guards.d.ts +47 -0
- package/dist/types/validator/constants.d.ts +89 -0
- package/dist/types/validator/helpers.d.ts +37 -0
- package/dist/types/validator/index.d.ts +38 -0
- package/dist/types/validator/value.d.ts +12 -0
- package/dist/types/version.d.ts +5 -0
- package/dist/utils/adblockers.js +56 -0
- package/dist/utils/binary-schema-version.js +17 -0
- package/dist/utils/byte-buffer.js +91 -0
- package/dist/utils/categorizer.js +44 -0
- package/dist/utils/clone.js +28 -0
- package/dist/utils/constants.js +249 -0
- package/dist/utils/cosmetic-rule-separator.js +127 -0
- package/dist/utils/deep-freeze.js +32 -0
- package/dist/utils/domain.js +59 -0
- package/dist/utils/error.js +49 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/input-byte-buffer.js +265 -0
- package/dist/utils/is-chromium.js +20 -0
- package/dist/utils/logical-expression.js +92 -0
- package/dist/utils/multi-value-map.js +33 -0
- package/dist/utils/output-byte-buffer.js +231 -0
- package/dist/utils/position-provider.js +73 -0
- package/dist/utils/quotes.js +214 -0
- package/dist/utils/regexp.js +176 -0
- package/dist/utils/string.js +559 -0
- package/dist/utils/text-decoder-polyfill.js +107 -0
- package/dist/utils/text-encoder-polyfill.js +78 -0
- package/dist/utils/type-guards.js +47 -0
- package/dist/validator/constants.js +210 -0
- package/dist/validator/helpers.js +45 -0
- package/dist/validator/index.js +174 -0
- package/dist/validator/value.js +568 -0
- package/dist/version.js +18 -0
- package/package.json +61 -39
- package/dist/agtree.d.ts +0 -4155
- package/dist/agtree.js +0 -15819
- package/dist/agtree.mjs +0 -15720
- package/dist/compatibility-table-data.js +0 -12782
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
const OperatorValue = {
|
|
8
|
+
Not: '!',
|
|
9
|
+
And: '&&',
|
|
10
|
+
Or: '||',
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Represents the different comment markers that can be used in an adblock rule.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* - If the rule is `! This is just a comment`, then the marker will be `!`.
|
|
17
|
+
* - If the rule is `# This is just a comment`, then the marker will be `#`.
|
|
18
|
+
*/
|
|
19
|
+
const CommentMarker = {
|
|
20
|
+
/**
|
|
21
|
+
* Regular comment marker. It is supported by all ad blockers.
|
|
22
|
+
*/
|
|
23
|
+
Regular: '!',
|
|
24
|
+
/**
|
|
25
|
+
* Hashmark comment marker. It is supported by uBlock Origin and AdGuard,
|
|
26
|
+
* and also used in hosts files.
|
|
27
|
+
*/
|
|
28
|
+
Hashmark: '#',
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents the main categories that an adblock rule can belong to.
|
|
32
|
+
* Of course, these include additional subcategories.
|
|
33
|
+
*/
|
|
34
|
+
const RuleCategory = {
|
|
35
|
+
/**
|
|
36
|
+
* Empty "rules" that are only containing whitespaces. These rules are handled just for convenience.
|
|
37
|
+
*/
|
|
38
|
+
Empty: 'Empty',
|
|
39
|
+
/**
|
|
40
|
+
* Syntactically invalid rules (tolerant mode only).
|
|
41
|
+
*/
|
|
42
|
+
Invalid: 'Invalid',
|
|
43
|
+
/**
|
|
44
|
+
* Comment rules, such as comment rules, metadata rules, preprocessor rules, etc.
|
|
45
|
+
*/
|
|
46
|
+
Comment: 'Comment',
|
|
47
|
+
/**
|
|
48
|
+
* Cosmetic rules, such as element hiding rules, CSS rules, scriptlet rules, HTML rules, and JS rules.
|
|
49
|
+
*/
|
|
50
|
+
Cosmetic: 'Cosmetic',
|
|
51
|
+
/**
|
|
52
|
+
* Network rules, such as basic network rules, header remover network rules, redirect network rules,
|
|
53
|
+
* response header filtering rules, etc.
|
|
54
|
+
*/
|
|
55
|
+
Network: 'Network',
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Represents similar types of modifiers values
|
|
59
|
+
* which may be separated by a comma `,` (only for DomainList) or a pipe `|`.
|
|
60
|
+
*/
|
|
61
|
+
const ListNodeType = {
|
|
62
|
+
Unknown: 'Unknown',
|
|
63
|
+
AppList: 'AppList',
|
|
64
|
+
DomainList: 'DomainList',
|
|
65
|
+
MethodList: 'MethodList',
|
|
66
|
+
StealthOptionList: 'StealthOptionList',
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Represents child items for {@link ListNodeType}.
|
|
70
|
+
*/
|
|
71
|
+
const ListItemNodeType = {
|
|
72
|
+
Unknown: 'Unknown',
|
|
73
|
+
App: 'App',
|
|
74
|
+
Domain: 'Domain',
|
|
75
|
+
Method: 'Method',
|
|
76
|
+
StealthOption: 'StealthOption',
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Represents possible comment types.
|
|
80
|
+
*/
|
|
81
|
+
const CommentRuleType = {
|
|
82
|
+
AgentCommentRule: 'AgentCommentRule',
|
|
83
|
+
CommentRule: 'CommentRule',
|
|
84
|
+
ConfigCommentRule: 'ConfigCommentRule',
|
|
85
|
+
HintCommentRule: 'HintCommentRule',
|
|
86
|
+
MetadataCommentRule: 'MetadataCommentRule',
|
|
87
|
+
PreProcessorCommentRule: 'PreProcessorCommentRule',
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Represents possible cosmetic rule types.
|
|
91
|
+
*/
|
|
92
|
+
const CosmeticRuleType = {
|
|
93
|
+
ElementHidingRule: 'ElementHidingRule',
|
|
94
|
+
CssInjectionRule: 'CssInjectionRule',
|
|
95
|
+
ScriptletInjectionRule: 'ScriptletInjectionRule',
|
|
96
|
+
HtmlFilteringRule: 'HtmlFilteringRule',
|
|
97
|
+
JsInjectionRule: 'JsInjectionRule',
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Represents possible cosmetic rule separators.
|
|
101
|
+
*/
|
|
102
|
+
const CosmeticRuleSeparator = {
|
|
103
|
+
/**
|
|
104
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
105
|
+
*/
|
|
106
|
+
ElementHiding: '##',
|
|
107
|
+
/**
|
|
108
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
109
|
+
*/
|
|
110
|
+
ElementHidingException: '#@#',
|
|
111
|
+
/**
|
|
112
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
113
|
+
*/
|
|
114
|
+
ExtendedElementHiding: '#?#',
|
|
115
|
+
/**
|
|
116
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
117
|
+
*/
|
|
118
|
+
ExtendedElementHidingException: '#@?#',
|
|
119
|
+
/**
|
|
120
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
121
|
+
*/
|
|
122
|
+
AbpSnippet: '#$#',
|
|
123
|
+
/**
|
|
124
|
+
* @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_basic}
|
|
125
|
+
*/
|
|
126
|
+
AbpSnippetException: '#@$#',
|
|
127
|
+
/**
|
|
128
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
|
|
129
|
+
*/
|
|
130
|
+
AdgCssInjection: '#$#',
|
|
131
|
+
/**
|
|
132
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
|
|
133
|
+
*/
|
|
134
|
+
AdgCssInjectionException: '#@$#',
|
|
135
|
+
/**
|
|
136
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
|
|
137
|
+
*/
|
|
138
|
+
AdgExtendedCssInjection: '#$?#',
|
|
139
|
+
/**
|
|
140
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#cosmetic-css-rules}
|
|
141
|
+
*/
|
|
142
|
+
AdgExtendedCssInjectionException: '#@$?#',
|
|
143
|
+
/**
|
|
144
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#scriptlets}
|
|
145
|
+
*/
|
|
146
|
+
AdgJsInjection: '#%#',
|
|
147
|
+
/**
|
|
148
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#scriptlets}
|
|
149
|
+
*/
|
|
150
|
+
AdgJsInjectionException: '#@%#',
|
|
151
|
+
/**
|
|
152
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#html-filtering-rules}
|
|
153
|
+
*/
|
|
154
|
+
AdgHtmlFiltering: '$$',
|
|
155
|
+
/**
|
|
156
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#html-filtering-rules}
|
|
157
|
+
*/
|
|
158
|
+
AdgHtmlFilteringException: '$@$',
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Represents the different types of network rules.
|
|
162
|
+
*/
|
|
163
|
+
const NetworkRuleType = {
|
|
164
|
+
NetworkRule: 'NetworkRule',
|
|
165
|
+
HostRule: 'HostRule',
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export { CommentMarker, CommentRuleType, CosmeticRuleSeparator, CosmeticRuleType, ListItemNodeType, ListNodeType, NetworkRuleType, OperatorValue, RuleCategory };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
const version = "3.0.0-alpha.2";
|
|
8
|
+
|
|
9
|
+
export { version };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { NotImplementedError } from '../errors/not-implemented-error.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file Base parser class.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Base class for parsers. Each parser should extend this class.
|
|
14
|
+
*/
|
|
15
|
+
class BaseParser {
|
|
16
|
+
/**
|
|
17
|
+
* Parses the input string and returns the AST node.
|
|
18
|
+
*
|
|
19
|
+
* @param input Input string to parse.
|
|
20
|
+
* @param options Parser options, see {@link ParserOptions}.
|
|
21
|
+
* @param baseOffset Base offset. Locations in the AST node will be relative to this offset.
|
|
22
|
+
* @param args Additional, parser-specific arguments, if needed.
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
+
static parse(input, options, baseOffset, ...args) {
|
|
26
|
+
throw new NotImplementedError();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { BaseParser };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, SEMICOLON } from '../../utils/constants.js';
|
|
8
|
+
import { StringUtils } from '../../utils/string.js';
|
|
9
|
+
import { CommentRuleType, RuleCategory } from '../../nodes/index.js';
|
|
10
|
+
import { AgentParser } from './agent-parser.js';
|
|
11
|
+
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
12
|
+
import { AdblockSyntax } from '../../utils/adblockers.js';
|
|
13
|
+
import { CosmeticRuleSeparatorUtils } from '../../utils/cosmetic-rule-separator.js';
|
|
14
|
+
import { BaseParser } from '../base-parser.js';
|
|
15
|
+
import { defaultParserOptions } from '../options.js';
|
|
16
|
+
import { isNull } from '../../utils/type-guards.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `AgentParser` is responsible for parsing an Adblock agent rules.
|
|
20
|
+
* Adblock agent comment marks that the filter list is supposed to
|
|
21
|
+
* be used by the specified ad blockers.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* - ```adblock
|
|
25
|
+
* [AdGuard]
|
|
26
|
+
* ```
|
|
27
|
+
* - ```adblock
|
|
28
|
+
* [Adblock Plus 2.0]
|
|
29
|
+
* ```
|
|
30
|
+
* - ```adblock
|
|
31
|
+
* [uBlock Origin]
|
|
32
|
+
* ```
|
|
33
|
+
* - ```adblock
|
|
34
|
+
* [uBlock Origin 1.45.3]
|
|
35
|
+
* ```
|
|
36
|
+
* - ```adblock
|
|
37
|
+
* [Adblock Plus 2.0; AdGuard]
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class AgentCommentParser extends BaseParser {
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the raw rule is an adblock agent comment.
|
|
43
|
+
*
|
|
44
|
+
* @param raw Raw rule
|
|
45
|
+
* @returns `true` if the rule is an adblock agent, `false` otherwise
|
|
46
|
+
*/
|
|
47
|
+
static isAgentRule(raw) {
|
|
48
|
+
const rawTrimmed = raw.trim();
|
|
49
|
+
if (rawTrimmed.startsWith(OPEN_SQUARE_BRACKET) && rawTrimmed.endsWith(CLOSE_SQUARE_BRACKET)) {
|
|
50
|
+
// Avoid this case: [$adg-modifier]##[class^="adg-"]
|
|
51
|
+
return isNull(CosmeticRuleSeparatorUtils.find(rawTrimmed));
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parses a raw rule as an adblock agent comment.
|
|
57
|
+
*
|
|
58
|
+
* @param raw Raw input to parse.
|
|
59
|
+
* @param options Global parser options.
|
|
60
|
+
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
61
|
+
* @returns Agent rule AST or null (if the raw rule cannot be parsed as an adblock agent comment)
|
|
62
|
+
*/
|
|
63
|
+
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
64
|
+
// Ignore non-agent rules
|
|
65
|
+
if (!AgentCommentParser.isAgentRule(raw)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
let offset = 0;
|
|
69
|
+
// Skip whitespace characters before the rule
|
|
70
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
71
|
+
// Skip opening bracket
|
|
72
|
+
offset += 1;
|
|
73
|
+
// last character should be a closing bracket
|
|
74
|
+
const closingBracketIndex = StringUtils.skipWSBack(raw, raw.length - 1);
|
|
75
|
+
if (closingBracketIndex === -1 || raw[closingBracketIndex] !== CLOSE_SQUARE_BRACKET) {
|
|
76
|
+
throw new AdblockSyntaxError('Missing closing bracket', offset, offset + raw.length);
|
|
77
|
+
}
|
|
78
|
+
// Initialize the agent list
|
|
79
|
+
const result = {
|
|
80
|
+
type: CommentRuleType.AgentCommentRule,
|
|
81
|
+
syntax: AdblockSyntax.Common,
|
|
82
|
+
category: RuleCategory.Comment,
|
|
83
|
+
children: [],
|
|
84
|
+
};
|
|
85
|
+
if (options.includeRaws) {
|
|
86
|
+
result.raws = {
|
|
87
|
+
text: raw,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (options.isLocIncluded) {
|
|
91
|
+
result.start = baseOffset;
|
|
92
|
+
result.end = baseOffset + raw.length;
|
|
93
|
+
}
|
|
94
|
+
while (offset < closingBracketIndex) {
|
|
95
|
+
// Skip whitespace characters before the agent
|
|
96
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
97
|
+
// Find the separator or the closing bracket
|
|
98
|
+
let separatorIndex = raw.indexOf(SEMICOLON, offset);
|
|
99
|
+
if (separatorIndex === -1) {
|
|
100
|
+
separatorIndex = closingBracketIndex;
|
|
101
|
+
}
|
|
102
|
+
// Find the last non-whitespace character of the agent
|
|
103
|
+
// [AdGuard ; Adblock Plus 2.0]
|
|
104
|
+
// ^
|
|
105
|
+
// (if we have spaces between the agent name and the separator)
|
|
106
|
+
const agentEndIndex = StringUtils.findLastNonWhitespaceCharacter(raw.slice(offset, separatorIndex)) + offset + 1;
|
|
107
|
+
// Collect the agent
|
|
108
|
+
result.children.push(AgentParser.parse(raw.slice(offset, agentEndIndex), options, baseOffset + offset));
|
|
109
|
+
// Set the offset to the next agent or the end of the rule
|
|
110
|
+
offset = separatorIndex + 1;
|
|
111
|
+
}
|
|
112
|
+
if (result.children.length === 0) {
|
|
113
|
+
throw new AdblockSyntaxError('Empty agent list', baseOffset, baseOffset + raw.length);
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { AgentCommentParser };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import valid from 'semver/functions/valid.js';
|
|
8
|
+
import coerce from 'semver/functions/coerce.js';
|
|
9
|
+
import { StringUtils } from '../../utils/string.js';
|
|
10
|
+
import { AdblockSyntaxError } from '../../errors/adblock-syntax-error.js';
|
|
11
|
+
import { AdblockSyntax } from '../../utils/adblockers.js';
|
|
12
|
+
import { BaseParser } from '../base-parser.js';
|
|
13
|
+
import { defaultParserOptions } from '../options.js';
|
|
14
|
+
import { ValueParser } from '../misc/value-parser.js';
|
|
15
|
+
import { isUndefined } from '../../utils/type-guards.js';
|
|
16
|
+
import { getAdblockSyntax } from '../../common/agent-common.js';
|
|
17
|
+
|
|
18
|
+
/* eslint-disable no-param-reassign */
|
|
19
|
+
// eslint-disable-next-line import/extensions
|
|
20
|
+
/**
|
|
21
|
+
* `AgentParser` is responsible for parsing single adblock agent elements.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* If the adblock agent rule is
|
|
25
|
+
* ```adblock
|
|
26
|
+
* [Adblock Plus 2.0; AdGuard]
|
|
27
|
+
* ```
|
|
28
|
+
* then the adblock agents are `Adblock Plus 2.0` and `AdGuard`, and this
|
|
29
|
+
* class is responsible for parsing them. The rule itself is parsed by
|
|
30
|
+
* `AgentCommentParser`, which uses this class to parse single agents.
|
|
31
|
+
*/
|
|
32
|
+
class AgentParser extends BaseParser {
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the string is a valid version.
|
|
35
|
+
*
|
|
36
|
+
* @param str String to check
|
|
37
|
+
* @returns `true` if the string is a valid version, `false` otherwise
|
|
38
|
+
*/
|
|
39
|
+
static isValidVersion(str) {
|
|
40
|
+
return valid(coerce(str)) !== null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parses a raw rule as an adblock agent comment.
|
|
44
|
+
*
|
|
45
|
+
* @param raw Raw input to parse.
|
|
46
|
+
* @param options Global parser options.
|
|
47
|
+
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
48
|
+
* @returns Agent rule AST
|
|
49
|
+
* @throws {AdblockSyntaxError} If the raw rule cannot be parsed as an adblock agent
|
|
50
|
+
*/
|
|
51
|
+
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
52
|
+
let offset = 0;
|
|
53
|
+
// Save name start position
|
|
54
|
+
const nameStartIndex = offset;
|
|
55
|
+
let nameEndIndex = offset;
|
|
56
|
+
// Prepare variables for name and version
|
|
57
|
+
let name;
|
|
58
|
+
let version;
|
|
59
|
+
// default value for the syntax
|
|
60
|
+
let syntax = AdblockSyntax.Common;
|
|
61
|
+
// Get agent parts by splitting it by spaces. The last part may be a version.
|
|
62
|
+
// Example: "Adblock Plus 2.0"
|
|
63
|
+
while (offset < raw.length) {
|
|
64
|
+
// Skip whitespace before the part
|
|
65
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
66
|
+
const partEnd = StringUtils.findNextWhitespaceCharacter(raw, offset);
|
|
67
|
+
const part = raw.slice(offset, partEnd);
|
|
68
|
+
if (AgentParser.isValidVersion(part)) {
|
|
69
|
+
if (!isUndefined(version)) {
|
|
70
|
+
throw new AdblockSyntaxError('Duplicated versions are not allowed', baseOffset + offset, baseOffset + partEnd);
|
|
71
|
+
}
|
|
72
|
+
const parsedNamePart = raw.slice(nameStartIndex, nameEndIndex);
|
|
73
|
+
name = ValueParser.parse(parsedNamePart, options, baseOffset + nameStartIndex);
|
|
74
|
+
version = ValueParser.parse(part, options, baseOffset + offset);
|
|
75
|
+
syntax = getAdblockSyntax(parsedNamePart);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
nameEndIndex = partEnd;
|
|
79
|
+
}
|
|
80
|
+
// Skip whitespace after the part
|
|
81
|
+
offset = StringUtils.skipWS(raw, partEnd);
|
|
82
|
+
}
|
|
83
|
+
// If we didn't find a version, the whole string is the name
|
|
84
|
+
if (isUndefined(name)) {
|
|
85
|
+
const parsedNamePart = raw.slice(nameStartIndex, nameEndIndex);
|
|
86
|
+
name = ValueParser.parse(parsedNamePart, options, baseOffset + nameStartIndex);
|
|
87
|
+
syntax = getAdblockSyntax(parsedNamePart);
|
|
88
|
+
}
|
|
89
|
+
// Agent name cannot be empty
|
|
90
|
+
if (name.value.length === 0) {
|
|
91
|
+
throw new AdblockSyntaxError('Agent name cannot be empty', baseOffset, baseOffset + raw.length);
|
|
92
|
+
}
|
|
93
|
+
const result = {
|
|
94
|
+
type: 'Agent',
|
|
95
|
+
adblock: name,
|
|
96
|
+
syntax,
|
|
97
|
+
};
|
|
98
|
+
// only add version if it's present
|
|
99
|
+
if (version) {
|
|
100
|
+
result.version = version;
|
|
101
|
+
}
|
|
102
|
+
if (options.isLocIncluded) {
|
|
103
|
+
result.start = baseOffset;
|
|
104
|
+
result.end = baseOffset + raw.length;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { AgentParser };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { AgentCommentParser } from './agent-comment-parser.js';
|
|
8
|
+
import { ConfigCommentParser } from './config-comment-parser.js';
|
|
9
|
+
import { HintCommentParser } from './hint-comment-parser.js';
|
|
10
|
+
import { MetadataCommentParser } from './metadata-comment-parser.js';
|
|
11
|
+
import { PreProcessorCommentParser } from './preprocessor-parser.js';
|
|
12
|
+
import { defaultParserOptions } from '../options.js';
|
|
13
|
+
import { BaseParser } from '../base-parser.js';
|
|
14
|
+
import { SimpleCommentParser } from './simple-comment-parser.js';
|
|
15
|
+
|
|
16
|
+
/* eslint-disable no-param-reassign */
|
|
17
|
+
/**
|
|
18
|
+
* `CommentParser` is responsible for parsing any comment-like adblock rules.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* Example rules:
|
|
22
|
+
* - Adblock agent rules:
|
|
23
|
+
* - ```adblock
|
|
24
|
+
* [AdGuard]
|
|
25
|
+
* ```
|
|
26
|
+
* - ```adblock
|
|
27
|
+
* [Adblock Plus 2.0]
|
|
28
|
+
* ```
|
|
29
|
+
* - etc.
|
|
30
|
+
* - AdGuard hint rules:
|
|
31
|
+
* - ```adblock
|
|
32
|
+
* !+ NOT_OPTIMIZED
|
|
33
|
+
* ```
|
|
34
|
+
* - ```adblock
|
|
35
|
+
* !+ NOT_OPTIMIZED PLATFORM(windows)
|
|
36
|
+
* ```
|
|
37
|
+
* - etc.
|
|
38
|
+
* - Pre-processor rules:
|
|
39
|
+
* - ```adblock
|
|
40
|
+
* !#if (adguard)
|
|
41
|
+
* ```
|
|
42
|
+
* - ```adblock
|
|
43
|
+
* !#endif
|
|
44
|
+
* ```
|
|
45
|
+
* - etc.
|
|
46
|
+
* - Metadata rules:
|
|
47
|
+
* - ```adblock
|
|
48
|
+
* ! Title: My List
|
|
49
|
+
* ```
|
|
50
|
+
* - ```adblock
|
|
51
|
+
* ! Version: 2.0.150
|
|
52
|
+
* ```
|
|
53
|
+
* - etc.
|
|
54
|
+
* - AGLint inline config rules:
|
|
55
|
+
* - ```adblock
|
|
56
|
+
* ! aglint-enable some-rule
|
|
57
|
+
* ```
|
|
58
|
+
* - ```adblock
|
|
59
|
+
* ! aglint-disable some-rule
|
|
60
|
+
* ```
|
|
61
|
+
* - etc.
|
|
62
|
+
* - Simple comments:
|
|
63
|
+
* - Regular version:
|
|
64
|
+
* ```adblock
|
|
65
|
+
* ! This is just a comment
|
|
66
|
+
* ```
|
|
67
|
+
* - uBlock Origin / "hostlist" version:
|
|
68
|
+
* ```adblock
|
|
69
|
+
* # This is just a comment
|
|
70
|
+
* ```
|
|
71
|
+
* - etc.
|
|
72
|
+
*/
|
|
73
|
+
class CommentParser extends BaseParser {
|
|
74
|
+
/**
|
|
75
|
+
* Checks whether a rule is a comment.
|
|
76
|
+
*
|
|
77
|
+
* @param raw Raw rule
|
|
78
|
+
* @returns `true` if the rule is a comment, `false` otherwise
|
|
79
|
+
*/
|
|
80
|
+
static isCommentRule(raw) {
|
|
81
|
+
const trimmed = raw.trim();
|
|
82
|
+
return SimpleCommentParser.isSimpleComment(trimmed) || AgentCommentParser.isAgentRule(trimmed);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parses a raw rule as comment.
|
|
86
|
+
*
|
|
87
|
+
* @param raw Raw input to parse.
|
|
88
|
+
* @param options Global parser options.
|
|
89
|
+
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
90
|
+
* @returns Comment AST or null (if the raw rule cannot be parsed as comment)
|
|
91
|
+
*/
|
|
92
|
+
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
93
|
+
// Ignore non-comment rules
|
|
94
|
+
if (!CommentParser.isCommentRule(raw)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
// Note: we parse non-functional comments at the end,
|
|
98
|
+
// if the input does not match any of the previous, more specific comment patterns
|
|
99
|
+
return AgentCommentParser.parse(raw, options, baseOffset)
|
|
100
|
+
|| HintCommentParser.parse(raw, options, baseOffset)
|
|
101
|
+
|| PreProcessorCommentParser.parse(raw, options, baseOffset)
|
|
102
|
+
|| MetadataCommentParser.parse(raw, options, baseOffset)
|
|
103
|
+
|| ConfigCommentParser.parse(raw, options, baseOffset)
|
|
104
|
+
|| SimpleCommentParser.parse(raw, options, baseOffset);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { CommentParser };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import JSON5 from 'json5';
|
|
8
|
+
import { AdblockSyntax } from '../../utils/adblockers.js';
|
|
9
|
+
import { AGLINT_CONFIG_COMMENT_MARKER, AGLINT_COMMAND_PREFIX, COMMA } from '../../utils/constants.js';
|
|
10
|
+
import { CommentMarker, CommentRuleType, RuleCategory } from '../../nodes/index.js';
|
|
11
|
+
import { StringUtils } from '../../utils/string.js';
|
|
12
|
+
import { ParameterListParser } from '../misc/parameter-list-parser.js';
|
|
13
|
+
import { defaultParserOptions } from '../options.js';
|
|
14
|
+
import { BaseParser } from '../base-parser.js';
|
|
15
|
+
import { ValueParser } from '../misc/value-parser.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @file AGLint configuration comments. Inspired by ESLint inline configuration comments.
|
|
19
|
+
* @see {@link https://eslint.org/docs/latest/user-guide/configuring/rules#using-configuration-comments}
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* `ConfigCommentParser` is responsible for parsing inline AGLint configuration rules.
|
|
23
|
+
* Generally, the idea is inspired by ESLint inline configuration comments.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://eslint.org/docs/latest/user-guide/configuring/rules#using-configuration-comments}
|
|
26
|
+
*/
|
|
27
|
+
class ConfigCommentParser extends BaseParser {
|
|
28
|
+
/**
|
|
29
|
+
* Checks if the raw rule is an inline configuration comment rule.
|
|
30
|
+
*
|
|
31
|
+
* @param raw Raw rule
|
|
32
|
+
* @returns `true` if the rule is an inline configuration comment rule, otherwise `false`.
|
|
33
|
+
*/
|
|
34
|
+
static isConfigComment(raw) {
|
|
35
|
+
const trimmed = raw.trim();
|
|
36
|
+
if (trimmed[0] === CommentMarker.Regular || trimmed[0] === CommentMarker.Hashmark) {
|
|
37
|
+
// Skip comment marker and trim comment text (it is necessary because of "! something")
|
|
38
|
+
const text = raw.slice(1).trim();
|
|
39
|
+
// The code below is "not pretty", but it runs fast, which is necessary, since it will run on EVERY comment
|
|
40
|
+
// The essence of the indicator is that the control comment always starts with the "aglint" prefix
|
|
41
|
+
return ((text[0] === 'a' || text[0] === 'A')
|
|
42
|
+
&& (text[1] === 'g' || text[1] === 'G')
|
|
43
|
+
&& (text[2] === 'l' || text[2] === 'L')
|
|
44
|
+
&& (text[3] === 'i' || text[3] === 'I')
|
|
45
|
+
&& (text[4] === 'n' || text[4] === 'N')
|
|
46
|
+
&& (text[5] === 't' || text[5] === 'T'));
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parses a raw rule as an inline configuration comment.
|
|
52
|
+
*
|
|
53
|
+
* @param raw Raw input to parse.
|
|
54
|
+
* @param options Global parser options.
|
|
55
|
+
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
56
|
+
* @returns
|
|
57
|
+
* Inline configuration comment AST or null (if the raw rule cannot be parsed as configuration comment)
|
|
58
|
+
*/
|
|
59
|
+
static parse(raw, options = defaultParserOptions, baseOffset = 0) {
|
|
60
|
+
if (!ConfigCommentParser.isConfigComment(raw)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
let offset = 0;
|
|
64
|
+
// Skip leading whitespace (if any)
|
|
65
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
66
|
+
// Get comment marker
|
|
67
|
+
const marker = ValueParser.parse(raw[offset], options, baseOffset + offset);
|
|
68
|
+
// Skip marker
|
|
69
|
+
offset += 1;
|
|
70
|
+
// Skip whitespace (if any)
|
|
71
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
72
|
+
// Save the command start position
|
|
73
|
+
const commandStart = offset;
|
|
74
|
+
// Get comment text, for example: "aglint-disable-next-line"
|
|
75
|
+
offset = StringUtils.findNextWhitespaceCharacter(raw, offset);
|
|
76
|
+
const command = ValueParser.parse(raw.slice(commandStart, offset), options, baseOffset + commandStart);
|
|
77
|
+
// Skip whitespace after command
|
|
78
|
+
offset = StringUtils.skipWS(raw, offset);
|
|
79
|
+
// Get comment (if any)
|
|
80
|
+
const commentStart = raw.indexOf(AGLINT_CONFIG_COMMENT_MARKER, offset);
|
|
81
|
+
const commentEnd = commentStart !== -1 ? StringUtils.skipWSBack(raw) + 1 : -1;
|
|
82
|
+
let comment;
|
|
83
|
+
// Check if there is a comment
|
|
84
|
+
if (commentStart !== -1) {
|
|
85
|
+
comment = ValueParser.parse(raw.slice(commentStart, commentEnd), options, baseOffset + commentStart);
|
|
86
|
+
}
|
|
87
|
+
// Get parameter
|
|
88
|
+
const paramsStart = offset;
|
|
89
|
+
const paramsEnd = commentStart !== -1
|
|
90
|
+
? StringUtils.skipWSBack(raw, commentStart - 1) + 1
|
|
91
|
+
: StringUtils.skipWSBack(raw) + 1;
|
|
92
|
+
let params;
|
|
93
|
+
// `! aglint ...` config comment
|
|
94
|
+
if (command.value === AGLINT_COMMAND_PREFIX) {
|
|
95
|
+
params = {
|
|
96
|
+
type: 'ConfigNode',
|
|
97
|
+
// It is necessary to use JSON5.parse instead of JSON.parse because JSON5 allows unquoted keys.
|
|
98
|
+
// But don't forget to add { } to the beginning and end of the string,
|
|
99
|
+
// otherwise JSON5 will not be able to parse it.
|
|
100
|
+
// TODO: Better solution? ESLint uses "levn" package for parsing these comments.
|
|
101
|
+
value: JSON5.parse(`{${raw.slice(paramsStart, paramsEnd)}}`),
|
|
102
|
+
};
|
|
103
|
+
if (options.isLocIncluded) {
|
|
104
|
+
params.start = paramsStart;
|
|
105
|
+
params.end = paramsEnd;
|
|
106
|
+
}
|
|
107
|
+
// Throw error for empty config
|
|
108
|
+
if (Object.keys(params.value).length === 0) {
|
|
109
|
+
throw new Error('Empty AGLint config');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (paramsStart < paramsEnd) {
|
|
113
|
+
params = ParameterListParser.parse(raw.slice(paramsStart, paramsEnd), options, baseOffset + paramsStart, COMMA);
|
|
114
|
+
}
|
|
115
|
+
const result = {
|
|
116
|
+
type: CommentRuleType.ConfigCommentRule,
|
|
117
|
+
category: RuleCategory.Comment,
|
|
118
|
+
syntax: AdblockSyntax.Common,
|
|
119
|
+
marker,
|
|
120
|
+
command,
|
|
121
|
+
params,
|
|
122
|
+
comment,
|
|
123
|
+
};
|
|
124
|
+
if (options.includeRaws) {
|
|
125
|
+
result.raws = {
|
|
126
|
+
text: raw,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (options.isLocIncluded) {
|
|
130
|
+
result.start = baseOffset;
|
|
131
|
+
result.end = baseOffset + raw.length;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { ConfigCommentParser };
|