@tbela99/css-parser 1.4.7 → 1.4.9
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 +33 -2
- package/dist/index-umd-web.js +12953 -13248
- package/dist/index.cjs +10358 -10655
- package/dist/index.d.ts +820 -89
- package/dist/lib/ast/features/calc.js +3 -1
- package/dist/lib/ast/features/if.js +2 -96
- package/dist/lib/ast/features/prefix.js +7 -2
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/find.js +6 -6
- package/dist/lib/ast/math/expression.js +30 -12
- package/dist/lib/ast/minify.js +34 -5
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/utils.js +29 -21
- package/dist/lib/ast/types.js +12 -0
- package/dist/lib/fs/resolve.js +2 -17
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/linesmap.js +78 -0
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +103 -0
- package/dist/lib/parser/tokenize.js +112 -133
- package/dist/lib/parser/utils/at-rule-container.js +12 -44
- package/dist/lib/parser/utils/at-rule-generic.js +12 -24
- package/dist/lib/parser/utils/at-rule-import.js +4 -172
- package/dist/lib/parser/utils/at-rule-media.js +27 -263
- package/dist/lib/parser/utils/at-rule-support.js +8 -258
- package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
- package/dist/lib/parser/utils/declaration.js +5 -95
- package/dist/lib/parser/utils/hash.js +54 -1
- package/dist/lib/parser/utils/selector.js +1 -1
- package/dist/lib/parser/utils/token.js +1 -0
- package/dist/lib/renderer/render.js +79 -45
- package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
- package/dist/lib/syntax/color/cmyk.js +3 -3
- package/dist/lib/syntax/color/color-mix.js +15 -8
- package/dist/lib/syntax/color/color.js +19 -11
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/hsl.js +6 -6
- package/dist/lib/syntax/color/hwb.js +6 -6
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +6 -6
- package/dist/lib/syntax/color/oklab.js +5 -5
- package/dist/lib/syntax/color/oklch.js +5 -5
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +8 -1
- package/dist/lib/syntax/color/utils/distance.js +7 -2
- package/dist/lib/syntax/constants.js +5 -1
- package/dist/lib/syntax/syntax.js +12 -21
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +136 -11
- package/dist/web.js +135 -8
- package/llms.txt +73 -0
- package/package.json +14 -17
|
@@ -23,29 +23,6 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
23
23
|
EnumToken.ColumnCombinatorTokenType,
|
|
24
24
|
EnumToken.UniversalSelectorTokenType,
|
|
25
25
|
]);
|
|
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
|
-
// }
|
|
49
26
|
for (; i < stream.length; i++) {
|
|
50
27
|
tokens.push(stream[i]);
|
|
51
28
|
if (stream[i].typ == EnumToken.ColonTokenType) {
|
|
@@ -75,32 +52,6 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
75
52
|
continue;
|
|
76
53
|
}
|
|
77
54
|
}
|
|
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
|
-
// }
|
|
104
55
|
if (trimWhiteSpace.has(stream[i].typ)) {
|
|
105
56
|
if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
|
|
106
57
|
tokens.splice(tokens.length - 2, 1);
|
|
@@ -117,27 +68,6 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
117
68
|
tokens.push(stream[k]);
|
|
118
69
|
k++;
|
|
119
70
|
}
|
|
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
|
-
// }
|
|
141
71
|
expectAndOr = false;
|
|
142
72
|
}
|
|
143
73
|
if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
|
|
@@ -148,91 +78,11 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
148
78
|
switch (stream[i].typ) {
|
|
149
79
|
case EnumToken.EndParensTokenType:
|
|
150
80
|
{
|
|
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
|
-
// }
|
|
163
81
|
if (stack[stack.length - 1].typ === EnumToken.ColonTokenType) {
|
|
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
|
-
// }
|
|
220
82
|
// match declaration
|
|
221
83
|
const index = tokens.indexOf(stack[stack.length - 2]);
|
|
222
84
|
const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
223
85
|
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
|
-
// }
|
|
236
86
|
tokens.splice(index + 1, 0, declaration);
|
|
237
87
|
stack.pop();
|
|
238
88
|
}
|
|
@@ -244,30 +94,10 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
244
94
|
slice.filter((token) => {
|
|
245
95
|
return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
246
96
|
});
|
|
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
97
|
tokens[index] = {
|
|
268
98
|
typ: EnumToken.ParensTokenType,
|
|
269
99
|
chi: slice,
|
|
270
|
-
[LOC]: { ...stack.at(-1)[LOC], end:
|
|
100
|
+
[LOC]: { ...stack.at(-1)[LOC], end: stream[i]?.[LOC]?.end },
|
|
271
101
|
};
|
|
272
102
|
stack.pop();
|
|
273
103
|
tokens.pop();
|
|
@@ -281,7 +111,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
281
111
|
typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
|
|
282
112
|
val: stack.at(-1).val,
|
|
283
113
|
chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
|
|
284
|
-
[LOC]: { ...stack.at(-1)[LOC], end:
|
|
114
|
+
[LOC]: { ...stack.at(-1)[LOC], end: stream[i]?.[LOC]?.end },
|
|
285
115
|
};
|
|
286
116
|
if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
|
|
287
117
|
// not a declaration
|
|
@@ -301,42 +131,6 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
301
131
|
while (tokensfuncDefMap.has(stack[k]?.typ)) {
|
|
302
132
|
k--;
|
|
303
133
|
}
|
|
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
|
-
// }
|
|
340
134
|
stack.pop();
|
|
341
135
|
tokens.pop();
|
|
342
136
|
scopes.pop();
|
|
@@ -348,46 +142,22 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
348
142
|
typ: EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
349
143
|
l: stack.at(-1),
|
|
350
144
|
r: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
351
|
-
[LOC]: { ...stack.at(-1)[LOC], end:
|
|
145
|
+
[LOC]: { ...stack.at(-1)[LOC], end: stream[i]?.[LOC]?.end },
|
|
352
146
|
};
|
|
353
147
|
stack.pop();
|
|
354
148
|
}
|
|
355
149
|
if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
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
|
-
// }
|
|
368
150
|
const index = tokens.indexOf(stack.at(-1));
|
|
369
151
|
const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
|
|
370
152
|
const left = trimArray(tokens.slice(index2, index));
|
|
371
153
|
left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
|
|
372
154
|
t.l.typ === EnumToken.NotTokenType);
|
|
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
155
|
tokens[index2] = {
|
|
386
156
|
typ: EnumToken.SupportsQueryConditionTokenType,
|
|
387
157
|
op: stack.at(-1),
|
|
388
158
|
l: left,
|
|
389
159
|
r: trimArray(tokens.slice(index + 1)),
|
|
390
|
-
[LOC]: { ...stack.at(-1)[LOC], end:
|
|
160
|
+
[LOC]: { ...stack.at(-1)[LOC], end: stream[i]?.[LOC]?.end },
|
|
391
161
|
};
|
|
392
162
|
tokens.length = index2 + 1;
|
|
393
163
|
stack.pop();
|
|
@@ -406,24 +176,16 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
406
176
|
break;
|
|
407
177
|
}
|
|
408
178
|
if ("and" === val || "or" === val) {
|
|
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
|
-
// }
|
|
420
179
|
if ("or" === val && scopes.length === 1) {
|
|
180
|
+
const fileName = options.source.getFileName() ?? "";
|
|
181
|
+
const [line, column] = options.source.getOffsets(stream[i]?.[LOC]?.sta);
|
|
421
182
|
return {
|
|
422
183
|
success: false,
|
|
423
184
|
errors: [
|
|
424
185
|
{
|
|
425
186
|
action: "drop",
|
|
426
|
-
message: `<or> is not allowed outside of a parenthesis at ${
|
|
187
|
+
message: `<or> is not allowed outside of a parenthesis at ${fileName}:${line}:${column}`,
|
|
188
|
+
location: [fileName, line, column],
|
|
427
189
|
},
|
|
428
190
|
],
|
|
429
191
|
};
|
|
@@ -439,18 +201,6 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
439
201
|
break;
|
|
440
202
|
}
|
|
441
203
|
}
|
|
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
|
-
// }
|
|
454
204
|
stream.length = 0;
|
|
455
205
|
stream.push(...trimArray(tokens));
|
|
456
206
|
return { success, errors };
|
|
@@ -12,59 +12,9 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
12
12
|
let expectAndOr = false;
|
|
13
13
|
let scope = new Set();
|
|
14
14
|
const errors = [];
|
|
15
|
-
//
|
|
16
|
-
// i < stream.length &&
|
|
17
|
-
// (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)
|
|
18
|
-
// ) {
|
|
19
|
-
// tokens.push(stream[i]);
|
|
20
|
-
// i++;
|
|
21
|
-
// }
|
|
22
|
-
// if (i >= stream.length) {
|
|
23
|
-
// success = "else" === context.nam;
|
|
24
|
-
// return {
|
|
25
|
-
// success,
|
|
26
|
-
// errors: success
|
|
27
|
-
// ? []
|
|
28
|
-
// : [
|
|
29
|
-
// {
|
|
30
|
-
// action: "drop",
|
|
31
|
-
// node: stream[i],
|
|
32
|
-
// location: stream[i]?.[LOC],
|
|
33
|
-
// message: `expecting '<boolean-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
34
|
-
// },
|
|
35
|
-
// ],
|
|
36
|
-
// };
|
|
37
|
-
// }
|
|
38
|
-
// if (
|
|
39
|
-
// stream[i]?.typ !== EnumToken.WhenElseFunctionTokenDefType &&
|
|
40
|
-
// stream[i]?.typ !== EnumToken.SupportsFunctionTokenDefType &&
|
|
41
|
-
// stream[i]?.typ !== EnumToken.StartParensTokenType &&
|
|
42
|
-
// "val" in stream[i] &&
|
|
43
|
-
// !(
|
|
44
|
-
// stream[i]?.typ === EnumToken.IdenTokenType &&
|
|
45
|
-
// (equalsIgnoreCase((stream[i] as IdentToken).val, "not") ||
|
|
46
|
-
// equalsIgnoreCase((stream[i] as IdentToken).val, "only"))
|
|
47
|
-
// )
|
|
48
|
-
// ) {
|
|
49
|
-
// return {
|
|
50
|
-
// success: false,
|
|
51
|
-
// errors: [
|
|
52
|
-
// {
|
|
53
|
-
// action: "drop",
|
|
54
|
-
// node: stream[i],
|
|
55
|
-
// location: stream[i]?.[LOC],
|
|
56
|
-
// message: `expecting '<boolean-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
57
|
-
// },
|
|
58
|
-
// ],
|
|
59
|
-
// };
|
|
60
|
-
// }
|
|
15
|
+
// const scopes: Array<Set<EnumToken>> = [scope];
|
|
61
16
|
for (; i < stream.length; i++) {
|
|
62
17
|
tokens.push(stream[i]);
|
|
63
|
-
// if (stream[i].typ === EnumToken.StartParensTokenType) {
|
|
64
|
-
// stack.push(stream[i]);
|
|
65
|
-
// scopes.push((scope = new Set()));
|
|
66
|
-
// continue;
|
|
67
|
-
// }
|
|
68
18
|
if (expectAndOr) {
|
|
69
19
|
let k = i;
|
|
70
20
|
while (k < stream.length &&
|
|
@@ -72,173 +22,13 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
72
22
|
tokens.push(stream[k]);
|
|
73
23
|
k++;
|
|
74
24
|
}
|
|
75
|
-
// if (k < stream.length) {
|
|
76
|
-
// if (
|
|
77
|
-
// stream[k].typ !== EnumToken.EndParensTokenType &&
|
|
78
|
-
// !(
|
|
79
|
-
// stream[k].typ === EnumToken.IdenTokenType &&
|
|
80
|
-
// (equalsIgnoreCase((stream[k] as IdentToken).val, "and") ||
|
|
81
|
-
// equalsIgnoreCase((stream[k] as IdentToken).val, "or"))
|
|
82
|
-
// )
|
|
83
|
-
// ) {
|
|
84
|
-
// return {
|
|
85
|
-
// success: false,
|
|
86
|
-
// errors: [
|
|
87
|
-
// {
|
|
88
|
-
// action: "drop",
|
|
89
|
-
// node: stream[k],
|
|
90
|
-
// message: `expecting 'and' or 'or' at ${stream[k]?.[LOC]?.src}:${stream[k]?.[LOC]?.sta.lin}:${stream[k]?.[LOC]?.sta.col}`,
|
|
91
|
-
// location: stream[k][LOC],
|
|
92
|
-
// },
|
|
93
|
-
// ],
|
|
94
|
-
// };
|
|
95
|
-
// }
|
|
96
|
-
// }
|
|
97
25
|
expectAndOr = false;
|
|
98
26
|
}
|
|
99
27
|
switch (stream[i].typ) {
|
|
100
|
-
// case EnumToken.EndParensTokenType:
|
|
101
|
-
// {
|
|
102
|
-
// if (stack.length === 0) {
|
|
103
|
-
// return {
|
|
104
|
-
// success: false,
|
|
105
|
-
// errors: [
|
|
106
|
-
// {
|
|
107
|
-
// action: "drop",
|
|
108
|
-
// node: stream[i],
|
|
109
|
-
// message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
110
|
-
// },
|
|
111
|
-
// ],
|
|
112
|
-
// };
|
|
113
|
-
// }
|
|
114
|
-
// if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
|
|
115
|
-
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
116
|
-
// const slice: Token[] = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
117
|
-
// const filtered: Token[] = slice.filter((token) => {
|
|
118
|
-
// return (
|
|
119
|
-
// token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType
|
|
120
|
-
// );
|
|
121
|
-
// });
|
|
122
|
-
// if (
|
|
123
|
-
// filtered.length !== 1 ||
|
|
124
|
-
// !(
|
|
125
|
-
// validChildTypes.has(filtered[0].typ) ||
|
|
126
|
-
// tokensfuncDefMap.has(filtered[0].typ) ||
|
|
127
|
-
// tokensfuncSet.has(filtered[0].typ)
|
|
128
|
-
// )
|
|
129
|
-
// ) {
|
|
130
|
-
// const token = filtered[0] ?? slice[0] ?? stream[i];
|
|
131
|
-
// return {
|
|
132
|
-
// success: false,
|
|
133
|
-
// errors: [
|
|
134
|
-
// {
|
|
135
|
-
// action: "drop",
|
|
136
|
-
// node: token,
|
|
137
|
-
// location: token[LOC],
|
|
138
|
-
// message: `expecting '<boolean-condition"}>' at ${token?.[LOC]?.src}:${token?.[LOC]?.sta.lin}:${token?.[LOC]?.sta.col}`,
|
|
139
|
-
// },
|
|
140
|
-
// ],
|
|
141
|
-
// };
|
|
142
|
-
// }
|
|
143
|
-
// tokens[index] = {
|
|
144
|
-
// typ: EnumToken.ParensTokenType,
|
|
145
|
-
// chi: slice,
|
|
146
|
-
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } } as Location,
|
|
147
|
-
// };
|
|
148
|
-
// stack.pop();
|
|
149
|
-
// tokens.pop();
|
|
150
|
-
// scopes.pop();
|
|
151
|
-
// scope = scopes[scopes.length - 1];
|
|
152
|
-
// expectAndOr = true;
|
|
153
|
-
// }
|
|
154
|
-
// if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
|
|
155
|
-
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
156
|
-
// tokens[index] = {
|
|
157
|
-
// typ: EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
158
|
-
// l: stack.at(-1),
|
|
159
|
-
// r: trimArray(tokens.splice(index + 1, i - index - 1)),
|
|
160
|
-
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
161
|
-
// } as SupportsQueryUnaryConditionToken;
|
|
162
|
-
// stack.pop();
|
|
163
|
-
// }
|
|
164
|
-
// if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
|
|
165
|
-
// if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
|
|
166
|
-
// return {
|
|
167
|
-
// success: false,
|
|
168
|
-
// errors: [
|
|
169
|
-
// {
|
|
170
|
-
// action: "drop",
|
|
171
|
-
// node: stack.at(-2),
|
|
172
|
-
// message: `expecting '(' at ${stack.at(-2)?.[LOC]?.src}:${stack.at(-2)?.[LOC]?.sta.lin}:${stack.at(-2)?.[LOC]?.sta.col}`,
|
|
173
|
-
// },
|
|
174
|
-
// ],
|
|
175
|
-
// };
|
|
176
|
-
// }
|
|
177
|
-
// const index: number = tokens.indexOf(stack.at(-1)!);
|
|
178
|
-
// const index2: number = stack.length > 1 ? tokens.indexOf(stack.at(-2)!) + 1 : 0;
|
|
179
|
-
// const left: Token[] = trimArray(tokens.slice(index2, index));
|
|
180
|
-
// const notToken = left.find(
|
|
181
|
-
// (t) =>
|
|
182
|
-
// t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
|
|
183
|
-
// (t as SupportsQueryUnaryConditionToken).l.typ === EnumToken.NotTokenType,
|
|
184
|
-
// );
|
|
185
|
-
// if (notToken != null) {
|
|
186
|
-
// return {
|
|
187
|
-
// success: false,
|
|
188
|
-
// errors: [
|
|
189
|
-
// {
|
|
190
|
-
// action: "drop",
|
|
191
|
-
// node: stack.at(-1),
|
|
192
|
-
// message: `unexpected token after 'not' expression at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
|
|
193
|
-
// },
|
|
194
|
-
// ],
|
|
195
|
-
// };
|
|
196
|
-
// }
|
|
197
|
-
// tokens[index2] = {
|
|
198
|
-
// typ: EnumToken.SupportsQueryConditionTokenType,
|
|
199
|
-
// op: stack.at(-1)!,
|
|
200
|
-
// l: left,
|
|
201
|
-
// r: trimArray(tokens.slice(index + 1)),
|
|
202
|
-
// [LOC]: { ...stack.at(-1)![LOC], end: { ...stream[i]?.[LOC]?.end } },
|
|
203
|
-
// } as SupportsQueryConditionToken;
|
|
204
|
-
// tokens.length = index2 + 1;
|
|
205
|
-
// stack.pop();
|
|
206
|
-
// }
|
|
207
|
-
// }
|
|
208
|
-
// break;
|
|
209
28
|
case EnumToken.IdenTokenType:
|
|
210
29
|
{
|
|
211
30
|
const val = stream[i].val.toLowerCase();
|
|
212
|
-
// if ("not" === val || "only" === val) {
|
|
213
|
-
// stack.push(stream[i]);
|
|
214
|
-
// Object.assign(stream[i], {
|
|
215
|
-
// typ: "only" === val ? EnumToken.OnlyTokenType : EnumToken.NotTokenType,
|
|
216
|
-
// });
|
|
217
|
-
// break;
|
|
218
|
-
// }
|
|
219
31
|
if ("and" === val || "or" === val) {
|
|
220
|
-
// if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
|
|
221
|
-
// return {
|
|
222
|
-
// success: false,
|
|
223
|
-
// errors: [
|
|
224
|
-
// {
|
|
225
|
-
// action: "drop",
|
|
226
|
-
// 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}`,
|
|
227
|
-
// },
|
|
228
|
-
// ],
|
|
229
|
-
// };
|
|
230
|
-
// }
|
|
231
|
-
// if ("or" === val && scopes.length === 1) {
|
|
232
|
-
// return {
|
|
233
|
-
// success: false,
|
|
234
|
-
// errors: [
|
|
235
|
-
// {
|
|
236
|
-
// action: "drop",
|
|
237
|
-
// message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
|
|
238
|
-
// },
|
|
239
|
-
// ],
|
|
240
|
-
// };
|
|
241
|
-
// }
|
|
242
32
|
Object.assign(stream[i], {
|
|
243
33
|
typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
|
|
244
34
|
});
|
|
@@ -270,7 +60,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
270
60
|
const tokenList = [
|
|
271
61
|
{
|
|
272
62
|
typ: EnumToken.StartParensTokenType,
|
|
273
|
-
[LOC]: { ...stream[i][LOC], end:
|
|
63
|
+
[LOC]: { ...stream[i][LOC], end: stream[j]?.[LOC]?.end },
|
|
274
64
|
},
|
|
275
65
|
// @ts-expect-error
|
|
276
66
|
].concat(slice.slice(1));
|
|
@@ -301,7 +91,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
301
91
|
// location: stream[i][LOC],
|
|
302
92
|
// });
|
|
303
93
|
// }
|
|
304
|
-
stream[i][LOC] = { ...stream[i][LOC], end:
|
|
94
|
+
stream[i][LOC] = { ...stream[i][LOC], end: stream[j]?.[LOC]?.end };
|
|
305
95
|
Object.assign(stream[i], {
|
|
306
96
|
typ: tokensfuncDefMap.get(stream[i].typ),
|
|
307
97
|
chi: stream[i].typ === EnumToken.SupportsFunctionTokenDefType
|
|
@@ -327,7 +117,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
|
|
|
327
117
|
op: stack.at(-1),
|
|
328
118
|
l: trimArray(tokens.slice(index2, index)),
|
|
329
119
|
r: trimArray(tokens.slice(index + 1)),
|
|
330
|
-
[LOC]: { ...stack.at(-1)[LOC], end:
|
|
120
|
+
[LOC]: { ...stack.at(-1)[LOC], end: stream[i]?.[LOC]?.end },
|
|
331
121
|
};
|
|
332
122
|
tokens.length = index2 + 1;
|
|
333
123
|
stack.pop();
|