@tbela99/css-parser 1.4.6 → 1.4.8
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/CHANGELOG.md +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +284 -283
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -298
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { EnumToken
|
|
2
|
-
import {
|
|
3
|
-
import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
|
|
1
|
+
import { EnumToken } from '../../ast/types.js';
|
|
2
|
+
import { pseudoElements, LOC, tokensfuncDefMap } from '../../syntax/constants.js';
|
|
4
3
|
import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
|
|
5
|
-
import { matchAllSyntaxes, createValidationContext
|
|
4
|
+
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
6
5
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
7
6
|
import { parseDeclaration } from './declaration.js';
|
|
8
|
-
import { equalsIgnoreCase } from './text.js';
|
|
9
|
-
import { pseudoElements } from '../../syntax/syntax.js';
|
|
10
7
|
|
|
11
8
|
function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
12
9
|
const tokens = [];
|
|
@@ -26,34 +23,41 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
26
23
|
EnumToken.ColumnCombinatorTokenType,
|
|
27
24
|
EnumToken.UniversalSelectorTokenType,
|
|
28
25
|
]);
|
|
29
|
-
while (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
26
|
+
// while (
|
|
27
|
+
// i < stream.length &&
|
|
28
|
+
// (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)
|
|
29
|
+
// ) {
|
|
30
|
+
// tokens.push(stream[i]);
|
|
31
|
+
// i++;
|
|
32
|
+
// }
|
|
33
|
+
// if (
|
|
34
|
+
// !tokensfuncDefMap.has(stream[i]?.typ) &&
|
|
35
|
+
// stream[i]?.typ !== EnumToken.StartParensTokenType &&
|
|
36
|
+
// !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === (stream[i] as IdentToken)?.val.toLowerCase())
|
|
37
|
+
// ) {
|
|
38
|
+
// return {
|
|
39
|
+
// success: false,
|
|
40
|
+
// errors: [
|
|
41
|
+
// {
|
|
42
|
+
// action: "drop",
|
|
43
|
+
// node: stream[i],
|
|
44
|
+
// message: `expecting '<supports-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
45
|
+
// },
|
|
46
|
+
// ],
|
|
47
|
+
// };
|
|
48
|
+
// }
|
|
48
49
|
for (; i < stream.length; i++) {
|
|
49
50
|
tokens.push(stream[i]);
|
|
50
51
|
if (stream[i].typ == EnumToken.ColonTokenType) {
|
|
51
52
|
if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
|
|
53
|
+
const val = stream[i + 1].val;
|
|
52
54
|
Object.assign(stream[i], {
|
|
53
|
-
typ:
|
|
54
|
-
|
|
55
|
+
typ: pseudoElements.includes(val)
|
|
56
|
+
? EnumToken.PseudoElementTokenType
|
|
57
|
+
: EnumToken.PseudoClassTokenType,
|
|
58
|
+
val: ":" + val,
|
|
55
59
|
});
|
|
56
|
-
stream[i].
|
|
60
|
+
stream[i][LOC].end = stream[i + 1][LOC].end;
|
|
57
61
|
stream.splice(i + 1, 1);
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
@@ -66,36 +70,37 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
66
70
|
val,
|
|
67
71
|
});
|
|
68
72
|
stack.push(stream[i]);
|
|
69
|
-
stream[i].
|
|
70
|
-
stream.splice(i + 1, 1);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (stream[i].typ == EnumToken.DoubleColonTokenType) {
|
|
75
|
-
val = ":" + stream[i + 1].val;
|
|
76
|
-
if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
|
|
77
|
-
Object.assign(stream[i], {
|
|
78
|
-
typ: EnumToken.PseudoClassTokenType,
|
|
79
|
-
val: (pseudoElements.includes(val) ? "" : ":") + val,
|
|
80
|
-
});
|
|
81
|
-
stream[i].loc.end = stream[i + 1].loc.end;
|
|
82
|
-
stream.splice(i + 1, 1);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
|
|
86
|
-
val = "::" + stream[i + 1].val;
|
|
87
|
-
Object.assign(stream[i], {
|
|
88
|
-
typ: val + "()" in getSyntaxConfig().selectors
|
|
89
|
-
? EnumToken.PseudoClassFunctionTokenDefType
|
|
90
|
-
: EnumToken.FunctionTokenDefType,
|
|
91
|
-
val,
|
|
92
|
-
});
|
|
93
|
-
stack.push(stream[i]);
|
|
94
|
-
stream[i].loc.end = stream[i + 1].loc.end;
|
|
73
|
+
stream[i][LOC].end = stream[i + 1][LOC].end;
|
|
95
74
|
stream.splice(i + 1, 1);
|
|
96
75
|
continue;
|
|
97
76
|
}
|
|
98
77
|
}
|
|
78
|
+
// if (stream[i].typ == EnumToken.DoubleColonTokenType) {
|
|
79
|
+
// val = ":" + (stream[i + 1] as IdentToken).val;
|
|
80
|
+
// if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
|
|
81
|
+
// Object.assign(stream[i], {
|
|
82
|
+
// typ: EnumToken.PseudoClassTokenType,
|
|
83
|
+
// val: (pseudoElements.includes(val) ? "" : ":") + val,
|
|
84
|
+
// });
|
|
85
|
+
// stream[i][LOC]!.end = stream[i + 1]![LOC]!.end;
|
|
86
|
+
// stream.splice(i + 1, 1);
|
|
87
|
+
// continue;
|
|
88
|
+
// }
|
|
89
|
+
// if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
|
|
90
|
+
// val = "::" + (stream[i + 1] as IdentToken).val;
|
|
91
|
+
// Object.assign(stream[i], {
|
|
92
|
+
// typ:
|
|
93
|
+
// val + "()" in getSyntaxConfig().selectors
|
|
94
|
+
// ? EnumToken.PseudoClassFunctionTokenDefType
|
|
95
|
+
// : EnumToken.FunctionTokenDefType,
|
|
96
|
+
// val,
|
|
97
|
+
// });
|
|
98
|
+
// stack.push(stream[i]);
|
|
99
|
+
// stream[i][LOC]!.end = stream[i + 1]![LOC]!.end;
|
|
100
|
+
// stream.splice(i + 1, 1);
|
|
101
|
+
// continue;
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
99
104
|
if (trimWhiteSpace.has(stream[i].typ)) {
|
|
100
105
|
if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
|
|
101
106
|
tokens.splice(tokens.length - 2, 1);
|
|
@@ -112,23 +117,27 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
112
117
|
tokens.push(stream[k]);
|
|
113
118
|
k++;
|
|
114
119
|
}
|
|
115
|
-
if (k < stream.length) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
120
|
+
// if (k < stream.length) {
|
|
121
|
+
// if (
|
|
122
|
+
// stream[k].typ !== EnumToken.EndParensTokenType &&
|
|
123
|
+
// !(
|
|
124
|
+
// stream[k].typ === EnumToken.IdenTokenType &&
|
|
125
|
+
// ("and" === (stream[k] as IdentToken)?.val.toLowerCase() ||
|
|
126
|
+
// "or" === (stream[k] as IdentToken)?.val.toLowerCase())
|
|
127
|
+
// )
|
|
128
|
+
// ) {
|
|
129
|
+
// return {
|
|
130
|
+
// success: false,
|
|
131
|
+
// errors: [
|
|
132
|
+
// {
|
|
133
|
+
// action: "drop",
|
|
134
|
+
// node: stream[k],
|
|
135
|
+
// message: `expecting 'and' or 'or' at ${stream[k]?.[LOC]?.src}:${stream[k]?.[LOC]?.sta.lin}:${stream[k]?.[LOC]?.sta.col}`,
|
|
136
|
+
// },
|
|
137
|
+
// ],
|
|
138
|
+
// };
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
132
141
|
expectAndOr = false;
|
|
133
142
|
}
|
|
134
143
|
if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
|
|
@@ -139,77 +148,91 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
139
148
|
switch (stream[i].typ) {
|
|
140
149
|
case EnumToken.EndParensTokenType:
|
|
141
150
|
{
|
|
142
|
-
if (stack.length === 0) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
151
|
+
// if (stack.length === 0) {
|
|
152
|
+
// return {
|
|
153
|
+
// success: false,
|
|
154
|
+
// errors: [
|
|
155
|
+
// {
|
|
156
|
+
// action: "drop",
|
|
157
|
+
// node: stream[i],
|
|
158
|
+
// message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
159
|
+
// },
|
|
160
|
+
// ],
|
|
161
|
+
// };
|
|
162
|
+
// }
|
|
154
163
|
if (stack[stack.length - 1].typ === EnumToken.ColonTokenType) {
|
|
155
|
-
if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
164
|
+
// if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
|
|
165
|
+
// const index: number = tokens.indexOf(stack[stack.length - 1]);
|
|
166
|
+
// // expecting ident or dashed ident
|
|
167
|
+
// if (
|
|
168
|
+
// tokens[index + 1]?.typ == EnumToken.IdenTokenType ||
|
|
169
|
+
// tokens[index + 1]?.typ == EnumToken.DashedIdenTokenType
|
|
170
|
+
// ) {
|
|
171
|
+
// const val: string = (tokens[index + 1] as IdentToken | DashedIdentToken).val;
|
|
172
|
+
// Object.assign(tokens[index], {
|
|
173
|
+
// typ: pseudoElements.includes(val)
|
|
174
|
+
// ? EnumToken.PseudoElementTokenType
|
|
175
|
+
// : EnumToken.PseudoClassTokenType,
|
|
176
|
+
// val: ":" + val,
|
|
177
|
+
// });
|
|
178
|
+
// tokens[index][LOC]!.end = tokens[index + 1][LOC]!.end;
|
|
179
|
+
// tokens.splice(index + 1, 1);
|
|
180
|
+
// stack.pop();
|
|
181
|
+
// const index2: number = tokens.indexOf(stack[stack.length - 1]);
|
|
182
|
+
// const result = matchAllSyntaxes(
|
|
183
|
+
// (
|
|
184
|
+
// getParsedSyntax(
|
|
185
|
+
// ValidationSyntaxGroupEnum.Syntaxes,
|
|
186
|
+
// (tokens[index2] as FunctionToken).val + "()",
|
|
187
|
+
// ) as ValidationFunctionToken[]
|
|
188
|
+
// )[0]?.chi as ValidationToken[],
|
|
189
|
+
// createValidationContext(tokens.slice(index2 + 1, -1)),
|
|
190
|
+
// options,
|
|
191
|
+
// );
|
|
192
|
+
// if (!result.success) {
|
|
193
|
+
// return {
|
|
194
|
+
// success: false,
|
|
195
|
+
// errors: result.errors,
|
|
196
|
+
// };
|
|
197
|
+
// }
|
|
198
|
+
// tokens.pop();
|
|
199
|
+
// Object.assign(tokens[index2], {
|
|
200
|
+
// typ: tokensfuncDefMap.get(tokens[index2].typ)!,
|
|
201
|
+
// chi: tokens.splice(index2 + 1, tokens.length - index2 - 1),
|
|
202
|
+
// });
|
|
203
|
+
// tokens[index2][LOC]!.end = stream[i][LOC]!.end;
|
|
204
|
+
// stack.pop();
|
|
205
|
+
// break;
|
|
206
|
+
// }
|
|
207
|
+
// }
|
|
208
|
+
// if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
|
|
209
|
+
// return {
|
|
210
|
+
// success: false,
|
|
211
|
+
// errors: [
|
|
212
|
+
// {
|
|
213
|
+
// action: "drop",
|
|
214
|
+
// node: stream[i],
|
|
215
|
+
// message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
216
|
+
// },
|
|
217
|
+
// ],
|
|
218
|
+
// };
|
|
219
|
+
// }
|
|
197
220
|
// match declaration
|
|
198
221
|
const index = tokens.indexOf(stack[stack.length - 2]);
|
|
199
222
|
const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
200
|
-
const declaration = parseDeclaration(slice, context, { ...options, validation:
|
|
201
|
-
if (declaration.typ !== EnumToken.DeclarationNodeType) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
223
|
+
const declaration = parseDeclaration(slice, context, { ...options, validation: false }, errors);
|
|
224
|
+
// if (declaration.typ !== EnumToken.DeclarationNodeType) {
|
|
225
|
+
// return {
|
|
226
|
+
// success: false,
|
|
227
|
+
// errors: [
|
|
228
|
+
// {
|
|
229
|
+
// action: "drop",
|
|
230
|
+
// node: declaration,
|
|
231
|
+
// message: `invalid declaration at ${declaration?.[LOC]?.src}:${declaration?.[LOC]?.sta.lin}:${declaration?.[LOC]?.sta.col}`,
|
|
232
|
+
// },
|
|
233
|
+
// ],
|
|
234
|
+
// };
|
|
235
|
+
// }
|
|
213
236
|
tokens.splice(index + 1, 0, declaration);
|
|
214
237
|
stack.pop();
|
|
215
238
|
}
|
|
@@ -218,32 +241,34 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
218
241
|
if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
|
|
219
242
|
const index = tokens.indexOf(stack.at(-1));
|
|
220
243
|
const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
221
|
-
|
|
244
|
+
slice.filter((token) => {
|
|
222
245
|
return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
223
246
|
});
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
247
|
+
// if (
|
|
248
|
+
// filtered.length !== 1 ||
|
|
249
|
+
// !(
|
|
250
|
+
// trimTokenSpace.has(filtered[0].typ) ||
|
|
251
|
+
// tokensfuncDefMap.has(filtered[0].typ) ||
|
|
252
|
+
// tokensfuncSet.has(filtered[0].typ)
|
|
253
|
+
// )
|
|
254
|
+
// ) {
|
|
255
|
+
// const token = filtered[0] ?? slice[0] ?? stream[i];
|
|
256
|
+
// return {
|
|
257
|
+
// success: false,
|
|
258
|
+
// errors: [
|
|
259
|
+
// {
|
|
260
|
+
// action: "drop",
|
|
261
|
+
// node: token,
|
|
262
|
+
// message: `expecting '<${filtered[0]?.typ === EnumToken.IdenTokenType ? "supports-condition-name" : "supports-condition"}>' at ${token?.[LOC]?.src}:${token?.[LOC]?.sta.lin}:${token?.[LOC]?.sta.col}`,
|
|
263
|
+
// },
|
|
264
|
+
// ],
|
|
265
|
+
// };
|
|
266
|
+
// }
|
|
267
|
+
tokens[index] = {
|
|
241
268
|
typ: EnumToken.ParensTokenType,
|
|
242
269
|
chi: slice,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
246
|
-
});
|
|
270
|
+
[LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
271
|
+
};
|
|
247
272
|
stack.pop();
|
|
248
273
|
tokens.pop();
|
|
249
274
|
scopes.pop();
|
|
@@ -252,14 +277,12 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
252
277
|
}
|
|
253
278
|
else if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
|
|
254
279
|
const index = tokens.indexOf(stack.at(-1));
|
|
255
|
-
tokens[index] =
|
|
280
|
+
tokens[index] = {
|
|
256
281
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
257
282
|
val: stack.at(-1).val,
|
|
258
283
|
chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
262
|
-
});
|
|
284
|
+
[LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
285
|
+
};
|
|
263
286
|
if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
|
|
264
287
|
// not a declaration
|
|
265
288
|
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
|
|
@@ -278,33 +301,42 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
278
301
|
while (tokensfuncDefMap.has(stack[k]?.typ)) {
|
|
279
302
|
k--;
|
|
280
303
|
}
|
|
281
|
-
if (stack[k]?.typ !== EnumToken.ColonTokenType) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
304
|
+
// if (stack[k]?.typ !== EnumToken.ColonTokenType) {
|
|
305
|
+
// if (
|
|
306
|
+
// tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
|
|
307
|
+
// !equalsIgnoreCase("env", (tokens[index] as FunctionToken).val)
|
|
308
|
+
// ) {
|
|
309
|
+
// errors.push({
|
|
310
|
+
// action: "ignore",
|
|
311
|
+
// node: tokens[index],
|
|
312
|
+
// message: `expecting <supports-selector-fn>, <supports-env-fn>, <font-tech()>, <font-format()>, <at-rule()> or <named-feature()> at ${tokens[index]?.[LOC]?.src}:${tokens[index]?.[LOC]?.sta.lin}:${tokens[index]?.[LOC]?.sta.col}`,
|
|
313
|
+
// });
|
|
314
|
+
// } else {
|
|
315
|
+
// // not a declaration
|
|
316
|
+
// const result = matchAllSyntaxes(
|
|
317
|
+
// (
|
|
318
|
+
// getParsedSyntax(
|
|
319
|
+
// ValidationSyntaxGroupEnum.Syntaxes,
|
|
320
|
+
// (tokens[index] as FunctionToken).val + "()",
|
|
321
|
+
// ) as ValidationFunctionToken[]
|
|
322
|
+
// )?.[0]?.chi as ValidationToken[],
|
|
323
|
+
// createValidationContext((tokens[index] as FunctionToken).chi as Token[]),
|
|
324
|
+
// options,
|
|
325
|
+
// );
|
|
326
|
+
// if (!result.valid) {
|
|
327
|
+
// errors.push(...result.errors, {
|
|
328
|
+
// action: "ignore",
|
|
329
|
+
// node: tokens[index],
|
|
330
|
+
// message: `missing syntax for function '${(tokens[index] as FunctionToken).val}()' at ${tokens[index]?.[LOC]?.src}:${tokens[index]?.[LOC]?.sta.lin}:${tokens[index]?.[LOC]?.sta.col}`,
|
|
331
|
+
// });
|
|
332
|
+
// } else if (!result.success) {
|
|
333
|
+
// return {
|
|
334
|
+
// success: false,
|
|
335
|
+
// errors: result.errors,
|
|
336
|
+
// };
|
|
337
|
+
// }
|
|
338
|
+
// }
|
|
339
|
+
// }
|
|
308
340
|
stack.pop();
|
|
309
341
|
tokens.pop();
|
|
310
342
|
scopes.pop();
|
|
@@ -312,55 +344,51 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
312
344
|
}
|
|
313
345
|
if (stack.at(-1)?.typ === EnumToken.NotTokenType) {
|
|
314
346
|
const index = tokens.indexOf(stack.at(-1));
|
|
315
|
-
tokens[index] =
|
|
347
|
+
tokens[index] = {
|
|
316
348
|
typ: EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
317
349
|
l: stack.at(-1),
|
|
318
350
|
r: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
322
|
-
});
|
|
351
|
+
[LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
352
|
+
};
|
|
323
353
|
stack.pop();
|
|
324
354
|
}
|
|
325
355
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
326
|
-
if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
356
|
+
// if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
|
|
357
|
+
// return {
|
|
358
|
+
// success: false,
|
|
359
|
+
// errors: [
|
|
360
|
+
// {
|
|
361
|
+
// action: "drop",
|
|
362
|
+
// node: stack.at(-2),
|
|
363
|
+
// message: `expecting '(' at ${stack.at(-2)?.[LOC]?.src}:${stack.at(-2)?.[LOC]?.sta.lin}:${stack.at(-2)?.[LOC]?.sta.col}`,
|
|
364
|
+
// },
|
|
365
|
+
// ],
|
|
366
|
+
// };
|
|
367
|
+
// }
|
|
338
368
|
const index = tokens.indexOf(stack.at(-1));
|
|
339
369
|
const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
|
|
340
370
|
const left = trimArray(tokens.slice(index2, index));
|
|
341
|
-
|
|
371
|
+
left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
|
|
342
372
|
t.l.typ === EnumToken.NotTokenType);
|
|
343
|
-
if (notToken != null) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
tokens[index2] =
|
|
373
|
+
// if (notToken != null) {
|
|
374
|
+
// return {
|
|
375
|
+
// success: false,
|
|
376
|
+
// errors: [
|
|
377
|
+
// {
|
|
378
|
+
// action: "drop",
|
|
379
|
+
// node: stack.at(-1),
|
|
380
|
+
// message: `unexpected token after 'not' expression at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
381
|
+
// },
|
|
382
|
+
// ],
|
|
383
|
+
// };
|
|
384
|
+
// }
|
|
385
|
+
tokens[index2] = {
|
|
356
386
|
typ: EnumToken.SupportsQueryConditionTokenType,
|
|
357
387
|
op: stack.at(-1),
|
|
358
388
|
l: left,
|
|
359
389
|
r: trimArray(tokens.slice(index + 1)),
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
|
|
363
|
-
});
|
|
390
|
+
[LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
391
|
+
};
|
|
364
392
|
tokens.length = index2 + 1;
|
|
365
393
|
stack.pop();
|
|
366
394
|
}
|
|
@@ -378,24 +406,24 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
378
406
|
break;
|
|
379
407
|
}
|
|
380
408
|
if ("and" === val || "or" === val) {
|
|
381
|
-
if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
409
|
+
// if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
410
|
+
// return {
|
|
411
|
+
// success: false,
|
|
412
|
+
// errors: [
|
|
413
|
+
// {
|
|
414
|
+
// action: "drop",
|
|
415
|
+
// message: `mixing <and> and <or> at the same level is not allowed at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
416
|
+
// },
|
|
417
|
+
// ],
|
|
418
|
+
// };
|
|
419
|
+
// }
|
|
392
420
|
if ("or" === val && scopes.length === 1) {
|
|
393
421
|
return {
|
|
394
422
|
success: false,
|
|
395
423
|
errors: [
|
|
396
424
|
{
|
|
397
425
|
action: "drop",
|
|
398
|
-
message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.
|
|
426
|
+
message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
399
427
|
},
|
|
400
428
|
],
|
|
401
429
|
};
|
|
@@ -411,18 +439,18 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
411
439
|
break;
|
|
412
440
|
}
|
|
413
441
|
}
|
|
414
|
-
if (stack.length > 0) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
442
|
+
// if (stack.length > 0) {
|
|
443
|
+
// return {
|
|
444
|
+
// success: false,
|
|
445
|
+
// errors: [
|
|
446
|
+
// {
|
|
447
|
+
// action: "drop",
|
|
448
|
+
// node: stack.at(-1),
|
|
449
|
+
// message: `unmatched token '${renderValue(stack.at(-1) as Token)}' at ${stack.at(-1)![LOC]!.src}:${stack.at(-1)![LOC]!.sta.lin}:${stack.at(-1)![LOC]!.sta.col}`,
|
|
450
|
+
// },
|
|
451
|
+
// ],
|
|
452
|
+
// };
|
|
453
|
+
// }
|
|
426
454
|
stream.length = 0;
|
|
427
455
|
stream.push(...trimArray(tokens));
|
|
428
456
|
return { success, errors };
|