UNPKG

@adguard/aglint

Version:

Universal adblock filter list linter.

44 lines (43 loc) 1.51 kB
import { CssTreeParsingContext, type CssTreeParsingContextToNode } from './css-tree-types'; /** * Possible values for the cache map. */ export type CssCacheValue<K extends CssTreeParsingContext> = CssTreeParsingContextToNode[K] | Error; /** * Cache maps for CSS tree nodes. Key is the CSS tree parsing context and value is a map of CSS to node or error * (if parsing failed before). */ export type CssCacheMaps = { [K in CssTreeParsingContext]: Map<string, CssCacheValue<K>>; }; /** * Cache for CSS tree nodes. We share the cache between all rules to avoid parsing the same CSS multiple times. * For errors, we cache the relative error position, so the error position can be calculated for any AGTree node. */ export declare class CssCache { /** * Internal cache maps. */ private maps; /** * Creates a new cache instance for CSS tree nodes. */ constructor(); /** * Gets entry from the cache. * * @param context The parsing context. * @param css The CSS string. * * @returns The CSS tree node / error or undefined if CSS string is not cached. */ get<K extends CssTreeParsingContext>(context: K, css: string): CssCacheValue<K> | undefined; /** * Adds entry to the cache. * * @param context The parsing context. * @param css The CSS string. * @param node The CSS tree node / error. */ set<K extends CssTreeParsingContext>(context: K, css: string, node: CssCacheValue<K>): void; }