/** * @file Scriptlet injection rule converter. */ import { type ScriptletInjectionRule } from '../../nodes/index.js'; import { type NodeConversionResult } from '../base-interfaces/conversion-result.js'; import { RuleConverterBase } from '../base-interfaces/rule-converter-base.js'; /** * Scriptlet injection rule converter class. * * @todo Implement `convertToUbo` and `convertToAbp`. */ export declare class ScriptletRuleConverter extends RuleConverterBase { /** * Converts a scriptlet injection rule to AdGuard format, if possible. * * @param rule Rule node to convert. * * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted. * If the rule was not converted, the result array will contain the original node with the same object reference. * * @throws If the rule is invalid or cannot be converted. */ static convertToAdg(rule: ScriptletInjectionRule): NodeConversionResult; /** * Converts a scriptlet injection rule to uBlock format, if possible. * * @param rule Rule node to convert. * * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted. * If the rule was not converted, the result array will contain the original node with the same object reference. * * @throws If the rule is invalid or cannot be converted. */ static convertToUbo(rule: ScriptletInjectionRule): NodeConversionResult; /** * Remaps uBO key/value args of `json-prune-fetch-response` and * `json-prune-xhr-response` into AdGuard positional argument slots. * * These uBO variants accept only two positional args (`propsToRemove`, * `obligatoryProps`); args 3+ are key/value pairs parsed by uBO's * `getExtraArgs` (even index = key, odd index = value). Recognized keys: * `propsToMatch`, `stackToMatch`. ADG's equivalents use positional * `propsToMatch` (arg 3) and `stack` (arg 4), so the pairs are remapped into * positional slots. Unknown keys are dropped, because uBO ignores keys it * does not read and they cannot be mapped to an ADG positional slot. When a * recognized key repeats, the last value wins. * * Besides remapping arguments, this method also sets the scriptlet node's * name to the AdGuard native name (the uBO canonical name without the * `.js` suffix). This overrides the `ubo-` prefix that `convertToAdg` * adds earlier in its main flow for these two scriptlets, so the final * output uses the native AdGuard name with positional argument semantics. * * @see https://github.com/AdguardTeam/FiltersCompiler/issues/250 * * @param scriptletClone Cloned scriptlet node to remap in place. * @param scriptletData Compatibility data for the matched uBO scriptlet. */ private static remapUboPruneResponseArgs; /** * Inverse of {@link ScriptletRuleConverter.remapUboPruneResponseArgs}: * remaps AdGuard positional `propsToMatch`/`stack` args of * `json-prune-fetch-response` / `json-prune-xhr-response` back into uBO * key/value pairs (`propsToMatch`, `stackToMatch`). * * `children` layout (AdGuard, before this method): `[name, propsToRemove, * obligatoryProps, propsToMatch, stack]`. `propsToMatch` and `stack` are * optional; empty values are not re-emitted, so the output never has * trailing empty key/value pairs. ADG rules that already use the * `ubo-`-prefixed name keep key/value args and are not handled here (they * take the `ubo-` prefix branch in `convertToUbo`, not this `switch`). * * @param scriptletClone Cloned scriptlet node to remap in place. */ private static remapAdgToUboPruneResponseArgs; }