@adguard/agtree 1.1.8 → 2.0.0

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/agtree.d.ts CHANGED
@@ -1,12 +1,52 @@
1
1
  /*
2
- * AGTree v1.1.8 (build date: Wed, 24 Apr 2024 15:20:41 GMT)
2
+ * AGTree v2.0.0 (build date: Thu, 15 Aug 2024 15:06:58 GMT)
3
3
  * (c) 2024 Adguard Software Ltd.
4
4
  * Released under the MIT license
5
5
  * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
6
6
  */
7
- import { MediaQueryListPlain, SelectorListPlain, DeclarationListPlain, FunctionNodePlain, CssNode, CssNodePlain, SelectorList, DeclarationList, MediaQueryList, MediaQuery, Selector, SelectorPlain, AttributeSelector, PseudoClassSelectorPlain, PseudoClassSelector, FunctionNode } from '@adguard/ecss-tree';
8
- import * as ecssTree from '@adguard/ecss-tree';
9
- export { ecssTree as ECSSTree };
7
+ import zod from 'zod';
8
+
9
+ /**
10
+ * @file Common options for all parsers.
11
+ */
12
+ /**
13
+ * Common options for all parsers.
14
+ */
15
+ interface ParserOptions {
16
+ /**
17
+ * If `true`, then the parser will not throw an error if the rule is syntactically invalid, instead it will
18
+ * return an `InvalidRule` object with the error attached to it.
19
+ */
20
+ tolerant?: boolean;
21
+ /**
22
+ * Whether to include location information in the AST nodes.
23
+ */
24
+ isLocIncluded?: boolean;
25
+ /**
26
+ * Whether to parse AdBlock-specific rules.
27
+ */
28
+ parseAbpSpecificRules?: boolean;
29
+ /**
30
+ * Whether to parse uBlock Origin-specific rules.
31
+ */
32
+ parseUboSpecificRules?: boolean;
33
+ /**
34
+ * Whether to parse raw parts.
35
+ */
36
+ includeRaws?: boolean;
37
+ /**
38
+ * Whether to ignore comment-rules.
39
+ */
40
+ ignoreComments?: boolean;
41
+ /**
42
+ * Whether to parse host rules.
43
+ */
44
+ parseHostRules?: boolean;
45
+ }
46
+ /**
47
+ * Default parser options.
48
+ */
49
+ declare const defaultParserOptions: ParserOptions;
10
50
 
11
51
  /**
12
52
  * @file Possible adblock syntaxes are listed here.
@@ -14,7 +54,7 @@ export { ecssTree as ECSSTree };
14
54
  /**
15
55
  * Possible adblock syntaxes (supported by this library)
16
56
  */
17
- declare const enum AdblockSyntax {
57
+ declare enum AdblockSyntax {
18
58
  /**
19
59
  * Common syntax, which is supported by more than one adblocker (or by all adblockers).
20
60
  *
@@ -58,7 +98,7 @@ declare const enum AdblockSyntax {
58
98
  }
59
99
 
60
100
  declare const ADG_SCRIPTLET_MASK = "//scriptlet";
61
- declare const UBO_SCRIPTLET_MASK = "js";
101
+ declare const UBO_SCRIPTLET_MASK = "+js";
62
102
  declare const MODIFIERS_SEPARATOR = ",";
63
103
  declare const MODIFIER_ASSIGN_OPERATOR = "=";
64
104
  declare const NEGATION_MARKER = "~";
@@ -92,9 +132,13 @@ declare const IF = "if";
92
132
  declare const INCLUDE = "include";
93
133
 
94
134
  /**
95
- * Represents possible logical expression operators.
135
+ * Possible operators in the logical expression.
96
136
  */
97
- type AnyOperator = '&&' | '||' | '!';
137
+ declare const enum OperatorValue {
138
+ Not = "!",
139
+ And = "&&",
140
+ Or = "||"
141
+ }
98
142
  /**
99
143
  * Represents possible new line types.
100
144
  */
@@ -106,7 +150,7 @@ type AnyExpressionNode = ExpressionVariableNode | ExpressionOperatorNode | Expre
106
150
  /**
107
151
  * Represents any kind of adblock rule.
108
152
  */
109
- type AnyRule = EmptyRule | AnyCommentRule | AnyCosmeticRule | NetworkRule | InvalidRule;
153
+ type AnyRule = EmptyRule | AnyCommentRule | AnyCosmeticRule | AnyNetworkRule | InvalidRule;
110
154
  /**
111
155
  * Represents any comment-like adblock rule.
112
156
  */
@@ -115,6 +159,10 @@ type AnyCommentRule = AgentCommentRule | CommentRule | ConfigCommentRule | HintC
115
159
  * Represents any cosmetic adblock rule.
116
160
  */
117
161
  type AnyCosmeticRule = CssInjectionRule | ElementHidingRule | ScriptletInjectionRule | HtmlFilteringRule | JsInjectionRule;
162
+ /**
163
+ * Represents any network adblock rule.
164
+ */
165
+ type AnyNetworkRule = NetworkRule | HostRule;
118
166
  /**
119
167
  * Represents the different comment markers that can be used in an adblock rule.
120
168
  *
@@ -137,7 +185,7 @@ declare const enum CommentMarker {
137
185
  * Represents the main categories that an adblock rule can belong to.
138
186
  * Of course, these include additional subcategories.
139
187
  */
140
- declare const enum RuleCategory {
188
+ declare enum RuleCategory {
141
189
  /**
142
190
  * Empty "rules" that are only containing whitespaces. These rules are handled just for convenience.
143
191
  */
@@ -165,6 +213,7 @@ declare const enum RuleCategory {
165
213
  * which may be separated by a comma `,` (only for DomainList) or a pipe `|`.
166
214
  */
167
215
  declare const enum ListNodeType {
216
+ Unknown = "Unknown",
168
217
  AppList = "AppList",
169
218
  DomainList = "DomainList",
170
219
  MethodList = "MethodList",
@@ -173,7 +222,8 @@ declare const enum ListNodeType {
173
222
  /**
174
223
  * Represents child items for {@link ListNodeType}.
175
224
  */
176
- declare const enum ListItemNodeType {
225
+ declare enum ListItemNodeType {
226
+ Unknown = "Unknown",
177
227
  App = "App",
178
228
  Domain = "Domain",
179
229
  Method = "Method",
@@ -182,7 +232,7 @@ declare const enum ListItemNodeType {
182
232
  /**
183
233
  * Represents possible comment types.
184
234
  */
185
- declare const enum CommentRuleType {
235
+ declare enum CommentRuleType {
186
236
  AgentCommentRule = "AgentCommentRule",
187
237
  CommentRule = "CommentRule",
188
238
  ConfigCommentRule = "ConfigCommentRule",
@@ -193,7 +243,7 @@ declare const enum CommentRuleType {
193
243
  /**
194
244
  * Represents possible cosmetic rule types.
195
245
  */
196
- declare const enum CosmeticRuleType {
246
+ declare enum CosmeticRuleType {
197
247
  ElementHidingRule = "ElementHidingRule",
198
248
  CssInjectionRule = "CssInjectionRule",
199
249
  ScriptletInjectionRule = "ScriptletInjectionRule",
@@ -259,23 +309,7 @@ declare const enum CosmeticRuleSeparator {
259
309
  /**
260
310
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#html-filtering-rules}
261
311
  */
262
- AdgHtmlFilteringException = "$@$",
263
- /**
264
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#scriptlet-injection}
265
- */
266
- UboScriptletInjection = "##+",
267
- /**
268
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#scriptlet-injection}
269
- */
270
- UboScriptletInjectionException = "#@#+",
271
- /**
272
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#html-filters}
273
- */
274
- UboHtmlFiltering = "##^",
275
- /**
276
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#html-filters}
277
- */
278
- UboHtmlFilteringException = "#@#^"
312
+ AdgHtmlFilteringException = "$@$"
279
313
  }
280
314
  /**
281
315
  * Represents a basic node in the AST.
@@ -285,27 +319,18 @@ interface Node {
285
319
  * The type of the node. Every node should have a type.
286
320
  */
287
321
  type: string;
288
- /**
289
- * Every node should support a loc property, which refers to the location of the node in the source code.
290
- */
291
- loc?: LocationRange;
292
322
  /**
293
323
  * Optionally the raw representation of the node in the source code.
294
324
  */
295
325
  raw?: string;
296
- }
297
- /**
298
- * Represents a location range in the source code.
299
- */
300
- interface LocationRange {
301
326
  /**
302
- * The start location of the node.
327
+ * Start offset of the node.
303
328
  */
304
- start: Location;
329
+ start?: number;
305
330
  /**
306
- * The end location of the node.
331
+ * End offset of the node.
307
332
  */
308
- end: Location;
333
+ end?: number;
309
334
  }
310
335
  /**
311
336
  * Represents a location in the source code.
@@ -325,24 +350,27 @@ interface Location {
325
350
  column: number;
326
351
  }
327
352
  /**
328
- * Represents a basic value node in the AST.
353
+ * Represents a location range in the source code.
329
354
  */
330
- interface Value<T = string> extends Node {
331
- type: 'Value';
355
+ interface LocationRange {
332
356
  /**
333
- * Value of the node.
357
+ * The start location of the node.
334
358
  */
335
- value: T;
359
+ start: Location;
360
+ /**
361
+ * The end location of the node.
362
+ */
363
+ end: Location;
336
364
  }
337
365
  /**
338
- * Represents a basic parameter node in the AST.
366
+ * Represents a basic value node in the AST.
339
367
  */
340
- interface Parameter extends Node {
341
- type: 'Parameter';
368
+ interface Value<T = string> extends Node {
369
+ type: 'Value';
342
370
  /**
343
371
  * Value of the node.
344
372
  */
345
- value: string;
373
+ value: T;
346
374
  }
347
375
  /**
348
376
  * Represents a list of parameters.
@@ -351,8 +379,10 @@ interface ParameterList extends Node {
351
379
  type: 'ParameterList';
352
380
  /**
353
381
  * List of values
382
+ *
383
+ * @note `null` values are allowed in the list, they represent empty parameters.
354
384
  */
355
- children: Parameter[];
385
+ children: (Value | null)[];
356
386
  }
357
387
  /**
358
388
  * Represents a logical expression variable node in the AST.
@@ -366,7 +396,7 @@ interface ExpressionVariableNode extends Node {
366
396
  */
367
397
  interface ExpressionOperatorNode extends Node {
368
398
  type: 'Operator';
369
- operator: AnyOperator;
399
+ operator: OperatorValue;
370
400
  left: AnyExpressionNode;
371
401
  right?: AnyExpressionNode;
372
402
  }
@@ -415,6 +445,17 @@ interface RuleBase extends Node {
415
445
  nl?: NewLine;
416
446
  };
417
447
  }
448
+ interface InvalidRuleError extends Node {
449
+ type: 'InvalidRuleError';
450
+ /**
451
+ * Error name
452
+ */
453
+ name: string;
454
+ /**
455
+ * Error message
456
+ */
457
+ message: string;
458
+ }
418
459
  /**
419
460
  * Represents an invalid rule (used by tolerant mode).
420
461
  */
@@ -431,20 +472,7 @@ interface InvalidRule extends RuleBase {
431
472
  /**
432
473
  * Error details
433
474
  */
434
- error: {
435
- /**
436
- * Error name
437
- */
438
- name: string;
439
- /**
440
- * Error message
441
- */
442
- message: string;
443
- /**
444
- * Error location (if any)
445
- */
446
- loc?: LocationRange;
447
- };
475
+ error: InvalidRuleError;
448
476
  }
449
477
  /**
450
478
  * Represents an "empty rule" (practically an empty line)
@@ -487,7 +515,7 @@ interface CommentRule extends CommentBase {
487
515
  * - If the rule is `! This is just a comment`, then the marker will be `!`.
488
516
  * - If the rule is `# This is just a comment`, then the marker will be `#`.
489
517
  */
490
- marker: Value<CommentMarker>;
518
+ marker: Value;
491
519
  /**
492
520
  * Comment text.
493
521
  *
@@ -512,7 +540,7 @@ interface MetadataCommentRule extends CommentBase {
512
540
  /**
513
541
  * Comment marker.
514
542
  */
515
- marker: Value<CommentMarker>;
543
+ marker: Value;
516
544
  /**
517
545
  * Metadata header name.
518
546
  */
@@ -522,6 +550,21 @@ interface MetadataCommentRule extends CommentBase {
522
550
  */
523
551
  value: Value;
524
552
  }
553
+ /**
554
+ * Represents an AGLint configuration node.
555
+ *
556
+ * Used within config comments.
557
+ *
558
+ * @example
559
+ * ```adblock
560
+ * ! aglint "rule-1": ["warn", { "option1": "value1" }], "rule-2": "off"
561
+ * ! ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
562
+ * ```
563
+ */
564
+ interface ConfigNode extends Node {
565
+ type: 'ConfigNode';
566
+ value: object;
567
+ }
525
568
  /**
526
569
  * Represents an inline linter configuration comment.
527
570
  *
@@ -538,7 +581,7 @@ interface ConfigCommentRule extends CommentBase {
538
581
  /**
539
582
  * The marker for the comment. It can be `!` or `#`. It is always the first non-whitespace character in the comment.
540
583
  */
541
- marker: Value<CommentMarker>;
584
+ marker: Value;
542
585
  /**
543
586
  * The command for the comment. It is always begins with the `aglint` prefix.
544
587
  *
@@ -558,7 +601,7 @@ interface ConfigCommentRule extends CommentBase {
558
601
  * ```
559
602
  * the params would be `["some-rule", "another-rule"]`.
560
603
  */
561
- params?: Value<object> | ParameterList;
604
+ params?: ConfigNode | ParameterList;
562
605
  /**
563
606
  * Config comment text. The idea is generally the same as in ESLint.
564
607
  *
@@ -605,7 +648,7 @@ interface Agent extends Node {
605
648
  /**
606
649
  * Adblock version (if specified).
607
650
  */
608
- version: Value | null;
651
+ version?: Value;
609
652
  /**
610
653
  * Needed for network rules modifier validation.
611
654
  */
@@ -674,7 +717,7 @@ interface HintCommentRule extends RuleBase {
674
717
  /**
675
718
  * Currently only AdGuard supports hints.
676
719
  */
677
- syntax: AdblockSyntax.Adg;
720
+ syntax: AdblockSyntax;
678
721
  /**
679
722
  * List of hints.
680
723
  */
@@ -711,7 +754,7 @@ interface Modifier extends Node {
711
754
  /**
712
755
  * Modifier name
713
756
  */
714
- modifier: Value;
757
+ name: Value;
715
758
  /**
716
759
  * Is this modifier an exception? For example, `~third-party` is an exception
717
760
  */
@@ -747,8 +790,8 @@ type DomainListSeparator = CommaSeparator | PipeSeparator;
747
790
  * Common interface for a list item of $app, $denyallow, $domain, $method
748
791
  * which have similar syntax.
749
792
  */
750
- interface ListItem extends Node {
751
- type: ListItemNodeType;
793
+ interface ListItem<T extends ListItemNodeType> extends Node {
794
+ type: T;
752
795
  /**
753
796
  * Value of the node.
754
797
  */
@@ -764,27 +807,19 @@ interface ListItem extends Node {
764
807
  /**
765
808
  * Represents an element of the app list — $app.
766
809
  */
767
- interface App extends ListItem {
768
- type: ListItemNodeType.App;
769
- }
810
+ type App = ListItem<ListItemNodeType.App>;
770
811
  /**
771
812
  * Represents an element of the domain list — $domain, $denyallow.
772
813
  */
773
- interface Domain extends ListItem {
774
- type: ListItemNodeType.Domain;
775
- }
814
+ type Domain = ListItem<ListItemNodeType.Domain>;
776
815
  /**
777
816
  * Represents an element of the method list — $method.
778
817
  */
779
- interface Method extends ListItem {
780
- type: ListItemNodeType.Method;
781
- }
818
+ type Method = ListItem<ListItemNodeType.Method>;
782
819
  /**
783
820
  * Represents an element of the stealth option list — $stealth.
784
821
  */
785
- interface StealthOption extends ListItem {
786
- type: ListItemNodeType.StealthOption;
787
- }
822
+ type StealthOption = ListItem<ListItemNodeType.StealthOption>;
788
823
  /**
789
824
  * Represents a list of domains.
790
825
  * Needed for $domain and $denyallow.
@@ -875,17 +910,38 @@ interface StealthOptionList extends Node {
875
910
  interface CssInjectionRuleBody extends Node {
876
911
  type: 'CssInjectionRuleBody';
877
912
  /**
878
- * Media query list (if any)
913
+ * Media query, if any.
914
+ *
915
+ * @example
916
+ *
917
+ * ```text
918
+ * @media (max-width: 768px) { ... }
919
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
920
+ * ```
879
921
  */
880
- mediaQueryList?: MediaQueryListPlain;
922
+ mediaQueryList?: Value;
881
923
  /**
882
- * Selector list
924
+ * CSS selector list.
925
+ *
926
+ * @example
927
+ * section:has(> .ad) { display: none; }
928
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
929
+ * section:has(> .ad), article > p[advert] { display: none; }
930
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
883
931
  */
884
- selectorList: SelectorListPlain;
932
+ selectorList: Value;
885
933
  /**
886
- * Declaration block / remove flag
934
+ * Declaration list.
935
+ *
936
+ * @example
937
+ * section:has(> .ad) { display: none; }
938
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑
939
+ * section:has(> .ad), article > p[advert] { display: none; }
940
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑
941
+ * div[ad] { padding-top: 10px; padding-bottom: 10px; }
942
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
887
943
  */
888
- declarationList?: DeclarationListPlain;
944
+ declarationList?: Value;
889
945
  /**
890
946
  * Remove flag
891
947
  */
@@ -900,7 +956,7 @@ interface ElementHidingRuleBody extends Node {
900
956
  /**
901
957
  * Element hiding rule selector(s).
902
958
  */
903
- selectorList: SelectorListPlain;
959
+ selectorList: Value;
904
960
  }
905
961
  /**
906
962
  * Represents a scriptlet injection rule body.
@@ -920,7 +976,7 @@ interface HtmlFilteringRuleBody extends Node {
920
976
  /**
921
977
  * HTML rule selector(s).
922
978
  */
923
- body: SelectorListPlain | FunctionNodePlain;
979
+ body: Value;
924
980
  }
925
981
  /**
926
982
  * A generic representation of a cosmetic rule.
@@ -1065,7 +1121,7 @@ interface ScriptletInjectionRule extends CosmeticRule {
1065
1121
  */
1066
1122
  interface HtmlFilteringRule extends CosmeticRule {
1067
1123
  type: CosmeticRuleType.HtmlFilteringRule;
1068
- body: HtmlFilteringRuleBody;
1124
+ body: Value;
1069
1125
  }
1070
1126
  /**
1071
1127
  * Representation of a JS injection rule.
@@ -1082,13 +1138,39 @@ interface JsInjectionRule extends CosmeticRule {
1082
1138
  type: CosmeticRuleType.JsInjectionRule;
1083
1139
  body: Value;
1084
1140
  }
1141
+ /**
1142
+ * Represents the different types of network rules.
1143
+ */
1144
+ declare enum NetworkRuleType {
1145
+ NetworkRule = "NetworkRule",
1146
+ HostRule = "HostRule"
1147
+ }
1085
1148
  /**
1086
1149
  * Represents the common properties of network rules
1087
1150
  */
1088
- interface NetworkRule extends RuleBase {
1151
+ interface NetworkRuleBase extends RuleBase {
1152
+ /**
1153
+ * Category of the adblock rule.
1154
+ */
1089
1155
  category: RuleCategory.Network;
1090
- type: 'NetworkRule';
1156
+ /**
1157
+ * Type of the network rule.
1158
+ */
1159
+ type: NetworkRuleType;
1160
+ /**
1161
+ * Syntax of the adblock rule. If we are not able to determine the syntax of the rule,
1162
+ * we should use `AdblockSyntax.Common` as the value.
1163
+ */
1091
1164
  syntax: AdblockSyntax;
1165
+ }
1166
+ /**
1167
+ * Represents the common properties of network rules
1168
+ */
1169
+ interface NetworkRule extends NetworkRuleBase {
1170
+ /**
1171
+ * Type of the node.
1172
+ */
1173
+ type: NetworkRuleType.NetworkRule;
1092
1174
  /**
1093
1175
  * If the rule is an exception rule. If the rule begins with `@@`, it means that it is an exception rule.
1094
1176
  *
@@ -1134,197 +1216,733 @@ interface NetworkRule extends RuleBase {
1134
1216
  */
1135
1217
  modifiers?: ModifierList;
1136
1218
  }
1137
-
1138
1219
  /**
1139
- * `RuleParser` is responsible for parsing the rules.
1220
+ * Represents a list of hostnames.
1221
+ */
1222
+ interface HostnameList extends Node {
1223
+ /**
1224
+ * Type of the node.
1225
+ */
1226
+ type: 'HostnameList';
1227
+ /**
1228
+ * List of hostnames.
1229
+ */
1230
+ children: Value[];
1231
+ }
1232
+ /**
1233
+ * Represents the common properties of host rules.
1140
1234
  *
1141
- * It automatically determines the category and syntax of the rule, so you can pass any kind of rule to it.
1235
+ * @see https://adguard-dns.io/kb/general/dns-filtering-syntax/#etc-hosts-syntax
1142
1236
  */
1143
- declare class RuleParser {
1237
+ interface HostRule extends NetworkRuleBase {
1144
1238
  /**
1145
- * Parse an adblock rule. You can pass any kind of rule to this method, since it will automatically determine
1146
- * the category and syntax. If the rule is syntactically invalid, then an error will be thrown. If the
1147
- * syntax / compatibility cannot be determined clearly, then the value of the `syntax` property will be
1148
- * `Common`.
1149
- *
1150
- * For example, let's have this network rule:
1151
- * ```adblock
1152
- * ||example.org^$important
1153
- * ```
1154
- * The `syntax` property will be `Common`, since the rule is syntactically correct in every adblockers, but we
1155
- * cannot determine at parsing level whether `important` is an existing option or not, nor if it exists, then
1156
- * which adblocker supports it. This is why the `syntax` property is simply `Common` at this point.
1157
- * The concrete COMPATIBILITY of the rule will be determined later, in a different, higher-level layer, called
1158
- * "Compatibility table".
1239
+ * Type of the node.
1240
+ */
1241
+ type: NetworkRuleType.HostRule;
1242
+ /**
1243
+ * IP address. It can be an IPv4 or IPv6 address.
1159
1244
  *
1160
- * But we can determinate the concrete syntax of this rule:
1161
- * ```adblock
1162
- * example.org#%#//scriptlet("scriptlet0", "arg0")
1245
+ * @example
1246
+ * ```text
1247
+ * 127.0.0.1 example.com example.org
1248
+ * ↑↑↑↑↑↑↑↑↑
1163
1249
  * ```
1164
- * since it is clearly an AdGuard-specific rule and no other adblockers uses this syntax natively. However, we also
1165
- * cannot determine the COMPATIBILITY of this rule, as it is not clear at this point whether the `scriptlet0`
1166
- * scriptlet is supported by AdGuard or not. This is also the task of the "Compatibility table". Here, we simply
1167
- * mark the rule with the `AdGuard` syntax in this case.
1250
+ * @note If IP is not specified in the rule, it parsed as null IP: `0.0.0.0`.
1251
+ */
1252
+ ip: Value;
1253
+ /**
1254
+ * Hostnames.
1168
1255
  *
1169
- * @param raw Raw adblock rule
1170
- * @param tolerant If `true`, then the parser will not throw if the rule is syntactically invalid, instead it will
1171
- * return an `InvalidRule` object with the error attached to it. Default is `false`.
1172
- * @param loc Base location of the rule
1173
- * @returns Adblock rule AST
1174
- * @throws If the input matches a pattern but syntactically invalid
1175
1256
  * @example
1176
- * Take a look at the following example:
1177
- * ```js
1178
- * // Parse a network rule
1179
- * const ast1 = RuleParser.parse("||example.org^$important");
1180
- *
1181
- * // Parse another network rule
1182
- * const ast2 = RuleParser.parse("/ads.js^$important,third-party,domain=example.org|~example.com");
1183
- *
1184
- * // Parse a cosmetic rule
1185
- * const ast2 = RuleParser.parse("example.org##.banner");
1186
- *
1187
- * // Parse another cosmetic rule
1188
- * const ast3 = RuleParser.parse("example.org#?#.banner:-abp-has(.ad)");
1189
- *
1190
- * // Parse a comment rule
1191
- * const ast4 = RuleParser.parse("! Comment");
1192
- *
1193
- * // Parse an empty rule
1194
- * const ast5 = RuleParser.parse("");
1195
- *
1196
- * // Parse a comment rule (with metadata)
1197
- * const ast6 = RuleParser.parse("! Title: Example");
1198
- *
1199
- * // Parse a pre-processor rule
1200
- * const ast7 = RuleParser.parse("!#if (adguard)");
1257
+ * ```text
1258
+ * 127.0.0.1 example.com example.org
1259
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
1201
1260
  * ```
1202
1261
  */
1203
- static parse(raw: string, tolerant?: boolean, loc?: Location): AnyRule;
1262
+ hostnames: HostnameList;
1204
1263
  /**
1205
- * Converts a rule AST to a string.
1264
+ * Comment (optional).
1206
1265
  *
1207
- * @param ast - Adblock rule AST
1208
- * @returns Raw string
1209
1266
  * @example
1210
- * Take a look at the following example:
1211
- * ```js
1212
- * // Parse the rule to the AST
1213
- * const ast = RuleParser.parse("example.org##.banner");
1214
- * // Generate the rule from the AST
1215
- * const raw = RuleParser.generate(ast);
1216
- * // Print the generated rule
1217
- * console.log(raw); // "example.org##.banner"
1267
+ * ```text
1268
+ * 127.0.0.1 localhost # This is just a comment
1269
+ * ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
1218
1270
  * ```
1219
1271
  */
1220
- static generate(ast: AnyRule): string;
1272
+ comment?: Value;
1221
1273
  }
1222
1274
 
1223
1275
  /**
1224
- * @file Customized syntax error class for Adblock Filter Parser.
1276
+ * @file Core ByteBuffer implementation for handling binary data in chunks.
1225
1277
  */
1226
-
1227
1278
  /**
1228
- * Customized syntax error class for Adblock Filter Parser,
1229
- * which contains the location range of the error.
1279
+ * Core ByteBuffer implementation for handling binary data in chunks.
1280
+ * This class allows for efficient byte storage and manipulation by organizing data into chunks
1281
+ * and providing methods to read and write bytes.
1230
1282
  */
1231
- declare class AdblockSyntaxError extends SyntaxError {
1283
+ declare class ByteBuffer {
1232
1284
  /**
1233
- * Location range of the error.
1285
+ * The size of each chunk in bytes (32 KB).
1234
1286
  */
1235
- loc: LocationRange;
1287
+ static readonly CHUNK_SIZE = 32768;
1236
1288
  /**
1237
- * Constructs a new `AdblockSyntaxError` instance.
1289
+ * An array of Uint8Array chunks that make up the buffer.
1290
+ */
1291
+ protected chunks: Uint8Array[];
1292
+ /**
1293
+ * The total number of chunks in the buffer.
1294
+ */
1295
+ protected chunksLength: number;
1296
+ /**
1297
+ * Constructs a new ByteBuffer instance.
1238
1298
  *
1239
- * @param message Error message
1240
- * @param loc Location range of the error
1299
+ * @param chunks Optional array of chunks to initialize the ByteBuffer with.
1300
+ * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1301
+ * its default value is `false`. If the original chunks are guaranteed not to change,
1302
+ * leave this flag as `false` to avoid unnecessary copying.
1241
1303
  */
1242
- constructor(message: string, loc: LocationRange);
1243
- }
1244
-
1245
- /**
1246
- * `AgentParser` is responsible for parsing an Adblock agent rules.
1247
- * Adblock agent comment marks that the filter list is supposed to
1248
- * be used by the specified ad blockers.
1249
- *
1250
- * @example
1251
- * - ```adblock
1252
- * [AdGuard]
1253
- * ```
1254
- * - ```adblock
1255
- * [Adblock Plus 2.0]
1256
- * ```
1257
- * - ```adblock
1258
- * [uBlock Origin]
1259
- * ```
1260
- * - ```adblock
1261
- * [uBlock Origin 1.45.3]
1262
- * ```
1263
- * - ```adblock
1264
- * [Adblock Plus 2.0; AdGuard]
1265
- * ```
1266
- */
1267
- declare class AgentCommentRuleParser {
1304
+ constructor(chunks?: Uint8Array[], cloneChunks?: boolean);
1268
1305
  /**
1269
- * Checks if the raw rule is an adblock agent comment.
1306
+ * Ensures that the buffer has enough capacity to accommodate a given position.
1307
+ * This method adjusts the `chunks` array size to ensure it can hold the specified position.
1270
1308
  *
1271
- * @param raw Raw rule
1272
- * @returns `true` if the rule is an adblock agent, `false` otherwise
1309
+ * @param position The position to ensure capacity for.
1273
1310
  */
1274
- static isAgentRule(raw: string): boolean;
1311
+ protected ensureCapacity(position: number): void;
1275
1312
  /**
1276
- * Parses a raw rule as an adblock agent comment.
1313
+ * Writes a byte to the buffer at the specified position.
1314
+ * If the position is outside of the buffer's current size, the buffer is resized to accommodate it.
1277
1315
  *
1278
- * @param raw Raw rule
1279
- * @param loc Base location
1280
- * @returns Agent rule AST or null (if the raw rule cannot be parsed as an adblock agent comment)
1316
+ * @param position The position at which to write the byte.
1317
+ * @param value The byte value to write (0-255).
1281
1318
  */
1282
- static parse(raw: string, loc?: Location): AgentCommentRule | null;
1319
+ protected writeByte(position: number, value: number): void;
1283
1320
  /**
1284
- * Converts an adblock agent AST to a string.
1321
+ * Reads a byte from the specified position in the buffer.
1322
+ * Returns `undefined` if the position is outside of the buffer's current size.
1285
1323
  *
1286
- * @param ast Agent rule AST
1287
- * @returns Raw string
1324
+ * @param position The position from which to read the byte.
1325
+ * @returns The read byte value, or `undefined` if the position is out of bounds.
1288
1326
  */
1289
- static generate(ast: AgentCommentRule): string;
1327
+ protected readByte(position: number): number | undefined;
1290
1328
  }
1291
1329
 
1292
1330
  /**
1293
- * `AgentParser` is responsible for parsing single adblock agent elements.
1294
- *
1295
- * @example
1296
- * If the adblock agent rule is
1297
- * ```adblock
1298
- * [Adblock Plus 2.0; AdGuard]
1299
- * ```
1300
- * then the adblock agents are `Adblock Plus 2.0` and `AdGuard`, and this
1301
- * class is responsible for parsing them. The rule itself is parsed by
1302
- * `AgentCommentRuleParser`, which uses this class to parse single agents.
1331
+ * @file Represents a storage interface for reading and writing data.
1332
+ */
1333
+ /**
1334
+ * Represents a storage interface for reading and writing data.
1303
1335
  */
1304
- declare class AgentParser {
1336
+ interface Storage<K = string, V = unknown> {
1305
1337
  /**
1306
- * Checks if the string is a valid version.
1338
+ * Writes the given data to the storage with the specified key.
1307
1339
  *
1308
- * @param str String to check
1309
- * @returns `true` if the string is a valid version, `false` otherwise
1340
+ * @param key The key to identify the data in the storage.
1341
+ * @param chunks The data to write to the storage.
1342
+ * @returns A promise that resolves when the write operation is complete.
1310
1343
  */
1311
- private static isValidVersion;
1344
+ set(key: K, data: V): Promise<void>;
1312
1345
  /**
1313
- * Parses a raw rule as an adblock agent comment.
1346
+ * Reads the data from the storage with the specified key.
1347
+ *
1348
+ * @param key The key to identify the data in the storage.
1349
+ * @returns A promise that resolves with the data read from the storage.
1350
+ */
1351
+ get(key: K): Promise<V | undefined>;
1352
+ }
1353
+
1354
+ /**
1355
+ * @file Input byte buffer for reading binary data.
1356
+ */
1357
+
1358
+ /**
1359
+ * Input byte buffer for reading binary data.
1360
+ *
1361
+ * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
1362
+ */
1363
+ declare class InputByteBuffer extends ByteBuffer {
1364
+ /**
1365
+ * Current offset in the buffer for reading.
1366
+ */
1367
+ private offset;
1368
+ /**
1369
+ * Shared native decoder for decoding strings.
1370
+ */
1371
+ private readonly sharedNativeDecoder;
1372
+ /**
1373
+ * Flag indicating if the current environment is Chromium.
1374
+ * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
1375
+ * large marshalling overhead for small strings.
1376
+ */
1377
+ private readonly isChromium;
1378
+ /**
1379
+ * Constructs a new `InputByteBuffer` instance.
1380
+ *
1381
+ * @param chunks Array of chunks to initialize the ByteBuffer with.
1382
+ * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1383
+ * its default value is `false`. If the original chunks are guaranteed not to change,
1384
+ * leave this flag as `false` to avoid unnecessary copying.
1385
+ * @param initialOffset Initial offset in the buffer for reading.
1386
+ *
1387
+ * @throws If the specified chunks array is empty.
1388
+ * @throws If the binary schema version in the buffer is not equal to the expected version.
1389
+ * @throws If the initial offset is out of bounds.
1390
+ */
1391
+ constructor(chunks: Uint8Array[], cloneChunks?: boolean, initialOffset?: number);
1392
+ /**
1393
+ * Creates a new InputByteBuffer instance from a Storage instance by reading chunks from the storage.
1394
+ *
1395
+ * @param storage Storage instance.
1396
+ * @param key Key to read from the storage.
1397
+ * @returns New InputByteBuffer instance.
1398
+ * @note For performance reasons, chunks are passed by reference and not copied.
1399
+ */
1400
+ static createFromStorage(storage: Storage, key: string): Promise<InputByteBuffer>;
1401
+ /**
1402
+ * Reads a 8-bit unsigned integer from the buffer.
1403
+ *
1404
+ * @returns 8-bit unsigned integer from the buffer.
1405
+ */
1406
+ readUint8(): number;
1407
+ /**
1408
+ * Reads a 16-bit unsigned integer from the buffer.
1409
+ *
1410
+ * @returns 16-bit unsigned integer from the buffer.
1411
+ */
1412
+ readUint16(): number;
1413
+ /**
1414
+ * Reads a 32-bit unsigned integer from the buffer at the specified index.
1415
+ *
1416
+ * @param index Index to read the 32-bit unsigned integer from.
1417
+ *
1418
+ * @returns 32-bit unsigned integer from the buffer.
1419
+ */
1420
+ private readUint32FromIndex;
1421
+ /**
1422
+ * Reads a 32-bit unsigned integer from the buffer.
1423
+ *
1424
+ * @returns 32-bit unsigned integer from the buffer.
1425
+ */
1426
+ readUint32(): number;
1427
+ /**
1428
+ * Reads schema version from the buffer.
1429
+ *
1430
+ * @returns 32-bit unsigned integer from the buffer.
1431
+ * @note Schema version is always stored at the beginning of the buffer.
1432
+ */
1433
+ readSchemaVersion(): number;
1434
+ /**
1435
+ * Reads a 32-bit signed integer from the buffer.
1436
+ *
1437
+ * @returns 32-bit signed integer from the buffer.
1438
+ */
1439
+ readInt32(): number;
1440
+ /**
1441
+ * Reads an optimized unsigned integer from the buffer.
1442
+ * 'Optimized' means that the integer is stored in a variable number of bytes, depending on its value,
1443
+ * so that smaller numbers occupy less space.
1444
+ *
1445
+ * @returns Decoded unsigned integer from the buffer.
1446
+ */
1447
+ readOptimizedUint(): number;
1448
+ /**
1449
+ * Reads a string from the buffer.
1450
+ *
1451
+ * @returns Decoded string from the buffer.
1452
+ */
1453
+ readString(): string;
1454
+ /**
1455
+ * Reads a 8-bit unsigned integer from the buffer without advancing the offset.
1456
+ *
1457
+ * @returns 8-bit unsigned integer from the buffer.
1458
+ */
1459
+ peekUint8(): number;
1460
+ /**
1461
+ * Helper method for asserting the next 8-bit unsigned integer in the buffer.
1462
+ *
1463
+ * @param value Expected value.
1464
+ * @throws If the next value in the buffer is not equal to the expected value.
1465
+ */
1466
+ assertUint8(value: number): void;
1467
+ /**
1468
+ * Creates a new `InputByteBuffer` instance with the given initial offset.
1469
+ *
1470
+ * @param initialOffset Initial offset for the new buffer.
1471
+ * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
1472
+ * its default value is `false`. If the original chunks are guaranteed not to change,
1473
+ * leave this flag as `false` to avoid unnecessary copying.
1474
+ *
1475
+ * @returns New `InputByteBuffer` instance with the given initial offset.
1476
+ *
1477
+ * @note This method is useful if you want to read some data from a specific index.
1478
+ */
1479
+ createCopyWithOffset(initialOffset: number, cloneChunks?: boolean): InputByteBuffer;
1480
+ /**
1481
+ * Gets the current offset in the buffer for reading.
1482
+ *
1483
+ * @returns Current offset in the buffer for reading.
1484
+ */
1485
+ get currentOffset(): number;
1486
+ /**
1487
+ * Gets the capacity of the buffer.
1488
+ *
1489
+ * @returns Capacity of the buffer.
1490
+ */
1491
+ get capacity(): number;
1492
+ }
1493
+
1494
+ /**
1495
+ * Output byte buffer for writing binary data.
1496
+ *
1497
+ * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
1498
+ */
1499
+ declare class OutputByteBuffer extends ByteBuffer {
1500
+ /**
1501
+ * Current offset in the buffer for writing.
1502
+ */
1503
+ private offset;
1504
+ /**
1505
+ * Size of the shared buffer for encoding strings in bytes.
1506
+ * This is a divisor of ByteBuffer.CHUNK_SIZE and experience shows that this value works optimally.
1507
+ * This is sufficient for most strings that occur in filter lists (we checked average string length in popular
1508
+ * filter lists).
1509
+ */
1510
+ private static readonly ENCODER_BUFFER_SIZE;
1511
+ /**
1512
+ * Length threshold for using a shared buffer for encoding strings.
1513
+ * This temp buffer is needed because we write the short strings in it
1514
+ * (so there is no need to constantly allocate a new buffer).
1515
+ * The reason for dividing ENCODER_BUFFER_SIZE by 4 is to ensure that the encoded string fits in the buffer,
1516
+ * if we also take into account the worst possible case (each character is encoded with 4 bytes).
1517
+ */
1518
+ private static readonly SHORT_STRING_THRESHOLD;
1519
+ /**
1520
+ * Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
1521
+ * 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits — because the last bit in each byte is a flag indicating
1522
+ * if there are more bytes (except for the last byte).
1523
+ */
1524
+ static MAX_OPTIMIZED_UINT: number;
1525
+ /**
1526
+ * Shared buffer for encoding strings.
1527
+ */
1528
+ private readonly sharedBuffer;
1529
+ /**
1530
+ * Shared native encoder for encoding strings.
1531
+ */
1532
+ private readonly sharedNativeEncoder;
1533
+ /**
1534
+ * Flag indicating if the current environment is Chromium.
1535
+ * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
1536
+ * large marshalling overhead for small strings.
1537
+ */
1538
+ private readonly isChromium;
1539
+ /**
1540
+ * Constructs a new OutputByteBuffer instance.
1541
+ */
1542
+ constructor();
1543
+ /**
1544
+ * Writes a 8-bit unsigned integer to the buffer.
1545
+ *
1546
+ * @param value Value to write.
1547
+ * @returns Number of bytes written to the buffer.
1548
+ */
1549
+ writeUint8(value: number): number;
1550
+ /**
1551
+ * Writes a 16-bit unsigned integer to the buffer.
1552
+ *
1553
+ * @param value Value to write.
1554
+ * @returns Number of bytes written to the buffer.
1555
+ */
1556
+ writeUint16(value: number): number;
1557
+ /**
1558
+ * Writes a 32-bit unsigned integer to the buffer at a specific index.
1559
+ *
1560
+ * @param value Value to write.
1561
+ * @param index Index to write the value to.
1562
+ * @returns Number of bytes written to the buffer.
1563
+ */
1564
+ private writeUint32ToIndex;
1565
+ /**
1566
+ * Writes a 32-bit unsigned integer to the buffer.
1567
+ *
1568
+ * @param value Value to write.
1569
+ * @returns Number of bytes written to the buffer.
1570
+ */
1571
+ writeUint32(value: number): number;
1572
+ /**
1573
+ * Writes a 32-bit signed integer to the buffer.
1574
+ *
1575
+ * @param value Value to write.
1576
+ * @returns Number of bytes written to the buffer.
1577
+ */
1578
+ writeInt32(value: number): number;
1579
+ /**
1580
+ * Writes a Uint8Array to the byte buffer.
1581
+ *
1582
+ * @param buffer Buffer to write.
1583
+ */
1584
+ private writeBuffer;
1585
+ /**
1586
+ * Writes a string to the buffer.
1587
+ *
1588
+ * @param value Value to write.
1589
+ * @returns Number of bytes written to the buffer.
1590
+ */
1591
+ writeString(value: string): number;
1592
+ /**
1593
+ * Writes chunks to the storage.
1594
+ *
1595
+ * @param storage Storage to write the chunks to.
1596
+ * @param key Key to write the chunks to.
1597
+ * @note For performance reasons, chunks are passed by reference and not copied.
1598
+ * @throws If the storage write operation throws.
1599
+ */
1600
+ writeChunksToStorage(storage: Storage, key: string): Promise<void>;
1601
+ /**
1602
+ * Writes an 'optimized' unsigned integer to the buffer.
1603
+ * 'Optimized' means smaller storage usage for smaller numbers.
1604
+ * Except for the last byte, each byte's most significant bit is a flag indicating if there are more bytes.
1605
+ *
1606
+ * @param value Value to write.
1607
+ * @returns Number of bytes written to the buffer.
1608
+ * @throws If the value exceeds the 29-bit limit.
1609
+ */
1610
+ writeOptimizedUint(value: number): number;
1611
+ /**
1612
+ * Gets the current offset in the buffer for writing.
1613
+ *
1614
+ * @returns Current offset in the buffer for writing.
1615
+ */
1616
+ get currentOffset(): number;
1617
+ }
1618
+
1619
+ /**
1620
+ * Base class for parsers. Each parser should extend this class.
1621
+ */
1622
+ declare class ParserBase {
1623
+ /**
1624
+ * Parses the input string and returns the AST node.
1625
+ *
1626
+ * @param input Input string to parse.
1627
+ * @param options Parser options, see {@link ParserOptions}.
1628
+ * @param baseOffset Base offset. Locations in the AST node will be relative to this offset.
1629
+ * @param args Additional, parser-specific arguments, if needed.
1630
+ */
1631
+ static parse(input: string, options: ParserOptions, baseOffset: number, ...args: unknown[]): Node | null;
1632
+ /**
1633
+ * Generates a string from the AST node.
1634
+ *
1635
+ * @param node AST node to generate a string from.
1636
+ */
1637
+ static generate(node: Node): string;
1638
+ /**
1639
+ * Serializes the AST node to a byte buffer.
1640
+ *
1641
+ * @param node AST node to serialize.
1642
+ * @param buffer Output byte buffer to write to.
1643
+ * @param args Additional, parser-specific arguments, if needed.
1644
+ */
1645
+ static serialize(node: Node, buffer: OutputByteBuffer, ...args: unknown[]): void;
1646
+ /**
1647
+ * Deserializes the AST node from a byte buffer.
1648
+ *
1649
+ * @param buffer Input byte buffer to read from.
1650
+ * @param node Destination node to write to.
1651
+ * @param args Additional, parser-specific arguments, if needed.
1652
+ */
1653
+ static deserialize(buffer: InputByteBuffer, node: Partial<Node>, ...args: unknown[]): void;
1654
+ }
1655
+
1656
+ /**
1657
+ * `RuleParser` is responsible for parsing the rules.
1658
+ *
1659
+ * It automatically determines the category and syntax of the rule, so you can pass any kind of rule to it.
1660
+ */
1661
+ declare class RuleParser extends ParserBase {
1662
+ /**
1663
+ * Helper method to parse host rules if the `parseHostRules` option is enabled, otherwise it will
1664
+ * parse network rules.
1665
+ *
1666
+ * @param raw Raw input to parse.
1667
+ * @param options Global parser options.
1668
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1669
+ * @returns Host rule or network rule node.
1670
+ */
1671
+ private static parseHostOrNetworkRule;
1672
+ /**
1673
+ * Parse an adblock rule. You can pass any kind of rule to this method, since it will automatically determine
1674
+ * the category and syntax. If the rule is syntactically invalid, then an error will be thrown. If the
1675
+ * syntax / compatibility cannot be determined clearly, then the value of the `syntax` property will be
1676
+ * `Common`.
1677
+ *
1678
+ * For example, let's have this network rule:
1679
+ * ```adblock
1680
+ * ||example.org^$important
1681
+ * ```
1682
+ * The `syntax` property will be `Common`, since the rule is syntactically correct in every adblockers, but we
1683
+ * cannot determine at parsing level whether `important` is an existing option or not, nor if it exists, then
1684
+ * which adblocker supports it. This is why the `syntax` property is simply `Common` at this point.
1685
+ * The concrete COMPATIBILITY of the rule will be determined later, in a different, higher-level layer, called
1686
+ * "Compatibility table".
1687
+ *
1688
+ * But we can determinate the concrete syntax of this rule:
1689
+ * ```adblock
1690
+ * example.org#%#//scriptlet("scriptlet0", "arg0")
1691
+ * ```
1692
+ * since it is clearly an AdGuard-specific rule and no other adblockers uses this syntax natively. However, we also
1693
+ * cannot determine the COMPATIBILITY of this rule, as it is not clear at this point whether the `scriptlet0`
1694
+ * scriptlet is supported by AdGuard or not. This is also the task of the "Compatibility table". Here, we simply
1695
+ * mark the rule with the `AdGuard` syntax in this case.
1696
+ *
1697
+ * @param raw Raw input to parse.
1698
+ * @param options Global parser options.
1699
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1700
+ * @returns Adblock rule node
1701
+ * @throws If the input matches a pattern but syntactically invalid
1702
+ * @example
1703
+ * Take a look at the following example:
1704
+ * ```js
1705
+ * // Parse a network rule
1706
+ * const ast1 = RuleParser.parse("||example.org^$important");
1707
+ *
1708
+ * // Parse another network rule
1709
+ * const ast2 = RuleParser.parse("/ads.js^$important,third-party,domain=example.org|~example.com");
1710
+ *
1711
+ * // Parse a cosmetic rule
1712
+ * const ast2 = RuleParser.parse("example.org##.banner");
1713
+ *
1714
+ * // Parse another cosmetic rule
1715
+ * const ast3 = RuleParser.parse("example.org#?#.banner:-abp-has(.ad)");
1716
+ *
1717
+ * // Parse a comment rule
1718
+ * const ast4 = RuleParser.parse("! Comment");
1719
+ *
1720
+ * // Parse an empty rule
1721
+ * const ast5 = RuleParser.parse("");
1722
+ *
1723
+ * // Parse a comment rule (with metadata)
1724
+ * const ast6 = RuleParser.parse("! Title: Example");
1725
+ *
1726
+ * // Parse a pre-processor rule
1727
+ * const ast7 = RuleParser.parse("!#if (adguard)");
1728
+ * ```
1729
+ */
1730
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyRule;
1731
+ /**
1732
+ * Converts a rule AST to a string.
1733
+ *
1734
+ * @param ast - Adblock rule AST
1735
+ * @returns Raw string
1736
+ * @example
1737
+ * Take a look at the following example:
1738
+ * ```js
1739
+ * // Parse the rule to the AST
1740
+ * const ast = RuleParser.parse("example.org##.banner");
1741
+ * // Generate the rule from the AST
1742
+ * const raw = RuleParser.generate(ast);
1743
+ * // Print the generated rule
1744
+ * console.log(raw); // "example.org##.banner"
1745
+ * ```
1746
+ */
1747
+ static generate(ast: AnyRule): string;
1748
+ /**
1749
+ * Serializes an empty rule node to binary format.
1750
+ *
1751
+ * @param node Node to serialize.
1752
+ * @param buffer ByteBuffer for writing binary data.
1753
+ */
1754
+ static serializeEmptyRule(node: EmptyRule, buffer: OutputByteBuffer): void;
1755
+ /**
1756
+ * Deserializes an empty rule node from binary format.
1757
+ *
1758
+ * @param buffer ByteBuffer for reading binary data.
1759
+ * @param node Destination node.
1760
+ */
1761
+ static deserializeEmptyRule(buffer: InputByteBuffer, node: EmptyRule): void;
1762
+ /**
1763
+ * Serializes an invalid rule error node to binary format.
1764
+ *
1765
+ * @param node Node to serialize.
1766
+ * @param buffer ByteBuffer for writing binary data.
1767
+ */
1768
+ static serializeInvalidRuleErrorNode(node: InvalidRuleError, buffer: OutputByteBuffer): void;
1769
+ /**
1770
+ * Deserializes an invalid rule error node from binary format.
1771
+ *
1772
+ * @param buffer ByteBuffer for reading binary data.
1773
+ * @param node Destination node.
1774
+ */
1775
+ static deserializeInvalidRuleErrorNode(buffer: InputByteBuffer, node: Partial<InvalidRuleError>): void;
1776
+ /**
1777
+ * Serializes an invalid rule node to binary format.
1778
+ *
1779
+ * @param node Node to serialize.
1780
+ * @param buffer ByteBuffer for writing binary data.
1781
+ */
1782
+ static serializeInvalidRule(node: InvalidRule, buffer: OutputByteBuffer): void;
1783
+ /**
1784
+ * Deserializes an invalid rule node from binary format.
1785
+ *
1786
+ * @param buffer ByteBuffer for reading binary data.
1787
+ * @param node Destination node.
1788
+ */
1789
+ static deserializeInvalidRule(buffer: InputByteBuffer, node: InvalidRule): void;
1790
+ /**
1791
+ * Serializes a rule node to binary format.
1792
+ *
1793
+ * @param node Node to serialize.
1794
+ * @param buffer ByteBuffer for writing binary data.
1795
+ */
1796
+ static serialize(node: AnyRule, buffer: OutputByteBuffer): void;
1797
+ /**
1798
+ * Deserializes a rule node from binary format.
1799
+ *
1800
+ * @param buffer ByteBuffer for reading binary data.
1801
+ * @param node Destination node.
1802
+ */
1803
+ static deserialize(buffer: InputByteBuffer, node: Partial<AnyRule>): void;
1804
+ }
1805
+
1806
+ /**
1807
+ * @file Customized syntax error class for Adblock Filter Parser.
1808
+ */
1809
+ /**
1810
+ * Customized syntax error class for Adblock Filter Parser,
1811
+ * which contains the location range of the error.
1812
+ */
1813
+ declare class AdblockSyntaxError extends SyntaxError {
1814
+ /**
1815
+ * Start offset of the error.
1816
+ */
1817
+ start: number;
1818
+ /**
1819
+ * End offset of the error.
1820
+ */
1821
+ end: number;
1822
+ /**
1823
+ * Constructs a new `AdblockSyntaxError` instance.
1824
+ *
1825
+ * @param message Error message.
1826
+ * @param start Start offset of the error.
1827
+ * @param end End offset of the error.
1828
+ */
1829
+ constructor(message: string, start: number, end: number);
1830
+ }
1831
+
1832
+ /**
1833
+ * `AgentParser` is responsible for parsing an Adblock agent rules.
1834
+ * Adblock agent comment marks that the filter list is supposed to
1835
+ * be used by the specified ad blockers.
1836
+ *
1837
+ * @example
1838
+ * - ```adblock
1839
+ * [AdGuard]
1840
+ * ```
1841
+ * - ```adblock
1842
+ * [Adblock Plus 2.0]
1843
+ * ```
1844
+ * - ```adblock
1845
+ * [uBlock Origin]
1846
+ * ```
1847
+ * - ```adblock
1848
+ * [uBlock Origin 1.45.3]
1849
+ * ```
1850
+ * - ```adblock
1851
+ * [Adblock Plus 2.0; AdGuard]
1852
+ * ```
1853
+ */
1854
+ declare class AgentCommentRuleParser extends ParserBase {
1855
+ /**
1856
+ * Checks if the raw rule is an adblock agent comment.
1314
1857
  *
1315
1858
  * @param raw Raw rule
1316
- * @param loc Base location
1859
+ * @returns `true` if the rule is an adblock agent, `false` otherwise
1860
+ */
1861
+ static isAgentRule(raw: string): boolean;
1862
+ /**
1863
+ * Parses a raw rule as an adblock agent comment.
1864
+ *
1865
+ * @param raw Raw input to parse.
1866
+ * @param options Global parser options.
1867
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1868
+ * @returns Agent rule AST or null (if the raw rule cannot be parsed as an adblock agent comment)
1869
+ */
1870
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AgentCommentRule | null;
1871
+ /**
1872
+ * Converts an adblock agent AST to a string.
1873
+ *
1874
+ * @param ast Agent rule AST
1875
+ * @returns Raw string
1876
+ */
1877
+ static generate(ast: AgentCommentRule): string;
1878
+ /**
1879
+ * Serializes an adblock agent list node to binary format.
1880
+ *
1881
+ * @param node Node to serialize.
1882
+ * @param buffer ByteBuffer for writing binary data.
1883
+ */
1884
+ static serialize(node: AgentCommentRule, buffer: OutputByteBuffer): void;
1885
+ /**
1886
+ * Deserializes an agent list node from binary format.
1887
+ *
1888
+ * @param buffer ByteBuffer for reading binary data.
1889
+ * @param node Destination node.
1890
+ */
1891
+ static deserialize(buffer: InputByteBuffer, node: Partial<AgentCommentRule>): void;
1892
+ }
1893
+
1894
+ /**
1895
+ * `AgentParser` is responsible for parsing single adblock agent elements.
1896
+ *
1897
+ * @example
1898
+ * If the adblock agent rule is
1899
+ * ```adblock
1900
+ * [Adblock Plus 2.0; AdGuard]
1901
+ * ```
1902
+ * then the adblock agents are `Adblock Plus 2.0` and `AdGuard`, and this
1903
+ * class is responsible for parsing them. The rule itself is parsed by
1904
+ * `AgentCommentRuleParser`, which uses this class to parse single agents.
1905
+ */
1906
+ declare class AgentParser extends ParserBase {
1907
+ /**
1908
+ * Checks if the string is a valid version.
1909
+ *
1910
+ * @param str String to check
1911
+ * @returns `true` if the string is a valid version, `false` otherwise
1912
+ */
1913
+ private static isValidVersion;
1914
+ /**
1915
+ * Parses a raw rule as an adblock agent comment.
1916
+ *
1917
+ * @param raw Raw input to parse.
1918
+ * @param options Global parser options.
1919
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1317
1920
  * @returns Agent rule AST
1318
1921
  * @throws {AdblockSyntaxError} If the raw rule cannot be parsed as an adblock agent
1319
1922
  */
1320
- static parse(raw: string, loc?: Location): Agent;
1923
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): Agent;
1321
1924
  /**
1322
- * Converts an adblock agent AST to a string.
1925
+ * Converts an adblock agent node to a string.
1323
1926
  *
1324
- * @param ast Agent AST
1927
+ * @param value Agent node
1325
1928
  * @returns Raw string
1326
1929
  */
1327
- static generate(ast: Agent): string;
1930
+ static generate(value: Agent): string;
1931
+ /**
1932
+ * Serializes an agent node to binary format.
1933
+ *
1934
+ * @param node Node to serialize.
1935
+ * @param buffer ByteBuffer for writing binary data.
1936
+ */
1937
+ static serialize(node: Agent, buffer: OutputByteBuffer): void;
1938
+ /**
1939
+ * Deserializes an agent node from binary format.
1940
+ *
1941
+ * @param buffer ByteBuffer for reading binary data.
1942
+ * @param node Destination node.
1943
+ * @throws If the binary data is malformed.
1944
+ */
1945
+ static deserialize(buffer: InputByteBuffer, node: Partial<Agent>): void;
1328
1946
  }
1329
1947
 
1330
1948
  /**
@@ -1383,15 +2001,7 @@ declare class AgentParser {
1383
2001
  * ```
1384
2002
  * - etc.
1385
2003
  */
1386
- declare class CommentRuleParser {
1387
- /**
1388
- * Checks whether a rule is a regular comment. Regular comments are the ones that start with
1389
- * an exclamation mark (`!`).
1390
- *
1391
- * @param raw Raw rule
1392
- * @returns `true` if the rule is a regular comment, `false` otherwise
1393
- */
1394
- static isRegularComment(raw: string): boolean;
2004
+ declare class CommentRuleParser extends ParserBase {
1395
2005
  /**
1396
2006
  * Checks whether a rule is a comment.
1397
2007
  *
@@ -1402,32 +2012,43 @@ declare class CommentRuleParser {
1402
2012
  /**
1403
2013
  * Parses a raw rule as comment.
1404
2014
  *
1405
- * @param raw Raw rule
1406
- * @param loc Base location
2015
+ * @param raw Raw input to parse.
2016
+ * @param options Global parser options.
2017
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1407
2018
  * @returns Comment AST or null (if the raw rule cannot be parsed as comment)
1408
2019
  */
1409
- static parse(raw: string, loc?: Location): AnyCommentRule | null;
2020
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyCommentRule | null;
1410
2021
  /**
1411
- * Converts a comment AST to a string.
2022
+ * Converts a comment rule node to a string.
1412
2023
  *
1413
- * @param ast Comment AST
2024
+ * @param node Comment rule node
1414
2025
  * @returns Raw string
1415
2026
  */
1416
- static generate(ast: AnyCommentRule): string;
2027
+ static generate(node: AnyCommentRule): string;
2028
+ /**
2029
+ * Serializes a comment rule node to binary format.
2030
+ *
2031
+ * @param node Node to serialize.
2032
+ * @param buffer ByteBuffer for writing binary data.
2033
+ */
2034
+ static serialize(node: AnyCommentRule, buffer: OutputByteBuffer): void;
2035
+ /**
2036
+ * Deserializes a comment rule node from binary format.
2037
+ *
2038
+ * @param buffer ByteBuffer for reading binary data.
2039
+ * @param node Destination node.
2040
+ * @throws If the binary data is malformed.
2041
+ */
2042
+ static deserialize(buffer: InputByteBuffer, node: Partial<AnyCommentRule>): void;
1417
2043
  }
1418
2044
 
1419
- /**
1420
- * @file AGLint configuration comments. Inspired by ESLint inline configuration comments.
1421
- * @see {@link https://eslint.org/docs/latest/user-guide/configuring/rules#using-configuration-comments}
1422
- */
1423
-
1424
2045
  /**
1425
2046
  * `ConfigCommentParser` is responsible for parsing inline AGLint configuration rules.
1426
2047
  * Generally, the idea is inspired by ESLint inline configuration comments.
1427
2048
  *
1428
2049
  * @see {@link https://eslint.org/docs/latest/user-guide/configuring/rules#using-configuration-comments}
1429
2050
  */
1430
- declare class ConfigCommentRuleParser {
2051
+ declare class ConfigCommentRuleParser extends ParserBase {
1431
2052
  /**
1432
2053
  * Checks if the raw rule is an inline configuration comment rule.
1433
2054
  *
@@ -1438,19 +2059,50 @@ declare class ConfigCommentRuleParser {
1438
2059
  /**
1439
2060
  * Parses a raw rule as an inline configuration comment.
1440
2061
  *
1441
- * @param raw Raw rule
1442
- * @param loc Base location
2062
+ * @param raw Raw input to parse.
2063
+ * @param options Global parser options.
2064
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1443
2065
  * @returns
1444
2066
  * Inline configuration comment AST or null (if the raw rule cannot be parsed as configuration comment)
1445
2067
  */
1446
- static parse(raw: string, loc?: Location): ConfigCommentRule | null;
2068
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): ConfigCommentRule | null;
1447
2069
  /**
1448
- * Converts an inline configuration comment AST to a string.
2070
+ * Converts an inline configuration comment node to a string.
1449
2071
  *
1450
- * @param ast Inline configuration comment AST
2072
+ * @param node Inline configuration comment node
1451
2073
  * @returns Raw string
1452
2074
  */
1453
- static generate(ast: ConfigCommentRule): string;
2075
+ static generate(node: ConfigCommentRule): string;
2076
+ /**
2077
+ * Serializes a config node to binary format.
2078
+ *
2079
+ * @param node Node to serialize.
2080
+ * @param buffer ByteBuffer for writing binary data.
2081
+ */
2082
+ private static serializeConfigNode;
2083
+ /**
2084
+ * Deserializes a metadata comment node from binary format.
2085
+ *
2086
+ * @param buffer ByteBuffer for reading binary data.
2087
+ * @param node Destination node.
2088
+ * @throws If the binary data is malformed.
2089
+ */
2090
+ private static deserializeConfigNode;
2091
+ /**
2092
+ * Serializes a metadata comment node to binary format.
2093
+ *
2094
+ * @param node Node to serialize.
2095
+ * @param buffer ByteBuffer for writing binary data.
2096
+ */
2097
+ static serialize(node: ConfigCommentRule, buffer: OutputByteBuffer): void;
2098
+ /**
2099
+ * Deserializes a metadata comment node from binary format.
2100
+ *
2101
+ * @param buffer ByteBuffer for reading binary data.
2102
+ * @param node Destination node.
2103
+ * @throws If the binary data is malformed.
2104
+ */
2105
+ static deserialize(buffer: InputByteBuffer, node: Partial<ConfigCommentRule>): void;
1454
2106
  }
1455
2107
 
1456
2108
  /**
@@ -1467,7 +2119,7 @@ declare class ConfigCommentRuleParser {
1467
2119
  * compatible with the given adblocker. This is a completely natural behavior, meaningful
1468
2120
  * checking of compatibility is not done at the parser level.
1469
2121
  */
1470
- declare class CosmeticRuleParser {
2122
+ declare class CosmeticRuleParser extends ParserBase {
1471
2123
  /**
1472
2124
  * Determines whether a rule is a cosmetic rule. The rule is considered cosmetic if it
1473
2125
  * contains a cosmetic rule separator.
@@ -1482,42 +2134,85 @@ declare class CosmeticRuleParser {
1482
2134
  * - separator
1483
2135
  * - body
1484
2136
  *
1485
- * @param raw Raw cosmetic rule
1486
- * @param loc Location of the rule
2137
+ * @param raw Raw input to parse.
2138
+ * @param options Global parser options.
2139
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1487
2140
  * @returns
1488
2141
  * Parsed cosmetic rule AST or null if it failed to parse based on the known cosmetic rules
1489
2142
  * @throws If the input matches the cosmetic rule pattern but syntactically invalid
1490
2143
  */
1491
- static parse(raw: string, loc?: Location): AnyCosmeticRule | null;
2144
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyCosmeticRule | null;
1492
2145
  /**
1493
2146
  * Generates the rule pattern from the AST.
1494
2147
  *
1495
- * @param ast Cosmetic rule AST
2148
+ * @param node Cosmetic rule node
1496
2149
  * @returns Raw rule pattern
1497
2150
  * @example
1498
2151
  * - '##.foo' → ''
1499
2152
  * - 'example.com,example.org##.foo' → 'example.com,example.org'
1500
2153
  * - '[$path=/foo/bar]example.com##.foo' → '[$path=/foo/bar]example.com'
1501
2154
  */
1502
- static generatePattern(ast: AnyCosmeticRule): string;
2155
+ static generatePattern(node: AnyCosmeticRule): string;
1503
2156
  /**
1504
- * Generates the rule body from the AST.
2157
+ * Generates the rule body from the node.
1505
2158
  *
1506
- * @param ast Cosmetic rule AST
2159
+ * @param node Cosmetic rule node
1507
2160
  * @returns Raw rule body
1508
2161
  * @example
1509
2162
  * - '##.foo' → '.foo'
1510
2163
  * - 'example.com,example.org##.foo' → '.foo'
1511
2164
  * - 'example.com#%#//scriptlet('foo')' → '//scriptlet('foo')'
1512
2165
  */
1513
- static generateBody(ast: AnyCosmeticRule): string;
2166
+ static generateBody(node: AnyCosmeticRule): string;
1514
2167
  /**
1515
2168
  * Converts a cosmetic rule AST into a string.
1516
2169
  *
1517
- * @param ast Cosmetic rule AST
2170
+ * @param node Cosmetic rule AST
1518
2171
  * @returns Raw string
1519
2172
  */
1520
- static generate(ast: AnyCosmeticRule): string;
2173
+ static generate(node: AnyCosmeticRule): string;
2174
+ /**
2175
+ * Serializes an element hiding rule body node to binary format.
2176
+ *
2177
+ * @param node Node to serialize.
2178
+ * @param buffer ByteBuffer for writing binary data.
2179
+ */
2180
+ private static serializeElementHidingBody;
2181
+ /**
2182
+ * Deserializes an element hiding rule body node from binary format.
2183
+ *
2184
+ * @param buffer ByteBuffer for reading binary data.
2185
+ * @param node Destination node.
2186
+ */
2187
+ private static deserializeElementHidingBody;
2188
+ /**
2189
+ * Serializes a CSS injection rule body node to binary format.
2190
+ *
2191
+ * @param node Node to serialize.
2192
+ * @param buffer ByteBuffer for writing binary data.
2193
+ */
2194
+ private static serializeCssInjectionBody;
2195
+ /**
2196
+ * Deserializes CSS injection rule body node from binary format.
2197
+ *
2198
+ * @param buffer ByteBuffer for reading binary data.
2199
+ * @param node Destination node.
2200
+ */
2201
+ private static deserializeCssInjectionBody;
2202
+ /**
2203
+ * Serializes a cosmetic rule node to binary format.
2204
+ *
2205
+ * @param node Node to serialize.
2206
+ * @param buffer ByteBuffer for writing binary data.
2207
+ */
2208
+ static serialize(node: AnyCosmeticRule, buffer: OutputByteBuffer): void;
2209
+ /**
2210
+ * Deserializes a cosmetic rule node from binary format.
2211
+ *
2212
+ * @param buffer ByteBuffer for reading binary data.
2213
+ * @param node Destination node.
2214
+ */
2215
+ static deserialize(buffer: InputByteBuffer, node: Partial<AnyCosmeticRule>): void;
1521
2216
  }
1522
2217
 
1523
2218
  /**
@@ -1525,18 +2220,20 @@ declare class CosmeticRuleParser {
1525
2220
  *
1526
2221
  * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#app-modifier}
1527
2222
  */
1528
- declare class AppListParser {
2223
+ declare class AppListParser extends ParserBase {
1529
2224
  /**
1530
2225
  * Parses an app list which items are separated by `|`,
1531
2226
  * e.g. `Example.exe|com.example.osx`.
1532
2227
  *
1533
- * @param raw Raw app list
1534
- * @param loc Location of the app list in the rule. If not set, the default location is used.
2228
+ * @param raw Raw input to parse.
2229
+ * @param options Global parser options.
2230
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1535
2231
  *
1536
2232
  * @returns App list AST.
1537
2233
  * @throws An {@link AdblockSyntaxError} if the app list is syntactically invalid.
2234
+ * @throws An {@link Error} if the options are invalid.
1538
2235
  */
1539
- static parse(raw: string, loc?: Location): AppList;
2236
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AppList;
1540
2237
  }
1541
2238
 
1542
2239
  /**
@@ -1548,26 +2245,42 @@ declare class AppListParser {
1548
2245
  * This parser is responsible for parsing these domain lists.
1549
2246
  * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#elemhide_domains}
1550
2247
  */
1551
- declare class DomainListParser {
2248
+ declare class DomainListParser extends ParserBase {
1552
2249
  /**
1553
2250
  * Parses a domain list, eg. `example.com,example.org,~example.org`
1554
2251
  *
1555
- * @param raw Raw domain list.
1556
- * @param separator Separator character.
1557
- * @param loc Location of the domain list in the rule. If not set, the default location is used.
2252
+ * @param raw Raw input to parse.
2253
+ * @param options Global parser options.
2254
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2255
+ * @param separator Separator character (default: comma)
1558
2256
  *
1559
2257
  * @returns Domain list AST.
1560
2258
  * @throws An {@link AdblockSyntaxError} if the domain list is syntactically invalid.
2259
+ * @throws An {@link Error} if the options are invalid.
1561
2260
  */
1562
- static parse(raw: string, separator?: DomainListSeparator, loc?: Location): DomainList;
2261
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number, separator?: string): DomainList;
1563
2262
  /**
1564
- * Converts a domain list AST to a string.
2263
+ * Converts a domain list node to a string.
1565
2264
  *
1566
- * @param ast Domain list AST.
2265
+ * @param node Domain list node.
1567
2266
  *
1568
2267
  * @returns Raw string.
1569
2268
  */
1570
- static generate(ast: DomainList): string;
2269
+ static generate(node: DomainList): string;
2270
+ /**
2271
+ * Serializes a domain list node to binary format.
2272
+ *
2273
+ * @param node Node to serialize.
2274
+ * @param buffer ByteBuffer for writing binary data.
2275
+ */
2276
+ static serialize(node: DomainList, buffer: OutputByteBuffer): void;
2277
+ /**
2278
+ * Deserializes a modifier list node from binary format.
2279
+ *
2280
+ * @param buffer ByteBuffer for reading binary data.
2281
+ * @param node Destination node.
2282
+ */
2283
+ static deserialize(buffer: InputByteBuffer, node: DomainList): void;
1571
2284
  }
1572
2285
 
1573
2286
  /**
@@ -1575,18 +2288,20 @@ declare class DomainListParser {
1575
2288
  *
1576
2289
  * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#method-modifier}
1577
2290
  */
1578
- declare class MethodListParser {
2291
+ declare class MethodListParser extends ParserBase {
1579
2292
  /**
1580
2293
  * Parses a method list which items are separated by `|`,
1581
2294
  * e.g. `get|post|put`.
1582
2295
  *
1583
- * @param raw Raw method list
1584
- * @param loc Location of the method list in the rule. If not set, the default location is used.
2296
+ * @param raw Raw input to parse.
2297
+ * @param options Global parser options.
2298
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1585
2299
  *
1586
2300
  * @returns Method list AST.
1587
2301
  * @throws An {@link AdblockSyntaxError} if the method list is syntactically invalid.
2302
+ * @throws An {@link Error} if the options are invalid.
1588
2303
  */
1589
- static parse(raw: string, loc?: Location): MethodList;
2304
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): MethodList;
1590
2305
  }
1591
2306
 
1592
2307
  /**
@@ -1594,33 +2309,33 @@ declare class MethodListParser {
1594
2309
  *
1595
2310
  * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#stealth-modifier}
1596
2311
  */
1597
- declare class StealthOptionListParser {
2312
+ declare class StealthOptionListParser extends ParserBase {
1598
2313
  /**
1599
2314
  * Parses a stealth option list which items are separated by `|`,
1600
2315
  * e.g. `dpi|ip`.
1601
2316
  *
1602
- * @param raw Raw list of stealth options.
1603
- * @param loc Location of the stealth option list in the rule. If not set, the default location is used.
2317
+ * @param raw Raw input to parse.
2318
+ * @param options Global parser options.
2319
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1604
2320
  *
1605
2321
  * @returns Stealth option list AST.
1606
2322
  * @throws An {@link AdblockSyntaxError} if the stealth option list is syntactically invalid.
2323
+ * @throws An {@link Error} if the options are invalid.
1607
2324
  */
1608
- static parse(raw: string, loc?: Location): StealthOptionList;
2325
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): StealthOptionList;
1609
2326
  }
1610
2327
 
1611
2328
  /**
1612
2329
  * `FilterListParser` is responsible for parsing a whole adblock filter list (list of rules).
1613
2330
  * It is a wrapper around `RuleParser` which parses each line separately.
1614
2331
  */
1615
- declare class FilterListParser {
2332
+ declare class FilterListParser extends ParserBase {
1616
2333
  /**
1617
2334
  * Parses a whole adblock filter list (list of rules).
1618
2335
  *
1619
- * @param raw Filter list source code (including new lines)
1620
- * @param tolerant If `true`, then the parser will not throw if the rule is syntactically invalid,
1621
- * instead it will return an `InvalidRule` object with the error attached to it. Default is `true`.
1622
- * It is useful for parsing filter lists with invalid rules, because most of the rules are valid,
1623
- * and some invalid rules can't break the whole filter list parsing.
2336
+ * @param raw Raw input to parse.
2337
+ * @param options Global parser options.
2338
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1624
2339
  * @returns AST of the source code (list of rules)
1625
2340
  * @example
1626
2341
  * ```js
@@ -1635,7 +2350,7 @@ declare class FilterListParser {
1635
2350
  * ```
1636
2351
  * @throws If one of the rules is syntactically invalid (if `tolerant` is `false`)
1637
2352
  */
1638
- static parse(raw: string, tolerant?: boolean): FilterList;
2353
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): FilterList;
1639
2354
  /**
1640
2355
  * Serializes a whole adblock filter list (list of rules).
1641
2356
  *
@@ -1645,6 +2360,38 @@ declare class FilterListParser {
1645
2360
  * @returns Serialized filter list
1646
2361
  */
1647
2362
  static generate(ast: FilterList, preferRaw?: boolean): string;
2363
+ /**
2364
+ * Serializes a filter list node to binary format.
2365
+ *
2366
+ * @param node Node to serialize.
2367
+ * @param buffer ByteBuffer for writing binary data.
2368
+ */
2369
+ static serialize(node: FilterList, buffer: OutputByteBuffer): void;
2370
+ /**
2371
+ * Deserializes a filter list node from binary format.
2372
+ *
2373
+ * @param buffer ByteBuffer for reading binary data.
2374
+ * @param node Destination node.
2375
+ */
2376
+ static deserialize(buffer: InputByteBuffer, node: Partial<FilterList>): void;
2377
+ /**
2378
+ * Helper method to jump to the children of the filter list node.
2379
+ *
2380
+ * Filter lists serialized in binary format are structured as follows:
2381
+ * - `FilterListNode` filter list node indicator (1 byte)
2382
+ * - Properties:
2383
+ * - `Children` (1 byte) - children count, followed by children nodes
2384
+ * - `Start` (1 byte) - start offset, if present, followed by the value
2385
+ * - `End` (1 byte) - end offset, if present, followed by the value
2386
+ * - `NULL` (1 byte) - closing indicator
2387
+ *
2388
+ * This method skips indicators, reads the children count and returns it.
2389
+ * This way the buffer is positioned at the beginning of the children nodes.
2390
+ *
2391
+ * @param buffer Reference to the input byte buffer.
2392
+ * @returns Number of children nodes.
2393
+ */
2394
+ static jumpToChildren(buffer: InputByteBuffer): number;
1648
2395
  }
1649
2396
 
1650
2397
  /**
@@ -1658,7 +2405,7 @@ declare class FilterListParser {
1658
2405
  * contains two hints: `NOT_OPTIMIZED` and `PLATFORM`.
1659
2406
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#hints}
1660
2407
  */
1661
- declare class HintCommentRuleParser {
2408
+ declare class HintCommentRuleParser extends ParserBase {
1662
2409
  /**
1663
2410
  * Checks if the raw rule is a hint rule.
1664
2411
  *
@@ -1669,27 +2416,38 @@ declare class HintCommentRuleParser {
1669
2416
  /**
1670
2417
  * Parses a raw rule as a hint comment.
1671
2418
  *
1672
- * @param raw Raw rule
1673
- * @param loc Base location
2419
+ * @param raw Raw input to parse.
2420
+ * @param options Global parser options.
2421
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1674
2422
  * @returns Hint AST or null (if the raw rule cannot be parsed as a hint comment)
1675
2423
  * @throws If the input matches the HINT pattern but syntactically invalid
1676
2424
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#hints-1}
1677
2425
  */
1678
- static parse(raw: string, loc?: Location): HintCommentRule | null;
2426
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): HintCommentRule | null;
1679
2427
  /**
1680
- * Converts a hint rule AST to a raw string.
2428
+ * Converts a hint rule node to a raw string.
1681
2429
  *
1682
- * @param ast Hint rule AST
2430
+ * @param node Hint rule node
1683
2431
  * @returns Raw string
1684
2432
  */
1685
- static generate(ast: HintCommentRule): string;
2433
+ static generate(node: HintCommentRule): string;
2434
+ /**
2435
+ * Serializes a hint rule node to binary format.
2436
+ *
2437
+ * @param node Node to serialize.
2438
+ * @param buffer ByteBuffer for writing binary data.
2439
+ */
2440
+ static serialize(node: HintCommentRule, buffer: OutputByteBuffer): void;
2441
+ /**
2442
+ * Deserializes a hint rule node from binary format.
2443
+ *
2444
+ * @param buffer ByteBuffer for reading binary data.
2445
+ * @param node Destination node.
2446
+ * @throws If the binary data is malformed.
2447
+ */
2448
+ static deserialize(buffer: InputByteBuffer, node: Partial<HintCommentRule>): void;
1686
2449
  }
1687
2450
 
1688
- /**
1689
- * @file AdGuard Hints
1690
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#hints}
1691
- */
1692
-
1693
2451
  /**
1694
2452
  * `HintParser` is responsible for parsing AdGuard hints.
1695
2453
  *
@@ -1702,16 +2460,17 @@ declare class HintCommentRuleParser {
1702
2460
  * class is responsible for parsing them. The rule itself is parsed by
1703
2461
  * the `HintRuleParser`, which uses this class to parse single hints.
1704
2462
  */
1705
- declare class HintParser {
2463
+ declare class HintParser extends ParserBase {
1706
2464
  /**
1707
2465
  * Parses a raw rule as a hint.
1708
2466
  *
1709
- * @param raw Raw rule
1710
- * @param loc Base location
2467
+ * @param raw Raw input to parse.
2468
+ * @param options Global parser options.
2469
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1711
2470
  * @returns Hint rule AST or null
1712
2471
  * @throws If the syntax is invalid
1713
2472
  */
1714
- static parse(raw: string, loc?: Location): Hint;
2473
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): Hint;
1715
2474
  /**
1716
2475
  * Converts a single hint AST to a string.
1717
2476
  *
@@ -1719,6 +2478,21 @@ declare class HintParser {
1719
2478
  * @returns Hint string
1720
2479
  */
1721
2480
  static generate(hint: Hint): string;
2481
+ /**
2482
+ * Serializes a hint node to binary format.
2483
+ *
2484
+ * @param node Node to serialize.
2485
+ * @param buffer ByteBuffer for writing binary data.
2486
+ */
2487
+ static serialize(node: Hint, buffer: OutputByteBuffer): void;
2488
+ /**
2489
+ * Deserializes a hint node from binary format.
2490
+ *
2491
+ * @param buffer ByteBuffer for reading binary data.
2492
+ * @param node Destination node.
2493
+ * @throws If the binary data is malformed.
2494
+ */
2495
+ static deserialize(buffer: InputByteBuffer, node: Partial<Hint>): void;
1722
2496
  }
1723
2497
 
1724
2498
  /**
@@ -1731,38 +2505,99 @@ declare class HintParser {
1731
2505
  * ```
1732
2506
  * this parser will parse the expression `(adguard_ext_android_cb || adguard_ext_safari)`.
1733
2507
  */
1734
- declare class LogicalExpressionParser {
2508
+ declare class LogicalExpressionParser extends ParserBase {
1735
2509
  /**
1736
2510
  * Split the expression into tokens.
1737
2511
  *
1738
- * @param raw Source code of the expression
1739
- * @param loc Location of the expression
1740
- * @returns Token list
1741
- * @throws {AdblockSyntaxError} If the expression is invalid
2512
+ * @param raw Source code of the expression
2513
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2514
+ * @returns Token list
2515
+ * @throws {AdblockSyntaxError} If the expression is invalid
2516
+ */
2517
+ private static tokenize;
2518
+ /**
2519
+ * Parses a logical expression.
2520
+ *
2521
+ * @param raw Raw input to parse.
2522
+ * @param options Global parser options.
2523
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2524
+ * @returns Parsed expression
2525
+ * @throws {AdblockSyntaxError} If the expression is invalid
2526
+ */
2527
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): AnyExpressionNode;
2528
+ /**
2529
+ * Generates a string representation of the logical expression (serialization).
2530
+ *
2531
+ * @param node Expression node
2532
+ * @returns String representation of the logical expression
2533
+ */
2534
+ static generate(node: AnyExpressionNode): string;
2535
+ /**
2536
+ * Serializes a variable node to binary format.
2537
+ *
2538
+ * @param node Node to serialize.
2539
+ * @param buffer ByteBuffer for writing binary data.
2540
+ */
2541
+ private static serializeVariableNode;
2542
+ /**
2543
+ * Serializes a parenthesis node to binary format.
2544
+ *
2545
+ * @param node Node to serialize.
2546
+ * @param buffer ByteBuffer for writing binary data.
2547
+ */
2548
+ private static serializeParenthesisNode;
2549
+ /**
2550
+ * Serializes an operator node to binary format.
2551
+ *
2552
+ * @param node Node to serialize.
2553
+ * @param buffer ByteBuffer for writing binary data.
2554
+ */
2555
+ private static serializeOperatorNode;
2556
+ /**
2557
+ * Serializes a logical expression node to binary format.
2558
+ *
2559
+ * @param node Node to serialize.
2560
+ * @param buffer ByteBuffer for writing binary data.
2561
+ */
2562
+ static serialize(node: AnyExpressionNode, buffer: OutputByteBuffer): void;
2563
+ /**
2564
+ * Deserializes a variable node from binary format.
2565
+ *
2566
+ * @param buffer ByteBuffer for reading binary data.
2567
+ * @param node Destination node.
2568
+ * @throws If the binary data is malformed.
2569
+ */
2570
+ private static deserializeVariableNode;
2571
+ /**
2572
+ * Deserializes a parenthesis node from binary format.
2573
+ *
2574
+ * @param buffer ByteBuffer for reading binary data.
2575
+ * @param node Destination node.
2576
+ * @throws If the binary data is malformed.
1742
2577
  */
1743
- private static tokenize;
2578
+ private static deserializeParenthesisNode;
1744
2579
  /**
1745
- * Parses a logical expression.
2580
+ * Deserializes an operator node from binary format.
1746
2581
  *
1747
- * @param raw Source code of the expression
1748
- * @param loc Location of the expression
1749
- * @returns Parsed expression
1750
- * @throws {AdblockSyntaxError} If the expression is invalid
2582
+ * @param buffer ByteBuffer for reading binary data.
2583
+ * @param node Destination node.
2584
+ * @throws If the binary data is malformed.
1751
2585
  */
1752
- static parse(raw: string, loc?: Location): AnyExpressionNode;
2586
+ private static deserializeOperatorNode;
1753
2587
  /**
1754
- * Generates a string representation of the logical expression (serialization).
2588
+ * Deserializes a logical expression node from binary format.
1755
2589
  *
1756
- * @param ast Expression node
1757
- * @returns String representation of the logical expression
2590
+ * @param buffer ByteBuffer for reading binary data.
2591
+ * @param node Destination node.
2592
+ * @throws If the binary data is malformed.
1758
2593
  */
1759
- static generate(ast: AnyExpressionNode): string;
2594
+ static deserialize(buffer: InputByteBuffer, node: Partial<AnyExpressionNode>): void;
1760
2595
  }
1761
2596
 
1762
2597
  /**
1763
- * @file Metadata comments
2598
+ * Known metadata headers.
1764
2599
  */
1765
-
2600
+ declare const KNOWN_METADATA_HEADERS: string[];
1766
2601
  /**
1767
2602
  * `MetadataParser` is responsible for parsing metadata comments.
1768
2603
  * Metadata comments are special comments that specify some properties of the list.
@@ -1776,22 +2611,38 @@ declare class LogicalExpressionParser {
1776
2611
  * the list title is `My List`, and it can be used in the adblocker UI.
1777
2612
  * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#special-comments}
1778
2613
  */
1779
- declare class MetadataCommentRuleParser {
2614
+ declare class MetadataCommentRuleParser extends ParserBase {
1780
2615
  /**
1781
2616
  * Parses a raw rule as a metadata comment.
1782
2617
  *
1783
- * @param raw Raw rule
1784
- * @param loc Base location
2618
+ * @param raw Raw input to parse.
2619
+ * @param options Global parser options.
2620
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1785
2621
  * @returns Metadata comment AST or null (if the raw rule cannot be parsed as a metadata comment)
1786
2622
  */
1787
- static parse(raw: string, loc?: Location): MetadataCommentRule | null;
2623
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): MetadataCommentRule | null;
1788
2624
  /**
1789
- * Converts a metadata comment AST to a string.
2625
+ * Converts a metadata comment rule node to a string.
1790
2626
  *
1791
- * @param ast - Metadata comment AST
1792
- * @returns Raw string
2627
+ * @param node Metadata comment rule node.
2628
+ * @returns Raw string.
2629
+ */
2630
+ static generate(node: MetadataCommentRule): string;
2631
+ /**
2632
+ * Serializes a metadata comment node to binary format.
2633
+ *
2634
+ * @param node Node to serialize.
2635
+ * @param buffer ByteBuffer for writing binary data.
2636
+ */
2637
+ static serialize(node: MetadataCommentRule, buffer: OutputByteBuffer): void;
2638
+ /**
2639
+ * Deserializes a metadata comment node from binary format.
2640
+ *
2641
+ * @param buffer ByteBuffer for reading binary data.
2642
+ * @param node Destination node.
2643
+ * @throws If the binary data is malformed.
1793
2644
  */
1794
- static generate(ast: MetadataCommentRule): string;
2645
+ static deserialize(buffer: InputByteBuffer, node: Partial<MetadataCommentRule>): void;
1795
2646
  }
1796
2647
 
1797
2648
  /**
@@ -1802,18 +2653,19 @@ declare class MetadataCommentRuleParser {
1802
2653
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#non-basic-rules-modifiers}
1803
2654
  * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#options}
1804
2655
  */
1805
- declare class ModifierListParser {
2656
+ declare class ModifierListParser extends ParserBase {
1806
2657
  /**
1807
2658
  * Parses the cosmetic rule modifiers, eg. `third-party,domain=example.com|~example.org`.
1808
2659
  *
1809
2660
  * _Note:_ you should remove `$` separator before passing the raw modifiers to this function,
1810
2661
  * or it will be parsed in the first modifier.
1811
2662
  *
1812
- * @param raw Raw modifier list
1813
- * @param loc Location of the modifier list
2663
+ * @param raw Raw input to parse.
2664
+ * @param options Global parser options.
2665
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1814
2666
  * @returns Parsed modifiers interface
1815
2667
  */
1816
- static parse(raw: string, loc?: Location): ModifierList;
2668
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): ModifierList;
1817
2669
  /**
1818
2670
  * Converts a modifier list AST to a string.
1819
2671
  *
@@ -1821,6 +2673,20 @@ declare class ModifierListParser {
1821
2673
  * @returns Raw string
1822
2674
  */
1823
2675
  static generate(ast: ModifierList): string;
2676
+ /**
2677
+ * Serializes a modifier list node to binary format.
2678
+ *
2679
+ * @param node Node to serialize.
2680
+ * @param buffer ByteBuffer for writing binary data.
2681
+ */
2682
+ static serialize(node: ModifierList, buffer: OutputByteBuffer): void;
2683
+ /**
2684
+ * Deserializes a modifier list node from binary format.
2685
+ *
2686
+ * @param buffer ByteBuffer for reading binary data.
2687
+ * @param node Destination node.
2688
+ */
2689
+ static deserialize(buffer: InputByteBuffer, node: ModifierList): void;
1824
2690
  }
1825
2691
 
1826
2692
  /**
@@ -1829,17 +2695,18 @@ declare class ModifierListParser {
1829
2695
  * @example
1830
2696
  * `match-case`, `~third-party`, `domain=example.com|~example.org`
1831
2697
  */
1832
- declare class ModifierParser {
2698
+ declare class ModifierParser extends ParserBase {
1833
2699
  /**
1834
2700
  * Parses a modifier.
1835
2701
  *
1836
- * @param raw Raw modifier string
1837
- * @param loc Location of the modifier
2702
+ * @param raw Raw input to parse.
2703
+ * @param options Global parser options.
2704
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1838
2705
  *
1839
2706
  * @returns Parsed modifier
1840
2707
  * @throws An error if modifier name or value is empty.
1841
2708
  */
1842
- static parse(raw: string, loc?: Location): Modifier;
2709
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): Modifier;
1843
2710
  /**
1844
2711
  * Generates a string from a modifier (serializes it).
1845
2712
  *
@@ -1847,6 +2714,20 @@ declare class ModifierParser {
1847
2714
  * @returns String representation of the modifier
1848
2715
  */
1849
2716
  static generate(modifier: Modifier): string;
2717
+ /**
2718
+ * Serializes a modifier node to binary format.
2719
+ *
2720
+ * @param node Node to serialize.
2721
+ * @param buffer ByteBuffer for writing binary data.
2722
+ */
2723
+ static serialize(node: Modifier, buffer: OutputByteBuffer): void;
2724
+ /**
2725
+ * Deserializes a modifier node from binary format.
2726
+ *
2727
+ * @param buffer ByteBuffer for reading binary data.
2728
+ * @param node Destination node.
2729
+ */
2730
+ static deserialize(buffer: InputByteBuffer, node: Partial<Modifier>): void;
1850
2731
  }
1851
2732
 
1852
2733
  /**
@@ -1858,15 +2739,18 @@ declare class ModifierParser {
1858
2739
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
1859
2740
  * @see {@link https://help.eyeo.com/adblockplus/how-to-write-filters#basic}
1860
2741
  */
1861
- declare class NetworkRuleParser {
2742
+ declare class NetworkRuleParser extends ParserBase {
1862
2743
  /**
1863
2744
  * Parses a network rule (also known as basic rule).
1864
2745
  *
1865
- * @param raw Raw rule
1866
- * @param loc Location of the rule
2746
+ * @param raw Raw input to parse.
2747
+ * @param options Global parser options.
2748
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1867
2749
  * @returns Network rule AST
2750
+ *
2751
+ * @throws If the rule is syntactically incorrect.
1868
2752
  */
1869
- static parse(raw: string, loc?: Location): NetworkRule;
2753
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): NetworkRule;
1870
2754
  /**
1871
2755
  * Finds the index of the separator character in a network rule.
1872
2756
  *
@@ -1877,10 +2761,24 @@ declare class NetworkRuleParser {
1877
2761
  /**
1878
2762
  * Converts a network rule (basic rule) AST to a string.
1879
2763
  *
1880
- * @param ast - Network rule AST
2764
+ * @param node Network rule node
1881
2765
  * @returns Raw string
1882
2766
  */
1883
- static generate(ast: NetworkRule): string;
2767
+ static generate(node: NetworkRule): string;
2768
+ /**
2769
+ * Serializes a network rule node to binary format.
2770
+ *
2771
+ * @param node Node to serialize.
2772
+ * @param buffer ByteBuffer for writing binary data.
2773
+ */
2774
+ static serialize(node: NetworkRule, buffer: OutputByteBuffer): void;
2775
+ /**
2776
+ * Deserializes a modifier node from binary format.
2777
+ *
2778
+ * @param buffer ByteBuffer for reading binary data.
2779
+ * @param node Destination node.
2780
+ */
2781
+ static deserialize(buffer: InputByteBuffer, node: Partial<NetworkRule>): void;
1884
2782
  }
1885
2783
 
1886
2784
  /**
@@ -1898,16 +2796,17 @@ declare class NotImplementedError extends Error {
1898
2796
  constructor(message?: string | undefined);
1899
2797
  }
1900
2798
 
1901
- declare class ParameterListParser {
2799
+ declare class ParameterListParser extends ParserBase {
1902
2800
  /**
1903
2801
  * Parses a raw parameter list.
1904
2802
  *
1905
- * @param raw Raw parameter list
2803
+ * @param raw Raw input to parse.
2804
+ * @param options Global parser options.
2805
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1906
2806
  * @param separator Separator character (default: comma)
1907
- * @param loc Base location
1908
2807
  * @returns Parameter list AST
1909
2808
  */
1910
- static parse(raw: string, separator?: string, loc?: Location): ParameterList;
2809
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number, separator?: string): ParameterList;
1911
2810
  /**
1912
2811
  * Converts a parameter list AST to a string.
1913
2812
  *
@@ -1916,14 +2815,94 @@ declare class ParameterListParser {
1916
2815
  * @returns String representation of the parameter list
1917
2816
  */
1918
2817
  static generate(params: ParameterList, separator?: string): string;
2818
+ /**
2819
+ * Serializes a parameter list node to binary format.
2820
+ *
2821
+ * @param node Node to serialize.
2822
+ * @param buffer ByteBuffer for writing binary data.
2823
+ * @param frequentValuesMap Optional map of frequent values.
2824
+ * @param toLower Whether to lowercase the value before the frequent value match (defaults to `false`).
2825
+ */
2826
+ static serialize(node: ParameterList, buffer: OutputByteBuffer, frequentValuesMap?: Map<string, number>, toLower?: boolean): void;
2827
+ /**
2828
+ * Deserializes a parameter list node from binary format.
2829
+ *
2830
+ * @param buffer ByteBuffer for reading binary data.
2831
+ * @param node Destination node.
2832
+ * @param frequentValuesMap Optional map of frequent values.
2833
+ * @throws If the binary data is malformed.
2834
+ */
2835
+ static deserialize(buffer: InputByteBuffer, node: ParameterList, frequentValuesMap?: Map<number, string>): void;
1919
2836
  }
1920
2837
 
1921
2838
  /**
1922
- * Pre-processor directives
2839
+ * `HostRuleParser` is responsible for parsing hosts-like rules.
1923
2840
  *
1924
- * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#pre-processor-directives}
1925
- * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#pre-parsing-directives}
2841
+ * HostRule is a structure for simple host-level rules (i.e. /etc/hosts syntax).
2842
+ * It also supports "just domain" syntax. In this case, the IP will be set to 0.0.0.0.
2843
+ *
2844
+ * Rules syntax looks like this:
2845
+ * ```text
2846
+ * IP_address canonical_hostname [aliases...]
2847
+ * ```
2848
+ *
2849
+ * @example
2850
+ * `192.168.1.13 bar.mydomain.org bar` -- ipv4
2851
+ * `ff02::1 ip6-allnodes` -- ipv6
2852
+ * `::1 localhost ip6-localhost ip6-loopback` -- ipv6 aliases
2853
+ * `example.org` -- "just domain" syntax
2854
+ * @see {@link http://man7.org/linux/man-pages/man5/hosts.5.html}
1926
2855
  */
2856
+ declare class HostRuleParser extends ParserBase {
2857
+ static readonly NULL_IP = "0.0.0.0";
2858
+ static readonly COMMENT_MARKER = "#";
2859
+ /**
2860
+ * Parses an etc/hosts-like rule.
2861
+ *
2862
+ * @param raw Raw input to parse.
2863
+ * @param options Global parser options.
2864
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
2865
+ * @returns Host rule node.
2866
+ *
2867
+ * @throws If the input contains invalid data.
2868
+ */
2869
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): HostRule;
2870
+ /**
2871
+ * Converts a host rule node to a raw string.
2872
+ *
2873
+ * @param node Host rule node.
2874
+ * @returns Raw string.
2875
+ */
2876
+ static generate(node: HostRule): string;
2877
+ /**
2878
+ * Serializes a hostname list node to binary format.
2879
+ *
2880
+ * @param node Node to serialize.
2881
+ * @param buffer ByteBuffer for writing binary data.
2882
+ */
2883
+ private static serializeHostnameList;
2884
+ /**
2885
+ * Deserializes a hostname list node from binary format.
2886
+ *
2887
+ * @param buffer ByteBuffer for reading binary data.
2888
+ * @param node Destination node.
2889
+ */
2890
+ private static deserializeHostnameList;
2891
+ /**
2892
+ * Serializes a host rule node to binary format.
2893
+ *
2894
+ * @param node Node to serialize.
2895
+ * @param buffer ByteBuffer for writing binary data.
2896
+ */
2897
+ static serialize(node: HostRule, buffer: OutputByteBuffer): void;
2898
+ /**
2899
+ * Deserializes a modifier node from binary format.
2900
+ *
2901
+ * @param buffer ByteBuffer for reading binary data.
2902
+ * @param node Destination node.
2903
+ */
2904
+ static deserialize(buffer: InputByteBuffer, node: Partial<HostRule>): void;
2905
+ }
1927
2906
 
1928
2907
  /**
1929
2908
  * `PreProcessorParser` is responsible for parsing preprocessor rules.
@@ -1941,7 +2920,7 @@ declare class ParameterListParser {
1941
2920
  * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#pre-processor-directives}
1942
2921
  * @see {@link https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#pre-parsing-directives}
1943
2922
  */
1944
- declare class PreProcessorCommentRuleParser {
2923
+ declare class PreProcessorCommentRuleParser extends ParserBase {
1945
2924
  /**
1946
2925
  * Determines whether the rule is a pre-processor rule.
1947
2926
  *
@@ -1952,19 +2931,35 @@ declare class PreProcessorCommentRuleParser {
1952
2931
  /**
1953
2932
  * Parses a raw rule as a pre-processor comment.
1954
2933
  *
1955
- * @param raw Raw rule
1956
- * @param loc Base location
2934
+ * @param raw Raw input to parse.
2935
+ * @param options Global parser options.
2936
+ * @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
1957
2937
  * @returns
1958
2938
  * Pre-processor comment AST or null (if the raw rule cannot be parsed as a pre-processor comment)
1959
2939
  */
1960
- static parse(raw: string, loc?: Location): PreProcessorCommentRule | null;
2940
+ static parse(raw: string, options?: ParserOptions, baseOffset?: number): PreProcessorCommentRule | null;
1961
2941
  /**
1962
- * Converts a pre-processor comment AST to a string.
2942
+ * Converts a pre-processor comment node to a string.
1963
2943
  *
1964
- * @param ast - Pre-processor comment AST
2944
+ * @param node Pre-processor comment node
1965
2945
  * @returns Raw string
1966
2946
  */
1967
- static generate(ast: PreProcessorCommentRule): string;
2947
+ static generate(node: PreProcessorCommentRule): string;
2948
+ /**
2949
+ * Serializes a pre-processor comment node to binary format.
2950
+ *
2951
+ * @param node Node to serialize.
2952
+ * @param buffer ByteBuffer for writing binary data.
2953
+ */
2954
+ static serialize(node: PreProcessorCommentRule, buffer: OutputByteBuffer): void;
2955
+ /**
2956
+ * Deserializes a pre-processor comment node from binary format.
2957
+ *
2958
+ * @param buffer ByteBuffer for reading binary data.
2959
+ * @param node Destination node.
2960
+ * @throws If the binary data is malformed.
2961
+ */
2962
+ static deserialize(buffer: InputByteBuffer, node: Partial<PreProcessorCommentRule>): void;
1968
2963
  }
1969
2964
 
1970
2965
  /**
@@ -1982,6 +2977,30 @@ declare class RuleConversionError extends Error {
1982
2977
  constructor(message: string);
1983
2978
  }
1984
2979
 
2980
+ /**
2981
+ * @file Customized error for binary schema mismatch.
2982
+ */
2983
+ /**
2984
+ * Customized error for binary schema mismatch.
2985
+ */
2986
+ declare class BinarySchemaMismatchError extends Error {
2987
+ /**
2988
+ * Expected schema version.
2989
+ */
2990
+ expectedVersion: number;
2991
+ /**
2992
+ * Actual schema version.
2993
+ */
2994
+ actualVersion: number;
2995
+ /**
2996
+ * Constructs a new `BinarySchemaMismatchError` instance.
2997
+ *
2998
+ * @param expectedVersion Expected schema version.
2999
+ * @param actualVersion Actual schema version.
3000
+ */
3001
+ constructor(expectedVersion: number, actualVersion: number);
3002
+ }
3003
+
1985
3004
  /**
1986
3005
  * Result of modifier validation:
1987
3006
  * - `{ valid: true }` for valid and _fully supported_ modifier;
@@ -2003,17 +3022,6 @@ type ValidationResult = {
2003
3022
  * Modifier validator class.
2004
3023
  */
2005
3024
  declare class ModifierValidator {
2006
- /**
2007
- * Map of all modifiers data parsed from yaml files.
2008
- */
2009
- private modifiersData;
2010
- /**
2011
- * List of all modifier names for any adblocker.
2012
- *
2013
- * Please note that **deprecated** modifiers are **included** as well.
2014
- */
2015
- private allModifierNames;
2016
- constructor();
2017
3025
  /**
2018
3026
  * Simply checks whether the modifier exists in any adblocker.
2019
3027
  *
@@ -2039,30 +3047,6 @@ declare class ModifierValidator {
2039
3047
  * @returns Result of modifier validation.
2040
3048
  */
2041
3049
  validate: (syntax: AdblockSyntax, rawModifier: Modifier, isException?: boolean) => ValidationResult;
2042
- /**
2043
- * Returns AdGuard documentation URL for given modifier.
2044
- *
2045
- * @param modifier Parsed modifier AST node.
2046
- *
2047
- * @returns AdGuard documentation URL or `null` if not found.
2048
- */
2049
- getAdgDocumentationLink: (modifier: Modifier) => string | null;
2050
- /**
2051
- * Returns Ublock Origin documentation URL for given modifier.
2052
- *
2053
- * @param modifier Parsed modifier AST node.
2054
- *
2055
- * @returns Ublock Origin documentation URL or `null` if not found.
2056
- */
2057
- getUboDocumentationLink: (modifier: Modifier) => string | null;
2058
- /**
2059
- * Returns AdBlock Plus documentation URL for given modifier.
2060
- *
2061
- * @param modifier Parsed modifier AST node.
2062
- *
2063
- * @returns AdBlock Plus documentation URL or `null` if not found.
2064
- */
2065
- getAbpDocumentationLink: (modifier: Modifier) => string | null;
2066
3050
  }
2067
3051
  declare const modifierValidator: ModifierValidator;
2068
3052
 
@@ -2290,8 +3274,28 @@ declare class RuleConverter extends RuleConverterBase {
2290
3274
  * @throws If the rule is invalid or cannot be converted
2291
3275
  */
2292
3276
  static convertToAdg(rule: AnyRule): NodeConversionResult<AnyRule>;
3277
+ /**
3278
+ * Converts an adblock filtering rule to uBlock Origin format, if possible.
3279
+ *
3280
+ * @param rule Rule node to convert
3281
+ * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3282
+ * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3283
+ * If the rule was not converted, the result array will contain the original node with the same object reference
3284
+ * @throws If the rule is invalid or cannot be converted
3285
+ */
3286
+ static convertToUbo(rule: AnyRule): NodeConversionResult<AnyRule>;
2293
3287
  }
2294
3288
 
3289
+ /**
3290
+ * @file Binary schema version.
3291
+ */
3292
+ /**
3293
+ * Binary schema version.
3294
+ * This version number is used to ensure that the binary format is compatible with the current library version.
3295
+ * We increment this number if the serialized format changes in a way that is not backwards-compatible.
3296
+ */
3297
+ declare const BINARY_SCHEMA_VERSION = 1;
3298
+
2295
3299
  /**
2296
3300
  * @file Cosmetic rule separator finder and categorizer
2297
3301
  */
@@ -2313,370 +3317,29 @@ interface CosmeticRuleSeparatorFinderResult {
2313
3317
  /**
2314
3318
  * Utility class for cosmetic rule separators.
2315
3319
  */
2316
- declare class CosmeticRuleSeparatorUtils {
2317
- /**
2318
- * Checks whether the specified separator is an exception.
2319
- *
2320
- * @param separator Separator to check
2321
- * @returns `true` if the separator is an exception, `false` otherwise
2322
- */
2323
- static isException(separator: CosmeticRuleSeparator): boolean;
2324
- /**
2325
- * Checks whether the specified separator is marks an Extended CSS cosmetic rule.
2326
- *
2327
- * @param separator Separator to check
2328
- * @returns `true` if the separator is marks an Extended CSS cosmetic rule, `false` otherwise
2329
- */
2330
- static isExtendedCssMarker(separator: CosmeticRuleSeparator): boolean;
2331
- /**
2332
- * Looks for the cosmetic rule separator in the rule. This is a simplified version that
2333
- * masks the recursive function.
2334
- *
2335
- * @param rule Raw rule
2336
- * @returns Separator result or null if no separator was found
2337
- */
2338
- static find(rule: string): CosmeticRuleSeparatorFinderResult | null;
2339
- }
2340
-
2341
- /**
2342
- * @file Helper file for CSSTree to provide better compatibility with TypeScript.
2343
- * @see {@link https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/62536}
2344
- */
2345
- /**
2346
- * CSSTree node types.
2347
- *
2348
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/ast.md#node-types}
2349
- */
2350
- declare const enum CssTreeNodeType {
2351
- AnPlusB = "AnPlusB",
2352
- Atrule = "Atrule",
2353
- AtrulePrelude = "AtrulePrelude",
2354
- AttributeSelector = "AttributeSelector",
2355
- Block = "Block",
2356
- Brackets = "Brackets",
2357
- CDC = "CDC",
2358
- CDO = "CDO",
2359
- ClassSelector = "ClassSelector",
2360
- Combinator = "Combinator",
2361
- Comment = "Comment",
2362
- Declaration = "Declaration",
2363
- DeclarationList = "DeclarationList",
2364
- Dimension = "Dimension",
2365
- Function = "Function",
2366
- Hash = "Hash",
2367
- Identifier = "Identifier",
2368
- IdSelector = "IdSelector",
2369
- MediaFeature = "MediaFeature",
2370
- MediaQuery = "MediaQuery",
2371
- MediaQueryList = "MediaQueryList",
2372
- NestingSelector = "NestingSelector",
2373
- Nth = "Nth",
2374
- Number = "Number",
2375
- Operator = "Operator",
2376
- Parentheses = "Parentheses",
2377
- Percentage = "Percentage",
2378
- PseudoClassSelector = "PseudoClassSelector",
2379
- PseudoElementSelector = "PseudoElementSelector",
2380
- Ratio = "Ratio",
2381
- Raw = "Raw",
2382
- Rule = "Rule",
2383
- Selector = "Selector",
2384
- SelectorList = "SelectorList",
2385
- String = "String",
2386
- StyleSheet = "StyleSheet",
2387
- TypeSelector = "TypeSelector",
2388
- UnicodeRange = "UnicodeRange",
2389
- Url = "Url",
2390
- Value = "Value",
2391
- WhiteSpace = "WhiteSpace"
2392
- }
2393
- /**
2394
- * Parser context for CSSTree.
2395
- *
2396
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/parsing.md#context}
2397
- */
2398
- declare const enum CssTreeParserContext {
2399
- /**
2400
- * Regular stylesheet, should be suitable in most cases (default)
2401
- */
2402
- stylesheet = "stylesheet",
2403
- /**
2404
- * at-rule (e.g. `@media screen`, `print { ... }`)
2405
- */
2406
- atrule = "atrule",
2407
- /**
2408
- * at-rule prelude (screen, print for example above)
2409
- */
2410
- atrulePrelude = "atrulePrelude",
2411
- /**
2412
- * used to parse comma separated media query list
2413
- */
2414
- mediaQueryList = "mediaQueryList",
2415
- /**
2416
- * used to parse media query
2417
- */
2418
- mediaQuery = "mediaQuery",
2419
- /**
2420
- * rule (e.g. `.foo`, `.bar:hover { color: red; border: 1px solid black; }`)
2421
- */
2422
- rule = "rule",
2423
- /**
2424
- * selector group (`.foo`, `.bar:hover` for rule example)
2425
- */
2426
- selectorList = "selectorList",
2427
- /**
2428
- * selector (`.foo` or `.bar:hover` for rule example)
2429
- */
2430
- selector = "selector",
2431
- /**
2432
- * block with curly braces ({ color: red; border: 1px solid black; } for rule example)
2433
- */
2434
- block = "block",
2435
- /**
2436
- * block content w/o curly braces (`color: red; border: 1px solid black;` for rule example),
2437
- * useful for parsing HTML style attribute value
2438
- */
2439
- declarationList = "declarationList",
2440
- /**
2441
- * declaration (`color: red` or `border: 1px solid black` for rule example)
2442
- */
2443
- declaration = "declaration",
2444
- /**
2445
- * declaration value (`red` or `1px solid black` for rule example)
2446
- */
2447
- value = "value"
2448
- }
2449
-
2450
- /**
2451
- * Additional / helper functions for CSSTree.
2452
- */
2453
- declare class CssTree {
2454
- /**
2455
- * Shifts location of the CSSTree node. Temporary workaround for CSSTree issue:
2456
- * https://github.com/csstree/csstree/issues/251
2457
- *
2458
- * @param root Root CSSTree node
2459
- * @param loc Location to shift
2460
- * @returns Root CSSTree node with shifted location
2461
- */
2462
- static shiftNodePosition(root: CssNode, loc?: Location): CssNode;
2463
- /**
2464
- * Helper function for parsing CSS parts.
2465
- *
2466
- * @param raw Raw CSS input
2467
- * @param context CSSTree context for parsing
2468
- * @param tolerant If `true`, then the parser will not throw an error on parsing fallbacks. Default is `false`
2469
- * @param loc Base location for the parsed node
2470
- * @returns CSSTree node (AST)
2471
- */
2472
- static parse(raw: string, context: CssTreeParserContext, tolerant?: boolean, loc?: Location): CssNode;
2473
- /**
2474
- * Helper function for parsing CSS parts.
2475
- *
2476
- * @param raw Raw CSS input
2477
- * @param context CSSTree context
2478
- * @param tolerant If `true`, then the parser will not throw an error on parsing fallbacks. Default is `false`
2479
- * @param loc Base location for the parsed node
2480
- * @returns CSSTree node (AST)
2481
- */
2482
- static parsePlain(raw: string, context: CssTreeParserContext, tolerant?: boolean, loc?: Location): CssNodePlain;
2483
- /**
2484
- * Checks if the CSSTree node is an ExtendedCSS node.
2485
- *
2486
- * @param node Node to check
2487
- * @param pseudoClasses List of the names of the pseudo classes to check
2488
- * @param attributeSelectors List of the names of the attribute selectors to check
2489
- * @returns `true` if the node is an ExtendedCSS node, otherwise `false`
2490
- */
2491
- static isExtendedCssNode(node: CssNode | CssNodePlain, pseudoClasses: Set<string>, attributeSelectors: Set<string>): boolean;
2492
- /**
2493
- * Walks through the CSSTree node and returns all ExtendedCSS nodes.
2494
- *
2495
- * @param selectorList Selector list (can be a string or a CSSTree node)
2496
- * @param pseudoClasses List of the names of the pseudo classes to check
2497
- * @param attributeSelectors List of the names of the attribute selectors to check
2498
- * @returns Extended CSS nodes (pseudos and attributes)
2499
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/ast.md#selectorlist}
2500
- */
2501
- static getSelectorExtendedCssNodes(selectorList: string | SelectorList | SelectorListPlain, pseudoClasses?: Set<string>, attributeSelectors?: Set<string>): CssNode[];
2502
- /**
2503
- * Checks if the selector contains any ExtendedCSS nodes. It is a faster alternative to
2504
- * `getSelectorExtendedCssNodes` if you only need to know if the selector contains any ExtendedCSS nodes,
2505
- * because it stops the search on the first ExtendedCSS node instead of going through the whole selector
2506
- * and collecting all ExtendedCSS nodes.
2507
- *
2508
- * @param selectorList Selector list (can be a string or a CSSTree node)
2509
- * @param pseudoClasses List of the names of the pseudo classes to check
2510
- * @param attributeSelectors List of the names of the attribute selectors to check
2511
- * @returns `true` if the selector contains any ExtendedCSS nodes
2512
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/ast.md#selectorlist}
2513
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/traversal.md#findast-fn}
2514
- */
2515
- static hasAnySelectorExtendedCssNode(selectorList: string | SelectorList | SelectorListPlain, pseudoClasses?: Set<string>, attributeSelectors?: Set<string>): boolean;
2516
- /**
2517
- * Checks if the node is a forbidden function (unsafe resource loading). Typically it is used to check
2518
- * if the node is a `url()` function, which is a security risk when using filter lists from untrusted
2519
- * sources.
2520
- *
2521
- * @param node Node to check
2522
- * @param forbiddenFunctions Set of the names of the functions to check
2523
- * @returns `true` if the node is a forbidden function
2524
- */
2525
- static isForbiddenFunction(node: CssNode | CssNodePlain, forbiddenFunctions?: Set<string>): boolean;
2526
- /**
2527
- * Gets the list of the forbidden function nodes in the declaration block. Typically it is used to get
2528
- * the list of the functions that can be used to load external resources, which is a security risk
2529
- * when using filter lists from untrusted sources.
2530
- *
2531
- * @param declarationList Declaration list to check (can be a string or a CSSTree node)
2532
- * @param forbiddenFunctions Set of the names of the functions to check
2533
- * @returns List of the forbidden function nodes in the declaration block (can be empty)
2534
- */
2535
- static getForbiddenFunctionNodes(declarationList: string | DeclarationList | DeclarationListPlain, forbiddenFunctions?: Set<string>): CssNode[];
2536
- /**
2537
- * Checks if the declaration block contains any forbidden functions. Typically it is used to check
2538
- * if the declaration block contains any functions that can be used to load external resources,
2539
- * which is a security risk when using filter lists from untrusted sources.
2540
- *
2541
- * @param declarationList Declaration list to check (can be a string or a CSSTree node)
2542
- * @param forbiddenFunctions Set of the names of the functions to check
2543
- * @returns `true` if the declaration block contains any forbidden functions
2544
- * @throws If you pass a string, but it is not a valid CSS
2545
- * @throws If you pass an invalid CSSTree node / AST
2546
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/ast.md#declarationlist}
2547
- * @see {@link https://github.com/AdguardTeam/AdguardBrowserExtension/issues/1196}
2548
- * @see {@link https://github.com/AdguardTeam/AdguardBrowserExtension/issues/1920}
2549
- */
2550
- static hasAnyForbiddenFunction(declarationList: string | DeclarationList | DeclarationListPlain, forbiddenFunctions?: Set<string>): boolean;
2551
- /**
2552
- * Generates string representation of the media query list.
2553
- *
2554
- * @param ast Media query list AST
2555
- * @returns String representation of the media query list
2556
- */
2557
- static generateMediaQueryList(ast: MediaQueryList): string;
2558
- /**
2559
- * Generates string representation of the media query.
2560
- *
2561
- * @param ast Media query AST
2562
- * @returns String representation of the media query
2563
- */
2564
- static generateMediaQuery(ast: MediaQuery): string;
2565
- /**
2566
- * Generates string representation of the selector list.
2567
- *
2568
- * @param ast SelectorList AST
2569
- * @returns String representation of the selector list
2570
- */
2571
- static generateSelectorList(ast: SelectorList): string;
2572
- /**
2573
- * Selector generation based on CSSTree's AST. This is necessary because CSSTree
2574
- * only adds spaces in some edge cases.
2575
- *
2576
- * @param ast CSS Tree AST
2577
- * @returns CSS selector as string
2578
- */
2579
- static generateSelector(ast: Selector): string;
2580
- /**
2581
- * Generates string representation of the selector list.
2582
- *
2583
- * @param ast SelectorList AST
2584
- * @returns String representation of the selector list
2585
- */
2586
- static generateSelectorListPlain(ast: SelectorListPlain): string;
2587
- /**
2588
- * Selector generation based on CSSTree's AST. This is necessary because CSSTree
2589
- * only adds spaces in some edge cases.
2590
- *
2591
- * @param ast CSS Tree AST
2592
- * @returns CSS selector as string
2593
- */
2594
- static generateSelectorPlain(ast: SelectorPlain): string;
2595
- /**
2596
- * Block generation based on CSSTree's AST. This is necessary because CSSTree only adds spaces in some edge cases.
2597
- *
2598
- * @param ast CSS Tree AST
2599
- * @returns CSS selector as string
2600
- */
2601
- static generateDeclarationList(ast: DeclarationList): string;
2602
- /**
2603
- * Helper method to assert that the attribute selector has a value
2604
- *
2605
- * @param node Attribute selector node
2606
- */
2607
- static assertAttributeSelectorHasStringValue(node: AttributeSelector): asserts node is AttributeSelector & {
2608
- value: {
2609
- type: 'String';
2610
- };
2611
- };
2612
- /**
2613
- * Helper method to assert that the pseudo-class selector has at least one argument
2614
- *
2615
- * @param node Pseudo-class selector node
2616
- */
2617
- static assertPseudoClassHasAnyArgument(node: PseudoClassSelectorPlain): asserts node is PseudoClassSelectorPlain & {
2618
- children: CssNodePlain[];
2619
- };
2620
- /**
2621
- * Helper method to parse an attribute selector value as a number
2622
- *
2623
- * @param node Attribute selector node
2624
- * @returns Parsed attribute selector value as a number
2625
- * @throws If the attribute selector hasn't a string value or the string value is can't be parsed as a number
2626
- */
2627
- static parseAttributeSelectorValueAsNumber(node: AttributeSelector): number;
2628
- /**
2629
- * Helper method to parse a pseudo-class argument as a number
2630
- *
2631
- * @param node Pseudo-class selector node to parse
2632
- * @returns Parsed pseudo-class argument as a number
2633
- */
2634
- static parsePseudoClassArgumentAsNumber(node: PseudoClassSelectorPlain): number;
2635
- /**
2636
- * Helper method to create an attribute selector node
2637
- *
2638
- * @param name Name of the attribute
2639
- * @param value Value of the attribute
2640
- * @param matcher Matcher of the attribute
2641
- * @param flags Flags of the attribute
2642
- * @returns Attribute selector node
2643
- * @see {@link https://github.com/csstree/csstree/blob/master/docs/ast.md#attributeselector}
2644
- */
2645
- static createAttributeSelectorNode(name: string, value: string, matcher?: string, flags?: string | null): AttributeSelector;
2646
- /**
2647
- * Helper function to rename a CSSTree pseudo-class node
2648
- *
2649
- * @param node Node to rename
2650
- * @param name New name
2651
- */
2652
- static renamePseudoClass(node: PseudoClassSelector, name: string): void;
3320
+ declare class CosmeticRuleSeparatorUtils {
2653
3321
  /**
2654
- * Helper function to generate a raw string from a pseudo-class
2655
- * selector's children
3322
+ * Checks whether the specified separator is an exception.
2656
3323
  *
2657
- * @param node Pseudo-class selector node
2658
- * @returns Generated pseudo-class value
2659
- * @example
2660
- * - `:nth-child(2n+1)` -> `2n+1`
2661
- * - `:matches-path(/foo/bar)` -> `/foo/bar`
3324
+ * @param separator Separator to check
3325
+ * @returns `true` if the separator is an exception, `false` otherwise
2662
3326
  */
2663
- static generatePseudoClassValue(node: PseudoClassSelector): string;
3327
+ static isException(separator: CosmeticRuleSeparator): boolean;
2664
3328
  /**
2665
- * Helper function to generate a raw string from a function selector's children
3329
+ * Checks whether the specified separator is marks an Extended CSS cosmetic rule.
2666
3330
  *
2667
- * @param node Function node
2668
- * @returns Generated function value
2669
- * @example `responseheader(name)` -> `name`
3331
+ * @param separator Separator to check
3332
+ * @returns `true` if the separator is marks an Extended CSS cosmetic rule, `false` otherwise
2670
3333
  */
2671
- static generateFunctionValue(node: FunctionNode): string;
3334
+ static isExtendedCssMarker(separator: CosmeticRuleSeparator): boolean;
2672
3335
  /**
2673
- * Helper function to generate a raw string from a function selector's children
3336
+ * Looks for the cosmetic rule separator in the rule. This is a simplified version that
3337
+ * masks the recursive function.
2674
3338
  *
2675
- * @param node Function node
2676
- * @returns Generated function value
2677
- * @example `responseheader(name)` -> `name`
3339
+ * @param rule Raw rule
3340
+ * @returns Separator result or null if no separator was found
2678
3341
  */
2679
- static generateFunctionPlainValue(node: FunctionNodePlain): string;
3342
+ static find(rule: string): CosmeticRuleSeparatorFinderResult | null;
2680
3343
  }
2681
3344
 
2682
3345
  declare class DomainUtils {
@@ -2690,7 +3353,7 @@ declare class DomainUtils {
2690
3353
  }
2691
3354
 
2692
3355
  /**
2693
- * @file Utility functions for logical expression AST.
3356
+ * @file Utility functions for logical expression node.
2694
3357
  */
2695
3358
 
2696
3359
  /**
@@ -2700,24 +3363,24 @@ type VariableTable = {
2700
3363
  [key: string]: boolean;
2701
3364
  };
2702
3365
  /**
2703
- * Utility functions for logical expression AST.
3366
+ * Utility functions for logical expression node.
2704
3367
  */
2705
3368
  declare class LogicalExpressionUtils {
2706
3369
  /**
2707
3370
  * Get all variables in the expression.
2708
3371
  *
2709
- * @param ast Logical expression AST
3372
+ * @param node Logical expression node
2710
3373
  * @returns List of variables in the expression (nodes)
2711
3374
  * @example
2712
3375
  * If the expression is `a && b || c`, the returned list will be
2713
3376
  * nodes for `a`, `b`, and `c`.
2714
3377
  */
2715
- static getVariables(ast: AnyExpressionNode): ExpressionVariableNode[];
3378
+ static getVariables(node: AnyExpressionNode): ExpressionVariableNode[];
2716
3379
  /**
2717
3380
  * Evaluate the parsed logical expression. You'll need to provide a
2718
3381
  * variable table.
2719
3382
  *
2720
- * @param ast Logical expression AST
3383
+ * @param node Logical expression node
2721
3384
  * @param table Variable table (key: variable name, value: boolean)
2722
3385
  * @returns Evaluation result
2723
3386
  * @example
@@ -2732,34 +3395,9 @@ declare class LogicalExpressionUtils {
2732
3395
  * );
2733
3396
  * ```
2734
3397
  */
2735
- static evaluate(ast: AnyExpressionNode, table: VariableTable): boolean;
3398
+ static evaluate(node: AnyExpressionNode, table: VariableTable): boolean;
2736
3399
  }
2737
3400
 
2738
- /**
2739
- * @file Utility functions for location and location range management.
2740
- */
2741
-
2742
- /**
2743
- * Shifts the specified location by the specified offset.
2744
- *
2745
- * @param loc Location to shift
2746
- * @param offset Offset to shift by
2747
- * @returns Location shifted by the specified offset
2748
- */
2749
- declare function shiftLoc(loc: Location, offset: number): Location;
2750
- /**
2751
- * Calculates a location range from the specified base location and offsets.
2752
- *
2753
- * Since every adblock rule is a single line, the start and end locations
2754
- * of the range will have the same line, no need to calculate it here.
2755
- *
2756
- * @param loc Base location
2757
- * @param startOffset Start offset
2758
- * @param endOffset End offset
2759
- * @returns Calculated location range
2760
- */
2761
- declare function locRange(loc: Location, startOffset: number, endOffset: number): LocationRange;
2762
-
2763
3401
  declare const ADBLOCK_URL_START: string;
2764
3402
  declare const ADBLOCK_URL_START_REGEX = "^(http|https|ws|wss)://([a-z0-9-_.]+\\.)?";
2765
3403
  declare const ADBLOCK_URL_SEPARATOR = "^";
@@ -2866,6 +3504,14 @@ declare class QuoteUtils {
2866
3504
  * @returns String without quotes
2867
3505
  */
2868
3506
  static removeQuotes(string: string): string;
3507
+ /**
3508
+ * Removes bounding quotes from a string, if any, and unescapes the escaped quotes,
3509
+ * like transforming `'abc\'def'` to `abc'def`.
3510
+ *
3511
+ * @param string Input string
3512
+ * @returns String without quotes
3513
+ */
3514
+ static removeQuotesAndUnescape(string: string): string;
2869
3515
  /**
2870
3516
  * Wraps given `strings` with `quote` (defaults to single quote `'`)
2871
3517
  * and joins them with `separator` (defaults to comma+space `, `).
@@ -2883,12 +3529,104 @@ declare class QuoteUtils {
2883
3529
  }
2884
3530
 
2885
3531
  /**
2886
- * Known metadata headers
3532
+ * @file Position provider class.
3533
+ */
3534
+ /**
3535
+ * Represents a position in the source code.
3536
+ */
3537
+ interface Position {
3538
+ /**
3539
+ * 1-based line number
3540
+ */
3541
+ line: number;
3542
+ /**
3543
+ * 1-based column number
3544
+ */
3545
+ column: number;
3546
+ }
3547
+ /**
3548
+ * Class responsible for converting a character offset in source code into a line and column position.
3549
+ * This conversion is particularly needed in linters and VSCode extensions,
3550
+ * where line and column numbers are more human-friendly and intuitive than character offsets.
3551
+ * Moreover, the VSCode diagnostics API does not directly support character offsets,
3552
+ * it also requires line and column numbers.
3553
+ */
3554
+ declare class PositionProvider {
3555
+ /**
3556
+ * Maps a character offset to a line number.
3557
+ */
3558
+ private offsetToLine;
3559
+ /**
3560
+ * Maps a line number to the starting character offset of that line.
3561
+ */
3562
+ private lineStartOffsets;
3563
+ /**
3564
+ * Constructs a new PositionProvider instance.
3565
+ *
3566
+ * @param sourceCode The source code as a string.
3567
+ */
3568
+ constructor(sourceCode: string);
3569
+ /**
3570
+ * Converts a character offset to a line and column position.
3571
+ *
3572
+ * @param offset The zero-based character offset in the source code.
3573
+ * @returns A Position object containing the 1-based line and column number, or null if the offset is out of range.
3574
+ */
3575
+ convertOffsetToPosition(offset: number): Position | null;
3576
+ }
3577
+
3578
+ /**
3579
+ * @file Utility for encoding strings to byte sequences.
3580
+ */
3581
+ interface TextEncoderPolyfillResult {
3582
+ readonly written: number;
3583
+ readonly read: number;
3584
+ }
3585
+ /**
3586
+ * Encodes an UTF-8 string into a byte sequence according to the WHATWG spec.
3587
+ *
3588
+ * @param str String to encode.
3589
+ * @param buffer Buffer to write the encoded bytes to.
3590
+ * @returns Number of bytes written to the buffer.
3591
+ * @see {@link https://encoding.spec.whatwg.org/#utf-8-encoder}
3592
+ * @note Bytes written maybe larger than the string length, but never smaller.
3593
+ * For example, the string '你好' has a length of 2, but its byte representation has a length of 6.
3594
+ */
3595
+ declare const encodeIntoPolyfill: (str: string, buffer: Uint8Array) => TextEncoderPolyfillResult;
3596
+
3597
+ /**
3598
+ * @file Optimized utility for decoding strings from byte sequences.
3599
+ */
3600
+ /**
3601
+ * Decodes a byte sequence into an UTF-8 string according to the WHATWG spec.
3602
+ * Optimized for performance.
3603
+ *
3604
+ * @param buffer Buffer to read the bytes from.
3605
+ * @param start Start offset in the buffer.
3606
+ * @param end End offset in the buffer.
3607
+ * @returns Decoded string.
3608
+ * @see {@link https://encoding.spec.whatwg.org/#utf-8-decoder}
3609
+ */
3610
+ declare const decodeTextPolyfill: (buffer: Uint8Array, start?: number, end?: number) => string;
3611
+
3612
+ /**
3613
+ * Utility functions for categorizing rules.
2887
3614
  */
2888
- declare const METADATA_HEADERS: string[];
3615
+ declare class RuleCategorizer {
3616
+ /**
3617
+ * Determines the type of a given raw cosmetic rule.
3618
+ *
3619
+ * @param rawRule Raw rule to check.
3620
+ *
3621
+ * @returns Type of the cosmetic rule or `null` if the rule is cannot be parsed as a cosmetic rule.
3622
+ */
3623
+ static getCosmeticRuleType(rawRule: string): CosmeticRuleType | null;
3624
+ }
2889
3625
 
2890
3626
  /**
2891
- * Known Extended CSS pseudo-classes. Please, keep this list sorted.
3627
+ * _ALL_ known Extended CSS pseudo-classes. Please, keep this list sorted.
3628
+ * It includes strict pseudo-classes and additional pseudo-classes that may be
3629
+ * supported by some browsers natively.
2892
3630
  */
2893
3631
  declare const EXT_CSS_PSEUDO_CLASSES: Set<string>;
2894
3632
  /**
@@ -2905,9 +3643,456 @@ declare const EXT_CSS_LEGACY_ATTRIBUTES: Set<string>;
2905
3643
  */
2906
3644
  declare const FORBIDDEN_CSS_FUNCTIONS: Set<string>;
2907
3645
 
3646
+ /**
3647
+ * @file Base compatibility data schema, which is commonly used in compatibility tables.
3648
+ */
3649
+
3650
+ /**
3651
+ * Zod schema for base compatibility data with camelCase properties.
3652
+ */
3653
+ declare const baseCompatibilityDataSchemaCamelCase: zod.ZodEffects<zod.ZodTypeAny, {
3654
+ name: string;
3655
+ description: string | null;
3656
+ aliases: string[] | null;
3657
+ docs: string | null;
3658
+ versionAdded: string | null;
3659
+ versionRemoved: string | null;
3660
+ deprecated: boolean;
3661
+ deprecationMessage: string | null;
3662
+ removed: boolean;
3663
+ removalMessage: string | null;
3664
+ }, any>;
3665
+ /**
3666
+ * Type of the base compatibility data schema.
3667
+ */
3668
+ type BaseCompatibilityDataSchema = zod.infer<typeof baseCompatibilityDataSchemaCamelCase>;
3669
+
3670
+ /**
3671
+ * @file Schema for modifier data.
3672
+ */
3673
+
3674
+ /**
3675
+ * Zod schema for modifier data.
3676
+ */
3677
+ declare const modifierDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3678
+ name: string;
3679
+ description: string | null;
3680
+ aliases: string[] | null;
3681
+ docs: string | null;
3682
+ versionAdded: string | null;
3683
+ versionRemoved: string | null;
3684
+ deprecated: boolean;
3685
+ deprecationMessage: string | null;
3686
+ removed: boolean;
3687
+ removalMessage: string | null;
3688
+ conflicts: string[] | null;
3689
+ inverseConflicts: boolean;
3690
+ assignable: boolean;
3691
+ negatable: boolean;
3692
+ blockOnly: boolean;
3693
+ exceptionOnly: boolean;
3694
+ valueOptional: boolean;
3695
+ valueFormat: string | null;
3696
+ }, any>;
3697
+ /**
3698
+ * Type of the modifier data schema.
3699
+ */
3700
+ type ModifierDataSchema = zod.infer<typeof modifierDataSchema>;
3701
+
3702
+ /**
3703
+ * @file Schema for redirect data.
3704
+ */
3705
+
3706
+ /**
3707
+ * Zod schema for redirect data.
3708
+ */
3709
+ declare const redirectDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3710
+ name: string;
3711
+ description: string | null;
3712
+ aliases: string[] | null;
3713
+ docs: string | null;
3714
+ versionAdded: string | null;
3715
+ versionRemoved: string | null;
3716
+ deprecated: boolean;
3717
+ deprecationMessage: string | null;
3718
+ removed: boolean;
3719
+ removalMessage: string | null;
3720
+ isBlocking: boolean;
3721
+ }, any>;
3722
+ /**
3723
+ * Type of the redirect data schema.
3724
+ */
3725
+ type RedirectDataSchema = zod.infer<typeof redirectDataSchema>;
3726
+
3727
+ /**
3728
+ * @file Schema for scriptlet data.
3729
+ */
3730
+
3731
+ /**
3732
+ * Zod schema for scriptlet data.
3733
+ */
3734
+ declare const scriptletDataSchema: zod.ZodEffects<zod.ZodTypeAny, {
3735
+ name: string;
3736
+ description: string | null;
3737
+ aliases: string[] | null;
3738
+ docs: string | null;
3739
+ versionAdded: string | null;
3740
+ versionRemoved: string | null;
3741
+ deprecated: boolean;
3742
+ deprecationMessage: string | null;
3743
+ removed: boolean;
3744
+ removalMessage: string | null;
3745
+ parameters?: {
3746
+ name: string;
3747
+ debug: boolean;
3748
+ pattern: string | null;
3749
+ description: string | null;
3750
+ default: string | null;
3751
+ required: boolean;
3752
+ }[] | undefined;
3753
+ }, any>;
3754
+ /**
3755
+ * Type of the scriptlet data schema.
3756
+ */
3757
+ type ScriptletDataSchema = zod.infer<typeof scriptletDataSchema>;
3758
+
3759
+ /**
3760
+ * @file Platform schema.
3761
+ */
3762
+
3763
+ /**
3764
+ * Parses a raw platform string into a platform bitmask.
3765
+ *
3766
+ * @param rawPlatforms Raw platform string, e.g. 'adg_safari_any|adg_os_any'.
3767
+ *
3768
+ * @returns Platform bitmask.
3769
+ */
3770
+ declare const parseRawPlatforms: (rawPlatforms: string) => number;
3771
+
3772
+ /**
3773
+ * @file Provides platform enums.
3774
+ * The difference between specific and generic platforms is that specific platforms are individual platforms
3775
+ * (e.g. AdGuard for Windows, AdGuard for Android, etc.),
3776
+ * while generic platforms are groups of specific platforms
3777
+ * (e.g. AdGuard for any OS, AdGuard for any Chromium-based extension, etc.).
3778
+ */
3779
+ /**
3780
+ * List of specific platforms.
3781
+ */
3782
+ declare enum SpecificPlatform {
3783
+ AdgOsWindows = 1,
3784
+ AdgOsMac = 2,
3785
+ AdgOsAndroid = 4,
3786
+ AdgExtChrome = 8,
3787
+ AdgExtOpera = 16,
3788
+ AdgExtEdge = 32,
3789
+ AdgExtFirefox = 64,
3790
+ AdgCbAndroid = 128,
3791
+ AdgCbIos = 256,
3792
+ AdgCbSafari = 512,
3793
+ UboExtChrome = 1024,
3794
+ UboExtOpera = 2048,
3795
+ UboExtEdge = 4096,
3796
+ UboExtFirefox = 8192,
3797
+ AbpExtChrome = 16384,
3798
+ AbpExtOpera = 32768,
3799
+ AbpExtEdge = 65536,
3800
+ AbpExtFirefox = 131072
3801
+ }
3802
+ /**
3803
+ * List of generic platforms (combinations of specific platforms).
3804
+ */
3805
+ declare enum GenericPlatform {
3806
+ AdgOsAny = 7,
3807
+ AdgSafariAny = 768,
3808
+ AdgExtChromium = 56,
3809
+ AdgExtAny = 120,
3810
+ AdgAny = 1023,
3811
+ UboExtChromium = 7168,
3812
+ UboExtAny = 15360,
3813
+ UboAny = 15360,
3814
+ AbpExtChromium = 114688,
3815
+ AbpExtAny = 245760,
3816
+ AbpAny = 245760,
3817
+ Any = 262143
3818
+ }
3819
+
3820
+ /**
3821
+ * @file Compatibility tables types.
3822
+ */
3823
+ /**
3824
+ * Map with shared storage.
3825
+ * The idea is to avoid storing the same value multiple times in the map,
3826
+ * so the value is stored in the `shared` array and the map refers to the index in the `shared` array.
3827
+ *
3828
+ * @template K Type of the map keys.
3829
+ * @template V Type of the map values.
3830
+ */
3831
+ interface MapWithSharedStorage<K extends string | number | symbol, V> {
3832
+ /**
3833
+ * Shared storage.
3834
+ */
3835
+ shared: V[];
3836
+ /**
3837
+ * Map of the values where the value is a pointer to the shared storage (refers to the index in the `shared` array).
3838
+ */
3839
+ map: Record<K, number>;
3840
+ }
3841
+ /**
3842
+ * Compatibility table row.
3843
+ *
3844
+ * @template T Type of the compatibility data.
3845
+ */
3846
+ type CompatibilityTableRow<T> = MapWithSharedStorage<number, T>;
3847
+ /**
3848
+ * Compatibility table.
3849
+ *
3850
+ * @template T Type of the compatibility data.
3851
+ */
3852
+ type CompatibilityTable<T> = MapWithSharedStorage<string, CompatibilityTableRow<T>>;
3853
+
3854
+ /**
3855
+ * @file Provides common compatibility table methods.
3856
+ */
3857
+
3858
+ /**
3859
+ * Lists all supported entity records by a product.
3860
+ *
3861
+ * Keys are compatibility flags, values are compatibility data records.
3862
+ *
3863
+ * @template T Compatibility data schema.
3864
+ */
3865
+ type ProductRecords<T> = {
3866
+ [key: string]: T;
3867
+ };
3868
+ /**
3869
+ * Defines a compatibility table row by product.
3870
+ *
3871
+ * Keys are Adblock syntaxes, values are product records.
3872
+ *
3873
+ * @template T Compatibility data schema.
3874
+ */
3875
+ type RowByProduct<T> = {
3876
+ [AdblockSyntax.Adg]: ProductRecords<T>;
3877
+ [AdblockSyntax.Ubo]: ProductRecords<T>;
3878
+ [AdblockSyntax.Abp]: ProductRecords<T>;
3879
+ };
3880
+ /**
3881
+ * Defines multiple compatibility table rows by product.
3882
+ *
3883
+ * @template T Compatibility data schema.
3884
+ */
3885
+ type RowsByProduct<T> = RowByProduct<T>[];
3886
+ /**
3887
+ * Single platform records type.
3888
+ *
3889
+ * Keys are platform enums values, values are compatibility data records.
3890
+ *
3891
+ * @template T Compatibility data schema.
3892
+ */
3893
+ type SinglePlatformRecords<T> = {
3894
+ [key: string]: T;
3895
+ };
3896
+ /**
3897
+ * Name transformer function type. This function is used to normalize compatibility data names before processing them,
3898
+ * e.g. converting to lowercase, remove unnecessary prefixes, etc.
3899
+ *
3900
+ * @param name Compatibility data name.
3901
+ *
3902
+ * @returns Normalized name.
3903
+ */
3904
+ type NameTransformer = (name: string) => string;
3905
+ /**
3906
+ * Base compatibility table class which provides common methods to work with compatibility data.
3907
+ *
3908
+ * @template T Compatibility data schema.
3909
+ */
3910
+ declare abstract class CompatibilityTableBase<T extends BaseCompatibilityDataSchema> {
3911
+ /**
3912
+ * Compatibility table data.
3913
+ */
3914
+ private data;
3915
+ /**
3916
+ * Optional name transformer function. If provided,
3917
+ * it will be called in all methods before processing compatibility data names.
3918
+ */
3919
+ private readonly nameTransformer;
3920
+ /**
3921
+ * Creates a new instance of the common compatibility table.
3922
+ *
3923
+ * @param data Compatibility table data.
3924
+ * @param nameTransformer Optional name transformer function.
3925
+ */
3926
+ constructor(data: CompatibilityTable<T>, nameTransformer?: NameTransformer | null);
3927
+ /**
3928
+ * Helper method to get a 'row' from the compatibility table data by name.
3929
+ *
3930
+ * @param name Compatibility data name.
3931
+ * @returns Compatibility table row storage or `null` if not found.
3932
+ */
3933
+ private getRowStorage;
3934
+ /**
3935
+ * Checks whether a compatibility data `name` exists for any platform.
3936
+ *
3937
+ * @note Technically, do the same as `exists()` method with generic platform _any_
3938
+ * but it is faster because it does not apply complex logic.
3939
+ *
3940
+ * @param name Compatibility data name.
3941
+ *
3942
+ * @returns True if the compatibility data exists, false otherwise.
3943
+ */
3944
+ existsAny(name: string): boolean;
3945
+ /**
3946
+ * Checks whether a compatibility data `name` exists for a specified platform.
3947
+ *
3948
+ * @param name Compatibility data name.
3949
+ * @param platform Specific or generic platform.
3950
+ *
3951
+ * @returns True if the compatibility data exists, false otherwise.
3952
+ */
3953
+ exists(name: string, platform: SpecificPlatform | GenericPlatform): boolean;
3954
+ /**
3955
+ * Returns a compatibility data by name and specific platform.
3956
+ *
3957
+ * @param name The name of the compatibility data.
3958
+ * @param platform The specific platform.
3959
+ *
3960
+ * @returns A single compatibility data or `null` if not found.
3961
+ */
3962
+ getSingle(name: string, platform: SpecificPlatform): T | null;
3963
+ /**
3964
+ * Returns all compatibility data records for name and specified platform.
3965
+ *
3966
+ * @param name Compatibility data name.
3967
+ * @param platform Specific or generic platform.
3968
+ *
3969
+ * @returns Multiple records grouped by platforms.
3970
+ * Technically, it is an object where keys are platform enums values and values are compatibility data records.
3971
+ *
3972
+ * @note Platform enum values can be converted to string names using {@link getSpecificPlatformName} on demand.
3973
+ */
3974
+ getMultiple(name: string, platform: SpecificPlatform | GenericPlatform): SinglePlatformRecords<T> | null;
3975
+ /**
3976
+ * Returns all compatibility data records for the specified platform.
3977
+ *
3978
+ * @param platform Specific or generic platform.
3979
+ *
3980
+ * @returns Array of multiple records grouped by platforms.
3981
+ */
3982
+ getAllMultiple(platform: SpecificPlatform | GenericPlatform): SinglePlatformRecords<T>[];
3983
+ /**
3984
+ * Returns the first compatibility data record for name and specified platform.
3985
+ *
3986
+ * @param name Compatibility data name.
3987
+ * @param platform Specific or generic platform.
3988
+ *
3989
+ * @returns First found compatibility data record or `null` if not found.
3990
+ */
3991
+ getFirst(name: string, platform: SpecificPlatform | GenericPlatform): T | null;
3992
+ /**
3993
+ * Returns all compatibility data records for the specified name.
3994
+ *
3995
+ * @param name Compatibility data name.
3996
+ *
3997
+ * @returns Array of multiple records grouped by platforms.
3998
+ */
3999
+ getRow(name: string): T[];
4000
+ /**
4001
+ * Returns all compatibility data grouped by products.
4002
+ *
4003
+ * @returns Array of multiple records grouped by products.
4004
+ */
4005
+ getRowsByProduct(): RowsByProduct<T>;
4006
+ }
4007
+
4008
+ /**
4009
+ * @file Compatibility tables for modifiers.
4010
+ */
4011
+
4012
+ /**
4013
+ * Compatibility table for modifiers.
4014
+ */
4015
+ declare class ModifiersCompatibilityTable extends CompatibilityTableBase<ModifierDataSchema> {
4016
+ /**
4017
+ * Creates a new instance of the compatibility table for modifiers.
4018
+ *
4019
+ * @param data Compatibility table data.
4020
+ */
4021
+ constructor(data: CompatibilityTable<ModifierDataSchema>);
4022
+ }
4023
+ /**
4024
+ * Compatibility table instance for modifiers.
4025
+ */
4026
+ declare const modifiersCompatibilityTable: ModifiersCompatibilityTable;
4027
+
4028
+ /**
4029
+ * @file Compatibility tables for redirects.
4030
+ */
4031
+
4032
+ /**
4033
+ * Compatibility table for redirects.
4034
+ */
4035
+ declare class RedirectsCompatibilityTable extends CompatibilityTableBase<RedirectDataSchema> {
4036
+ /**
4037
+ * Creates a new instance of the compatibility table for redirects.
4038
+ *
4039
+ * @param data Compatibility table data.
4040
+ */
4041
+ constructor(data: CompatibilityTable<RedirectDataSchema>);
4042
+ }
4043
+ /**
4044
+ * Compatibility table instance for redirects.
4045
+ */
4046
+ declare const redirectsCompatibilityTable: RedirectsCompatibilityTable;
4047
+
4048
+ /**
4049
+ * @file Compatibility tables for scriptlets.
4050
+ */
4051
+
4052
+ /**
4053
+ * Compatibility table for scriptlets.
4054
+ */
4055
+ declare class ScriptletsCompatibilityTable extends CompatibilityTableBase<ScriptletDataSchema> {
4056
+ }
4057
+ /**
4058
+ * Compatibility table instance for scriptlets.
4059
+ */
4060
+ declare const scriptletsCompatibilityTable: ScriptletsCompatibilityTable;
4061
+
4062
+ /**
4063
+ * @file Provides platform mapping and helper functions.
4064
+ */
4065
+
4066
+ /**
4067
+ * Check if the platform is a generic platform.
4068
+ *
4069
+ * @param platform Platform to check.
4070
+ *
4071
+ * @returns True if the platform is a generic platform, false otherwise.
4072
+ */
4073
+ declare const isGenericPlatform: (platform: number) => boolean;
4074
+ /**
4075
+ * Returns the platform enum value for the given platform string name.
4076
+ *
4077
+ * @param platform Platform string name, e.g., 'adg_os_windows'.
4078
+ *
4079
+ * @returns Specific or generic platform enum value.
4080
+ * @throws Error if the platform is unknown.
4081
+ */
4082
+ declare const getPlatformId: (platform: string) => SpecificPlatform | GenericPlatform;
4083
+ /**
4084
+ * Returns the specific platform string name for the given platform enum value.
4085
+ *
4086
+ * @param platform Specific platform enum value.
4087
+ *
4088
+ * @returns Specific platform string name, e.g., 'adg_os_windows'.
4089
+ * @throws Error if the platform is unknown.
4090
+ */
4091
+ declare const getSpecificPlatformName: (platform: SpecificPlatform) => string;
4092
+
2908
4093
  /**
2909
4094
  * @file AGTree version
2910
4095
  */
2911
- declare const version: string;
4096
+ declare const AGTREE_VERSION: string;
2912
4097
 
2913
- export { ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyOperator, AnyRule, AppListParser, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, CssTree, CssTreeNodeType, CssTreeParserContext, Domain, DomainList, DomainListParser, DomainListSeparator, DomainUtils, EXT_CSS_LEGACY_ATTRIBUTES, EXT_CSS_PSEUDO_CLASSES, ElementHidingRule, ElementHidingRuleBody, EmptyRule, ExpressionOperatorNode, ExpressionParenthesisNode, ExpressionVariableNode, FORBIDDEN_CSS_FUNCTIONS, FilterList, FilterListConverter, FilterListParser, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, JsInjectionRule, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, METADATA_HEADERS, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, Node, NotImplementedError, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, Parameter, ParameterList, ParameterListParser, PreProcessorCommentRule, PreProcessorCommentRuleParser, QuoteType, QuoteUtils, RawFilterListConverter, RawRuleConverter, RegExpUtils, RuleBase, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, StealthOptionListParser, UBO_SCRIPTLET_MASK, Value, VariableTable, locRange, modifierValidator, shiftLoc, version };
4098
+ export { ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AGTREE_VERSION, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyNetworkRule, AnyRule, AppListParser, BINARY_SCHEMA_VERSION, BinarySchemaMismatchError, ByteBuffer, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, CompatibilityTable, CompatibilityTableRow, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, Domain, DomainList, DomainListParser, DomainListSeparator, DomainUtils, EXT_CSS_LEGACY_ATTRIBUTES, EXT_CSS_PSEUDO_CLASSES, ElementHidingRule, ElementHidingRuleBody, EmptyRule, ExpressionOperatorNode, ExpressionParenthesisNode, ExpressionVariableNode, FORBIDDEN_CSS_FUNCTIONS, FilterList, FilterListConverter, FilterListParser, GenericPlatform, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HostRule, HostRuleParser, HostnameList, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, InputByteBuffer, JsInjectionRule, KNOWN_METADATA_HEADERS, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, NetworkRuleType, Node, NotImplementedError, OutputByteBuffer, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, ParameterList, ParameterListParser, ParserOptions, Position, PositionProvider, PreProcessorCommentRule, PreProcessorCommentRuleParser, ProductRecords, QuoteType, QuoteUtils, RawFilterListConverter, RawRuleConverter, RegExpUtils, RowByProduct, RowsByProduct, RuleBase, RuleCategorizer, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, SpecificPlatform, StealthOptionListParser, TextEncoderPolyfillResult, UBO_SCRIPTLET_MASK, Value, VariableTable, decodeTextPolyfill, defaultParserOptions, encodeIntoPolyfill, getPlatformId, getSpecificPlatformName, isGenericPlatform, modifierValidator, modifiersCompatibilityTable, parseRawPlatforms, redirectsCompatibilityTable, scriptletsCompatibilityTable };