1 | import { AstSelector } from './ast.js';
|
2 | import { CssLevel, SyntaxDefinition } from './syntax-definitions.js';
|
3 | /**
|
4 | * This error is thrown when parser encounters problems in CSS string.
|
5 | * On top of the usual error, it has `position` property to indicate where in the input string the error happened.
|
6 | */
|
7 | export interface ParserError extends Error {
|
8 | message: string;
|
9 | name: 'ParserError';
|
10 | position: number;
|
11 | }
|
12 | /**
|
13 | * Parses CSS selector string and returns CSS selector AST.
|
14 | * @throws {ParserError}
|
15 | */
|
16 | export type Parser = (input: string) => AstSelector;
|
17 | /**
|
18 | * Creates a parse function to be used later to parse CSS selectors.
|
19 | */
|
20 | export declare function createParser(options?: {
|
21 | /**
|
22 | * CSS Syntax options to be used for parsing.
|
23 | * Can either be one of the predefined CSS levels ({@link CssLevel}) or a more detailed syntax definition ({@link SyntaxDefinition}).
|
24 | * Default: `"latest"`
|
25 | */
|
26 | syntax?: CssLevel | SyntaxDefinition;
|
27 | /**
|
28 | * Flag to enable substitutes.
|
29 | * This is not part of CSS syntax, but rather a useful feature to pass variables into CSS selectors.
|
30 | * Default: `false`
|
31 | * @example "[attr=$variable]"
|
32 | */
|
33 | substitutes?: boolean;
|
34 | /**
|
35 | * CSS selector parser in modern browsers is very forgiving. For instance, it works fine with unclosed attribute
|
36 | * selectors: `"[attr=value"`.
|
37 | * Set to `false` in order to mimic browser behaviour.
|
38 | * Default: `true`
|
39 | */
|
40 | strict?: boolean;
|
41 | }): Parser;
|