@jesscss/css-parser 1.0.6-alpha.0 → 2.0.0-alpha.1
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/lib/advancedActionsParser.d.ts +60 -0
- package/lib/advancedActionsParser.js +203 -0
- package/lib/advancedActionsParser.js.map +1 -0
- package/lib/cssActionsParser.d.ts +155 -0
- package/lib/cssActionsParser.js +376 -0
- package/lib/cssActionsParser.js.map +1 -0
- package/lib/cssErrorMessageProvider.d.ts +14 -0
- package/lib/cssErrorMessageProvider.js +40 -0
- package/lib/cssErrorMessageProvider.js.map +1 -0
- package/lib/cssParser.d.ts +36 -103
- package/lib/cssParser.js +75 -58
- package/lib/cssParser.js.map +1 -0
- package/lib/cssTokens.d.ts +539 -5
- package/lib/cssTokens.js +488 -232
- package/lib/cssTokens.js.map +1 -0
- package/lib/index.d.ts +8 -16
- package/lib/index.js +9 -41
- package/lib/index.js.map +1 -0
- package/lib/productions.d.ts +273 -0
- package/lib/productions.js +3499 -0
- package/lib/productions.js.map +1 -0
- package/lib/test/ast-serialize.test.d.ts +1 -0
- package/lib/test/ast-serialize.test.js +157 -0
- package/lib/test/ast-serialize.test.js.map +1 -0
- package/lib/test/container.test.d.ts +1 -0
- package/lib/test/container.test.js +369 -0
- package/lib/test/container.test.js.map +1 -0
- package/lib/test/css-files.test.d.ts +1 -0
- package/lib/test/css-files.test.js +21 -0
- package/lib/test/css-files.test.js.map +1 -0
- package/lib/test/less-output.test.d.ts +1 -0
- package/lib/test/less-output.test.js +52 -0
- package/lib/test/less-output.test.js.map +1 -0
- package/lib/util/cst.d.ts +7 -2
- package/lib/util/cst.js +5 -9
- package/lib/util/cst.js.map +1 -0
- package/lib/util/index.d.ts +19 -13
- package/lib/util/index.js +98 -87
- package/lib/util/index.js.map +1 -0
- package/package.json +43 -20
- package/lib/productions/atRules.d.ts +0 -2
- package/lib/productions/atRules.js +0 -196
- package/lib/productions/blocks.d.ts +0 -2
- package/lib/productions/blocks.js +0 -181
- package/lib/productions/declarations.d.ts +0 -14
- package/lib/productions/declarations.js +0 -59
- package/lib/productions/root.d.ts +0 -2
- package/lib/productions/root.js +0 -49
- package/lib/productions/selectors.d.ts +0 -2
- package/lib/productions/selectors.js +0 -223
- package/lib/productions/values.d.ts +0 -2
- package/lib/productions/values.js +0 -114
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { EmbeddedActionsParser, type IParserConfig, type TokenVocabulary, type IToken, type SubruleMethodOpts } from 'chevrotain';
|
|
2
|
+
type ParserMethodInternal<ARGS extends any[] = any[], R = any> = ((...args: ARGS) => R) & {
|
|
3
|
+
ruleName: string;
|
|
4
|
+
};
|
|
5
|
+
import { TreeContext, type LocationInfo } from '@jesscss/core';
|
|
6
|
+
/** Apply this label to tokens you wish to skip during parsing consideration */
|
|
7
|
+
export declare const SKIPPED_LABEL = "Skipped";
|
|
8
|
+
/** The name of the whitespace token */
|
|
9
|
+
export declare const WS_NAME = "WS";
|
|
10
|
+
/**
|
|
11
|
+
* @note copied from 'chevrotain/src/parse/grammar/keys'
|
|
12
|
+
* We have to copy these because they aren't exported
|
|
13
|
+
*/
|
|
14
|
+
export declare const BITS_FOR_OCCURRENCE_IDX = 8;
|
|
15
|
+
export declare const OR_IDX: number;
|
|
16
|
+
export declare const OPTION_IDX: number;
|
|
17
|
+
/**
|
|
18
|
+
* A parser that can make decisions based on whitespace,
|
|
19
|
+
* yet doesn't _require_ parsing whitespace in the main
|
|
20
|
+
* token stream.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AdvancedActionsParser extends EmbeddedActionsParser {
|
|
23
|
+
/** Indexed by the startOffset of the next token it precedes */
|
|
24
|
+
preSkippedTokenMap: Map<number, IToken[]>;
|
|
25
|
+
postSkippedTokenMap: Map<number, IToken[]>;
|
|
26
|
+
/** Boolean flag for used in post node */
|
|
27
|
+
usedSkippedTokens: Set<IToken[]>;
|
|
28
|
+
_context: TreeContext | undefined;
|
|
29
|
+
locationStack: LocationInfo[];
|
|
30
|
+
originalInput: IToken[];
|
|
31
|
+
/** Exposed from Chevrotain */
|
|
32
|
+
currIdx: number;
|
|
33
|
+
get context(): TreeContext;
|
|
34
|
+
set context(c: TreeContext);
|
|
35
|
+
subruleInternal: <ARGS extends unknown[], R>(ruleToCall: ParserMethodInternal<ARGS, R>, idx: number, options?: SubruleMethodOpts<ARGS>) => R;
|
|
36
|
+
getKeyForAutomaticLookahead: (dslMethodIdx: number, occurrence: number) => number;
|
|
37
|
+
raiseNoAltException: (occurrence: number, errMsgTypes: string | undefined) => never;
|
|
38
|
+
getLaFuncFromCache: (key: number) => (...args: any[]) => any;
|
|
39
|
+
constructor(tokenVocabulary: TokenVocabulary, config: IParserConfig);
|
|
40
|
+
/** Separate skipped tokens into a new map */
|
|
41
|
+
set input(value: IToken[]);
|
|
42
|
+
_subruleInternal<ARGS extends unknown[], R>(ruleToCall: ParserMethodInternal<ARGS, R>, idx: number, options?: SubruleMethodOpts<ARGS>): R;
|
|
43
|
+
/**
|
|
44
|
+
* Used in a GATE.
|
|
45
|
+
* Determine if there is white-space before the next token
|
|
46
|
+
*/
|
|
47
|
+
hasWS(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Used in a GATE.
|
|
50
|
+
* Affirms that there is NOT white space or comment before next token
|
|
51
|
+
*/
|
|
52
|
+
noSep(offset?: number): boolean;
|
|
53
|
+
protected startRule(): LocationInfo | undefined;
|
|
54
|
+
/** Should only be called when not in recording phase */
|
|
55
|
+
protected endRule(): LocationInfo;
|
|
56
|
+
/** @note might not need these */
|
|
57
|
+
protected getLocationInfo(loc: IToken): LocationInfo;
|
|
58
|
+
protected isToken(node: any): node is IToken;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { EmbeddedActionsParser, EOF
|
|
2
|
+
// type IOrAlt,
|
|
3
|
+
// type OrMethodOpts
|
|
4
|
+
} from 'chevrotain';
|
|
5
|
+
import { TreeContext } from '@jesscss/core';
|
|
6
|
+
/** Apply this label to tokens you wish to skip during parsing consideration */
|
|
7
|
+
export const SKIPPED_LABEL = 'Skipped';
|
|
8
|
+
/** The name of the whitespace token */
|
|
9
|
+
export const WS_NAME = 'WS';
|
|
10
|
+
// const { isArray } = Array
|
|
11
|
+
/**
|
|
12
|
+
* @note copied from 'chevrotain/src/parse/grammar/keys'
|
|
13
|
+
* We have to copy these because they aren't exported
|
|
14
|
+
*/
|
|
15
|
+
export const BITS_FOR_OCCURRENCE_IDX = 8;
|
|
16
|
+
export const OR_IDX = 1 << BITS_FOR_OCCURRENCE_IDX;
|
|
17
|
+
export const OPTION_IDX = 2 << BITS_FOR_OCCURRENCE_IDX;
|
|
18
|
+
/**
|
|
19
|
+
* A parser that can make decisions based on whitespace,
|
|
20
|
+
* yet doesn't _require_ parsing whitespace in the main
|
|
21
|
+
* token stream.
|
|
22
|
+
*/
|
|
23
|
+
export class AdvancedActionsParser extends EmbeddedActionsParser {
|
|
24
|
+
/** Indexed by the startOffset of the next token it precedes */
|
|
25
|
+
preSkippedTokenMap;
|
|
26
|
+
postSkippedTokenMap;
|
|
27
|
+
/** Boolean flag for used in post node */
|
|
28
|
+
usedSkippedTokens;
|
|
29
|
+
_context;
|
|
30
|
+
locationStack = [];
|
|
31
|
+
// captureStack: number[]
|
|
32
|
+
originalInput;
|
|
33
|
+
get context() {
|
|
34
|
+
return (this._context ??= new TreeContext());
|
|
35
|
+
}
|
|
36
|
+
set context(c) {
|
|
37
|
+
this._context = c;
|
|
38
|
+
}
|
|
39
|
+
constructor(tokenVocabulary, config) {
|
|
40
|
+
super(tokenVocabulary, config);
|
|
41
|
+
if (!config.skipValidations) {
|
|
42
|
+
this.subruleInternal = this._subruleInternal.bind(this);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Separate skipped tokens into a new map */
|
|
46
|
+
set input(value) {
|
|
47
|
+
const preSkippedTokenMap = this.preSkippedTokenMap = new Map();
|
|
48
|
+
const postSkippedTokenMap = this.postSkippedTokenMap = new Map();
|
|
49
|
+
const inputTokens = [];
|
|
50
|
+
let valueLength = value.length;
|
|
51
|
+
let prevToken;
|
|
52
|
+
const isSkippedToken = (t) => {
|
|
53
|
+
if (!t) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const name = t.tokenType.name;
|
|
57
|
+
return t.tokenType.LABEL === SKIPPED_LABEL || name === WS_NAME || /Comment/i.test(name);
|
|
58
|
+
};
|
|
59
|
+
for (let i = 0; i < valueLength; i++) {
|
|
60
|
+
const token = value[i];
|
|
61
|
+
let nextToken = undefined;
|
|
62
|
+
/** Find the next non-skipped token; if none found, leave as undefined */
|
|
63
|
+
for (let j = i + 1; j < valueLength; j++) {
|
|
64
|
+
const candidate = value[j];
|
|
65
|
+
if (!isSkippedToken(candidate)) {
|
|
66
|
+
nextToken = candidate;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const beforeIndex = nextToken?.startOffset ?? Infinity;
|
|
71
|
+
const tokName = token.tokenType.name;
|
|
72
|
+
const currIsSkipped = isSkippedToken(token);
|
|
73
|
+
// removed diagnostics
|
|
74
|
+
if (currIsSkipped) {
|
|
75
|
+
let tokens = preSkippedTokenMap.get(beforeIndex);
|
|
76
|
+
if (tokens) {
|
|
77
|
+
tokens.push(token);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
tokens = [token];
|
|
81
|
+
preSkippedTokenMap.set(beforeIndex, tokens);
|
|
82
|
+
}
|
|
83
|
+
if (prevToken) {
|
|
84
|
+
postSkippedTokenMap.set(prevToken.endOffset, tokens);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
prevToken = token;
|
|
89
|
+
inputTokens.push(token);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.usedSkippedTokens = new Set();
|
|
93
|
+
// removed diagnostics
|
|
94
|
+
this.originalInput = value;
|
|
95
|
+
super.input = inputTokens;
|
|
96
|
+
}
|
|
97
|
+
_subruleInternal(ruleToCall, idx, options) {
|
|
98
|
+
let name = ruleToCall.ruleName;
|
|
99
|
+
let preLength = this.locationStack.length;
|
|
100
|
+
// @ts-expect-error - This exists
|
|
101
|
+
let result = super.subruleInternal(ruleToCall, idx, options);
|
|
102
|
+
let postLength = this.locationStack.length;
|
|
103
|
+
if (postLength !== preLength) {
|
|
104
|
+
/**
|
|
105
|
+
* In recovery-enabled parses (linting / language services), a rule may
|
|
106
|
+
* throw before reaching its explicit `endRule()` call. That should be a
|
|
107
|
+
* parse error, not a fatal runtime error.
|
|
108
|
+
*
|
|
109
|
+
* Keep the invariant check in non-recovery mode (to catch authoring bugs),
|
|
110
|
+
* but unwind the stack in recovery mode so parsing can continue.
|
|
111
|
+
*/
|
|
112
|
+
if (this.recoveryEnabled) {
|
|
113
|
+
while (this.locationStack.length > preLength) {
|
|
114
|
+
this.locationStack.pop();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
throw new Error(`Rule ${name} did not call endRule()`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Used in a GATE.
|
|
125
|
+
* Determine if there is white-space before the next token
|
|
126
|
+
*/
|
|
127
|
+
hasWS() {
|
|
128
|
+
let startOffset = this.LA(1).startOffset;
|
|
129
|
+
const skipped = this.preSkippedTokenMap.get(startOffset);
|
|
130
|
+
if (!skipped) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return !!skipped.find(token => token.tokenType.name === WS_NAME);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Used in a GATE.
|
|
137
|
+
* Affirms that there is NOT white space or comment before next token
|
|
138
|
+
*/
|
|
139
|
+
noSep(offset = 0) {
|
|
140
|
+
let startOffset = this.LA(1 + offset).startOffset;
|
|
141
|
+
return !this.preSkippedTokenMap.get(startOffset);
|
|
142
|
+
}
|
|
143
|
+
startRule() {
|
|
144
|
+
if (!this.RECORDING_PHASE) {
|
|
145
|
+
let { startOffset, startLine, startColumn } = this.LA(1);
|
|
146
|
+
let location = [startOffset, startLine, startColumn, NaN, NaN, NaN];
|
|
147
|
+
this.locationStack.push(location);
|
|
148
|
+
return location;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Should only be called when not in recording phase */
|
|
152
|
+
endRule() {
|
|
153
|
+
let { endOffset, endLine, endColumn } = this.LA(0);
|
|
154
|
+
let location = this.locationStack.pop();
|
|
155
|
+
location[3] = endOffset;
|
|
156
|
+
location[4] = endLine;
|
|
157
|
+
location[5] = endColumn;
|
|
158
|
+
return location;
|
|
159
|
+
}
|
|
160
|
+
/** @note might not need these */
|
|
161
|
+
// protected startCapture() {
|
|
162
|
+
// if (!this.RECORDING_PHASE) {
|
|
163
|
+
// let idx = this.currIdx
|
|
164
|
+
// this.startRule()
|
|
165
|
+
// this.captureStack.push(idx)
|
|
166
|
+
// }
|
|
167
|
+
// }
|
|
168
|
+
// protected endCapture(): [string, LocationInfo] {
|
|
169
|
+
// let location = this.endRule()
|
|
170
|
+
// let prevIdx = this.captureStack.pop()!
|
|
171
|
+
// let currIdx = this.currIdx
|
|
172
|
+
// let input = this.originalInput
|
|
173
|
+
// let tokenStr = ''
|
|
174
|
+
// let token: IToken | undefined
|
|
175
|
+
// for (let i = prevIdx; i <= currIdx; i++) {
|
|
176
|
+
// token = input[i]!
|
|
177
|
+
// if (this.preSkippedTokenMap.has(token.startOffset)) {
|
|
178
|
+
// for (let skipped of this.preSkippedTokenMap.get(token.startOffset)!) {
|
|
179
|
+
// tokenStr += skipped.image
|
|
180
|
+
// }
|
|
181
|
+
// }
|
|
182
|
+
// tokenStr += token.image
|
|
183
|
+
// }
|
|
184
|
+
// if (token && this.postSkippedTokenMap.has(token.endOffset!)) {
|
|
185
|
+
// for (let skipped of this.postSkippedTokenMap.get(token.endOffset!)!) {
|
|
186
|
+
// tokenStr += skipped.image
|
|
187
|
+
// }
|
|
188
|
+
// }
|
|
189
|
+
// return [tokenStr, location]
|
|
190
|
+
// }
|
|
191
|
+
getLocationInfo(loc) {
|
|
192
|
+
if (loc.tokenType === EOF) {
|
|
193
|
+
return new Array(6).fill(Infinity);
|
|
194
|
+
}
|
|
195
|
+
const { startOffset, startLine, startColumn, endOffset, endLine, endColumn } = loc;
|
|
196
|
+
/** Assert that, in our case, tokens will have these properties */
|
|
197
|
+
return [startOffset, startLine, startColumn, endOffset, endLine, endColumn];
|
|
198
|
+
}
|
|
199
|
+
isToken(node) {
|
|
200
|
+
return Boolean(node && 'tokenType' in node);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=advancedActionsParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedActionsParser.js","sourceRoot":"","sources":["../src/advancedActionsParser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAKrB,GAAG;AACH,eAAe;AACf,oBAAoB;EACrB,MAAM,YAAY,CAAC;AAOpB,OAAO,EACL,WAAW,EAEZ,MAAM,eAAe,CAAC;AAEvB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,uCAAuC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAE5B,4BAA4B;AAE5B;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAI,uBAAuB,CAAC;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,uBAAuB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,qBAAqB;IAC9D,+DAA+D;IAC/D,kBAAkB,CAAyB;IAC3C,mBAAmB,CAAyB;IAC5C,yCAAyC;IACzC,iBAAiB,CAAiB;IAElC,QAAQ,CAA0B;IAClC,aAAa,GAAmB,EAAE,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IAC9B,MAAM;IACN,mEAAmE;IACnE,6EAA6E;IAC7E,kCAAkC;IAClC,QAAQ;IACR,MAAM;IACN,gCAAgC;IAChC,IAAI;IAEM,eAAe,CAAC,GAAW;QACnC,IAAI,GAAG,CAAC,SAAS,KAAK,GAAG,EAAE,CAAC;YAC1B,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAiB,CAAC;QACrD,CAAC;QACD,MAAM,EACJ,WAAW,EACX,SAAS,EACT,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACV,GAAG,GAAG,CAAC;QACR,kEAAkE;QAClE,OAAO,CAAC,WAAW,EAAE,SAAU,EAAE,WAAY,EAAE,SAAU,EAAE,OAAQ,EAAE,SAAU,CAAC,CAAC;IACnF,CAAC;IAES,OAAO,CAAC,IAAS;QACzB,OAAO,OAAO,CAAC,IAAI,IAAI,WAAW,IAAI,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type TokenVocabulary, type TokenType, type IParserConfig, type ParserMethod, type IToken, type IRecognitionException } from 'chevrotain';
|
|
2
|
+
import { AdvancedActionsParser } from './advancedActionsParser.js';
|
|
3
|
+
import { type CssTokenType } from './cssTokens.js';
|
|
4
|
+
import { type LocationInfo, Node, Rules } from '@jesscss/core';
|
|
5
|
+
export type TokenMap = Record<CssTokenType, TokenType>;
|
|
6
|
+
export type Rule<F extends (...args: any[]) => void = (ctx?: RuleContext) => void> = ParserMethod<Parameters<F>, any>;
|
|
7
|
+
export interface CssParserConfig extends IParserConfig {
|
|
8
|
+
/** Things like star property hacks and IE filters */
|
|
9
|
+
legacyMode?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export type RuleContext = {
|
|
12
|
+
/** Inside a declaration list */
|
|
13
|
+
inner?: boolean;
|
|
14
|
+
/** Determine if this is the first selector in the list */
|
|
15
|
+
firstSelector?: boolean;
|
|
16
|
+
/** If downstream selector rules are part of a qualified rule */
|
|
17
|
+
qualifiedRule?: boolean;
|
|
18
|
+
/** Inside a custom property value */
|
|
19
|
+
inCustomPropertyValue?: boolean;
|
|
20
|
+
[k: string]: object | boolean | string | object[] | number | undefined;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @note - we use an EmbeddedActionsParser for a few reasons:
|
|
24
|
+
* 1. Jess's AST is essentially a CST; that is, it records
|
|
25
|
+
* all whitespace and comments. (The one difference may
|
|
26
|
+
* be that some nodes are "simplified" in the Jess AST.)
|
|
27
|
+
* 2. Chevrotain's CST is not the most efficient structure
|
|
28
|
+
* for a CST.
|
|
29
|
+
* 3. We can avoid the overhead of a CST visitor by creating
|
|
30
|
+
* the Jess nodes directly.
|
|
31
|
+
* 4. In some cases, we need some additional business logic
|
|
32
|
+
* about what the intended structure of the AST is, based
|
|
33
|
+
* on the presence of certain tokens.
|
|
34
|
+
*/
|
|
35
|
+
export declare class CssActionsParser extends AdvancedActionsParser {
|
|
36
|
+
T: TokenMap;
|
|
37
|
+
legacyMode: boolean;
|
|
38
|
+
ruleIndex: number;
|
|
39
|
+
_errors: Array<IRecognitionException>;
|
|
40
|
+
/** Expose Chevrotain's flag */
|
|
41
|
+
skipValidations: boolean;
|
|
42
|
+
/** Rewire, declaring class fields in constructor with `public` */
|
|
43
|
+
stylesheet: Rule<(options?: Record<string, any>) => void>;
|
|
44
|
+
main: Rule;
|
|
45
|
+
qualifiedRule: Rule;
|
|
46
|
+
atRule: Rule;
|
|
47
|
+
selectorList: Rule;
|
|
48
|
+
declarationList: Rule;
|
|
49
|
+
forgivingSelectorList: Rule;
|
|
50
|
+
classSelector: Rule;
|
|
51
|
+
idSelector: Rule;
|
|
52
|
+
pseudoSelector: Rule;
|
|
53
|
+
attributeSelector: Rule;
|
|
54
|
+
nthValue: Rule;
|
|
55
|
+
complexSelector: Rule;
|
|
56
|
+
simpleSelector: Rule;
|
|
57
|
+
compoundSelector: Rule;
|
|
58
|
+
relativeSelector: Rule;
|
|
59
|
+
declaration: Rule;
|
|
60
|
+
valueList: Rule;
|
|
61
|
+
/** Often a space-separated sequence */
|
|
62
|
+
valueSequence: Rule;
|
|
63
|
+
value: Rule;
|
|
64
|
+
squareValue: Rule;
|
|
65
|
+
customValue: Rule;
|
|
66
|
+
innerCustomValue: Rule;
|
|
67
|
+
functionCall: Rule;
|
|
68
|
+
functionCallLike: Rule;
|
|
69
|
+
functionCallArgs: Rule;
|
|
70
|
+
ifFunction: Rule;
|
|
71
|
+
ifFunctionArgs: Rule;
|
|
72
|
+
knownFunctions: Rule;
|
|
73
|
+
varFunction: Rule;
|
|
74
|
+
calcFunction: Rule;
|
|
75
|
+
urlFunction: Rule;
|
|
76
|
+
unknownValue: Rule;
|
|
77
|
+
string: Rule;
|
|
78
|
+
mathSum: Rule;
|
|
79
|
+
mathProduct: Rule;
|
|
80
|
+
mathValue: Rule;
|
|
81
|
+
mathParen: Rule;
|
|
82
|
+
/** At Rules */
|
|
83
|
+
innerAtRule: Rule;
|
|
84
|
+
importAtRule: Rule;
|
|
85
|
+
importPrelude: Rule;
|
|
86
|
+
importPostlude: Rule;
|
|
87
|
+
mediaAtRule: Rule;
|
|
88
|
+
supportsAtRule: Rule;
|
|
89
|
+
containerAtRule: Rule;
|
|
90
|
+
containerName: Rule;
|
|
91
|
+
containerQueryList: Rule;
|
|
92
|
+
containerQuery: Rule;
|
|
93
|
+
containerCondition: Rule;
|
|
94
|
+
containerInParens: Rule;
|
|
95
|
+
containerFeature: Rule;
|
|
96
|
+
containerAnd: Rule;
|
|
97
|
+
containerOr: Rule;
|
|
98
|
+
atRuleBody: Rule;
|
|
99
|
+
pageAtRule: Rule;
|
|
100
|
+
keyframesAtRule: Rule;
|
|
101
|
+
keyframesName: Rule;
|
|
102
|
+
layerAtRule: Rule;
|
|
103
|
+
layerName: Rule;
|
|
104
|
+
scopeAtRule: Rule;
|
|
105
|
+
documentAtRule: Rule;
|
|
106
|
+
pageSelector: Rule;
|
|
107
|
+
fontFaceAtRule: Rule;
|
|
108
|
+
nestedAtRule: Rule;
|
|
109
|
+
nonNestedAtRule: Rule;
|
|
110
|
+
unknownAtRule: Rule;
|
|
111
|
+
/** `@media` syntax */
|
|
112
|
+
mediaQueryList: Rule;
|
|
113
|
+
mediaQuery: Rule;
|
|
114
|
+
mediaCondition: Rule;
|
|
115
|
+
mediaType: Rule;
|
|
116
|
+
mediaConditionWithoutOr: Rule;
|
|
117
|
+
mediaNot: Rule;
|
|
118
|
+
mediaInParens: Rule;
|
|
119
|
+
mediaAnd: Rule;
|
|
120
|
+
mediaOr: Rule;
|
|
121
|
+
mediaFeature: Rule;
|
|
122
|
+
mfValue: Rule;
|
|
123
|
+
mediaRange: Rule;
|
|
124
|
+
mfComparison: Rule;
|
|
125
|
+
mfNonIdentifierValue: Rule;
|
|
126
|
+
/** `@container` syntax - declarations are above */
|
|
127
|
+
/**
|
|
128
|
+
* `@supports` syntax - the parsing is defined differently
|
|
129
|
+
* from `@media`, which is fortunate, because it's much
|
|
130
|
+
* simpler.
|
|
131
|
+
*/
|
|
132
|
+
supportsCondition: Rule;
|
|
133
|
+
supportsInParens: Rule;
|
|
134
|
+
/** General purpose subrules */
|
|
135
|
+
anyOuterValue: Rule;
|
|
136
|
+
anyInnerValue: Rule;
|
|
137
|
+
extraTokens: Rule;
|
|
138
|
+
customBlock: Rule;
|
|
139
|
+
constructor(tokenVocabulary: TokenVocabulary, T: TokenMap, config?: CssParserConfig);
|
|
140
|
+
set input(value: IToken[]);
|
|
141
|
+
protected getLocationFromNodes(nodes: Array<IToken | Node>): LocationInfo | undefined;
|
|
142
|
+
protected getRulesWithComments(existingRules?: Node[], nextTokenLocation?: LocationInfo): Rules;
|
|
143
|
+
protected getPrePost(offset: number, post?: boolean, ctx?: RuleContext): Node['pre'];
|
|
144
|
+
/**
|
|
145
|
+
* Attaches pre / post whitespace and comments.
|
|
146
|
+
* Note that nodes can be wrapped more than once.
|
|
147
|
+
*
|
|
148
|
+
* @note Some nodes can't be wrapped because they
|
|
149
|
+
* don't represent a location. For instance, a
|
|
150
|
+
* Rules node may be empty, and hence doesn't
|
|
151
|
+
* have a location.
|
|
152
|
+
*/
|
|
153
|
+
protected wrap<T extends Node = Node>(node: T, post?: boolean | 'both', ctx?: RuleContext): T;
|
|
154
|
+
protected processValueToken(token: IToken, _ctx?: RuleContext): Node;
|
|
155
|
+
}
|