@tbela99/css-parser 1.4.2 → 1.4.4

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.
Files changed (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -0,0 +1,431 @@
1
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
+ import { renderValue } from '../../renderer/render.js';
3
+ import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
4
+ import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
5
+ import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
6
+ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
7
+ import { parseDeclaration } from './declaration.js';
8
+ import { equalsIgnoreCase } from './text.js';
9
+ import { pseudoElements } from '../../syntax/syntax.js';
10
+
11
+ function parseAtRuleSupportSyntax(stream, context, options = {}) {
12
+ const tokens = [];
13
+ const stack = [];
14
+ let i = 0;
15
+ let success = true;
16
+ let expectAndOr = false;
17
+ let scope = new Set();
18
+ let val;
19
+ const errors = [];
20
+ const scopes = [scope];
21
+ const trimWhiteSpace = new Set([
22
+ EnumToken.GtTokenType,
23
+ EnumToken.ChildCombinatorTokenType,
24
+ EnumToken.NextSiblingCombinatorTokenType,
25
+ EnumToken.SubsequentSiblingCombinatorTokenType,
26
+ EnumToken.ColumnCombinatorTokenType,
27
+ EnumToken.UniversalSelectorTokenType,
28
+ ]);
29
+ while (i < stream.length &&
30
+ (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
31
+ tokens.push(stream[i]);
32
+ i++;
33
+ }
34
+ if (!tokensfuncDefMap.has(stream[i]?.typ) &&
35
+ stream[i]?.typ !== EnumToken.StartParensTokenType &&
36
+ !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === stream[i]?.val.toLowerCase())) {
37
+ return {
38
+ success: false,
39
+ errors: [
40
+ {
41
+ action: "drop",
42
+ node: stream[i],
43
+ message: `expecting '<supports-condition>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
44
+ },
45
+ ],
46
+ };
47
+ }
48
+ for (; i < stream.length; i++) {
49
+ tokens.push(stream[i]);
50
+ if (stream[i].typ == EnumToken.ColonTokenType) {
51
+ if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
52
+ Object.assign(stream[i], {
53
+ typ: EnumToken.PseudoElementTokenType,
54
+ val: ":" + stream[i + 1].val,
55
+ });
56
+ stream[i].loc.end = stream[i + 1].loc.end;
57
+ stream.splice(i + 1, 1);
58
+ continue;
59
+ }
60
+ if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
61
+ val = ":" + stream[i + 1].val;
62
+ Object.assign(stream[i], {
63
+ typ: val + "()" in getSyntaxConfig().selectors
64
+ ? EnumToken.PseudoClassFunctionTokenDefType
65
+ : stream[i + 1].typ,
66
+ val,
67
+ });
68
+ stack.push(stream[i]);
69
+ stream[i].loc.end = stream[i + 1].loc.end;
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;
95
+ stream.splice(i + 1, 1);
96
+ continue;
97
+ }
98
+ }
99
+ if (trimWhiteSpace.has(stream[i].typ)) {
100
+ if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
101
+ tokens.splice(tokens.length - 2, 1);
102
+ }
103
+ if (stream[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
104
+ i++;
105
+ continue;
106
+ }
107
+ }
108
+ if (expectAndOr) {
109
+ let k = i;
110
+ while (k < stream.length &&
111
+ (stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)) {
112
+ tokens.push(stream[k]);
113
+ k++;
114
+ }
115
+ if (k < stream.length) {
116
+ if (stream[k].typ !== EnumToken.EndParensTokenType &&
117
+ !(stream[k].typ === EnumToken.IdenTokenType &&
118
+ ("and" === stream[k]?.val.toLowerCase() ||
119
+ "or" === stream[k]?.val.toLowerCase()))) {
120
+ return {
121
+ success: false,
122
+ errors: [
123
+ {
124
+ action: "drop",
125
+ node: stream[k],
126
+ message: `expecting 'and' or 'or' at ${stream[k]?.loc?.src}:${stream[k]?.loc?.sta.lin}:${stream[k]?.loc?.sta.col}`,
127
+ },
128
+ ],
129
+ };
130
+ }
131
+ }
132
+ expectAndOr = false;
133
+ }
134
+ if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
135
+ scopes.push((scope = new Set()));
136
+ stack.push(stream[i]);
137
+ continue;
138
+ }
139
+ switch (stream[i].typ) {
140
+ case EnumToken.EndParensTokenType:
141
+ {
142
+ if (stack.length === 0) {
143
+ return {
144
+ success: false,
145
+ errors: [
146
+ {
147
+ action: "drop",
148
+ node: stream[i],
149
+ message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
150
+ },
151
+ ],
152
+ };
153
+ }
154
+ if (stack[stack.length - 1].typ === EnumToken.ColonTokenType) {
155
+ if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
156
+ const index = tokens.indexOf(stack[stack.length - 1]);
157
+ // expecting ident or dashed ident
158
+ if (tokens[index + 1]?.typ == EnumToken.IdenTokenType ||
159
+ tokens[index + 1]?.typ == EnumToken.DashedIdenTokenType) {
160
+ Object.assign(tokens[index], {
161
+ typ: EnumToken.PseudoElementTokenType,
162
+ val: ":" + tokens[index + 1].val,
163
+ });
164
+ tokens[index].loc.end = tokens[index + 1].loc.end;
165
+ tokens.splice(index + 1, 1);
166
+ stack.pop();
167
+ const index2 = tokens.indexOf(stack[stack.length - 1]);
168
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
169
+ if (!result.success) {
170
+ return {
171
+ success: false,
172
+ errors: result.errors,
173
+ };
174
+ }
175
+ tokens.pop();
176
+ Object.assign(tokens[index2], {
177
+ typ: tokensfuncDefMap.get(tokens[index2].typ),
178
+ chi: tokens.splice(index2 + 1, tokens.length - index2 - 1),
179
+ });
180
+ tokens[index2].loc.end = stream[i].loc.end;
181
+ stack.pop();
182
+ break;
183
+ }
184
+ }
185
+ if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
186
+ return {
187
+ success: false,
188
+ errors: [
189
+ {
190
+ action: "drop",
191
+ node: stream[i],
192
+ message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
193
+ },
194
+ ],
195
+ };
196
+ }
197
+ // match declaration
198
+ const index = tokens.indexOf(stack[stack.length - 2]);
199
+ const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
200
+ const declaration = parseDeclaration(slice, context, { ...options, validation: ValidationLevel.None }, errors);
201
+ if (declaration.typ !== EnumToken.DeclarationNodeType) {
202
+ return {
203
+ success: false,
204
+ errors: [
205
+ {
206
+ action: "drop",
207
+ node: declaration,
208
+ message: `invalid declaration at ${declaration?.loc?.src}:${declaration?.loc?.sta.lin}:${declaration?.loc?.sta.col}`,
209
+ },
210
+ ],
211
+ };
212
+ }
213
+ tokens.splice(index + 1, 0, declaration);
214
+ stack.pop();
215
+ }
216
+ // match <support-condition-name>
217
+ // @supports (--condition-name) {}
218
+ if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
219
+ const index = tokens.indexOf(stack.at(-1));
220
+ const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
221
+ const filtered = slice.filter((token) => {
222
+ return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
223
+ });
224
+ if (filtered.length !== 1 ||
225
+ !(trimTokenSpace.has(filtered[0].typ) ||
226
+ tokensfuncDefMap.has(filtered[0].typ) ||
227
+ tokensfuncSet.has(filtered[0].typ))) {
228
+ const token = filtered[0] ?? slice[0] ?? stream[i];
229
+ return {
230
+ success: false,
231
+ errors: [
232
+ {
233
+ action: "drop",
234
+ node: token,
235
+ message: `expecting '<${filtered[0]?.typ === EnumToken.IdenTokenType ? "supports-condition-name" : "supports-condition"}>' at ${token?.loc?.src}:${token?.loc?.sta.lin}:${token?.loc?.sta.col}`,
236
+ },
237
+ ],
238
+ };
239
+ }
240
+ tokens[index] = Object.defineProperty({
241
+ typ: EnumToken.ParensTokenType,
242
+ chi: slice,
243
+ }, "loc", {
244
+ ...definedPropertySettings,
245
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
246
+ });
247
+ stack.pop();
248
+ tokens.pop();
249
+ scopes.pop();
250
+ scope = scopes[scopes.length - 1];
251
+ expectAndOr = true;
252
+ }
253
+ else if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
254
+ const index = tokens.indexOf(stack.at(-1));
255
+ tokens[index] = Object.defineProperty({
256
+ typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
257
+ val: stack.at(-1).val,
258
+ chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
259
+ }, "loc", {
260
+ ...definedPropertySettings,
261
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
262
+ });
263
+ if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
264
+ // not a declaration
265
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
266
+ if (!result.success) {
267
+ return {
268
+ success: false,
269
+ errors: result.errors,
270
+ };
271
+ }
272
+ stack.pop();
273
+ tokens.pop();
274
+ break;
275
+ }
276
+ //
277
+ let k = stack.length - 1;
278
+ while (tokensfuncDefMap.has(stack[k]?.typ)) {
279
+ k--;
280
+ }
281
+ if (stack[k]?.typ !== EnumToken.ColonTokenType) {
282
+ if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
283
+ !equalsIgnoreCase("env", tokens[index].val)) {
284
+ errors.push({
285
+ action: "ignore",
286
+ node: tokens[index],
287
+ 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}`,
288
+ });
289
+ }
290
+ else {
291
+ // not a declaration
292
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
293
+ if (!result.valid) {
294
+ errors.push(...result.errors, {
295
+ action: "ignore",
296
+ node: tokens[index],
297
+ message: `missing syntax for function '${tokens[index].val}()' at ${tokens[index]?.loc?.src}:${tokens[index]?.loc?.sta.lin}:${tokens[index]?.loc?.sta.col}`,
298
+ });
299
+ }
300
+ else if (!result.success) {
301
+ return {
302
+ success: false,
303
+ errors: result.errors,
304
+ };
305
+ }
306
+ }
307
+ }
308
+ stack.pop();
309
+ tokens.pop();
310
+ scopes.pop();
311
+ scope = scopes[scopes.length - 1];
312
+ }
313
+ if (stack.at(-1)?.typ === EnumToken.NotTokenType) {
314
+ const index = tokens.indexOf(stack.at(-1));
315
+ tokens[index] = Object.defineProperty({
316
+ typ: EnumToken.SupportsQueryUnaryConditionTokenType,
317
+ l: stack.at(-1),
318
+ r: trimArray(tokens.splice(index + 1, i - index - 1)),
319
+ }, "loc", {
320
+ ...definedPropertySettings,
321
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
322
+ });
323
+ stack.pop();
324
+ }
325
+ 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
+ return {
328
+ success: false,
329
+ errors: [
330
+ {
331
+ action: "drop",
332
+ node: stack.at(-2),
333
+ message: `expecting '(' at ${stack.at(-2)?.loc?.src}:${stack.at(-2)?.loc?.sta.lin}:${stack.at(-2)?.loc?.sta.col}`,
334
+ },
335
+ ],
336
+ };
337
+ }
338
+ const index = tokens.indexOf(stack.at(-1));
339
+ const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
340
+ const left = trimArray(tokens.slice(index2, index));
341
+ const notToken = left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
342
+ t.l.typ === EnumToken.NotTokenType);
343
+ if (notToken != null) {
344
+ return {
345
+ success: false,
346
+ errors: [
347
+ {
348
+ action: "drop",
349
+ node: stack.at(-1),
350
+ message: `unexpected token after 'not' expression at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
351
+ },
352
+ ],
353
+ };
354
+ }
355
+ tokens[index2] = Object.defineProperty({
356
+ typ: EnumToken.SupportsQueryConditionTokenType,
357
+ op: stack.at(-1),
358
+ l: left,
359
+ r: trimArray(tokens.slice(index + 1)),
360
+ }, "loc", {
361
+ ...definedPropertySettings,
362
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
363
+ });
364
+ tokens.length = index2 + 1;
365
+ stack.pop();
366
+ }
367
+ }
368
+ break;
369
+ case EnumToken.ColonTokenType:
370
+ stack.push(stream[i]);
371
+ break;
372
+ case EnumToken.IdenTokenType:
373
+ {
374
+ const val = stream[i].val.toLowerCase();
375
+ if ("not" === val) {
376
+ stack.push(stream[i]);
377
+ Object.assign(stream[i], { typ: EnumToken.NotTokenType });
378
+ break;
379
+ }
380
+ if ("and" === val || "or" === val) {
381
+ if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
382
+ return {
383
+ success: false,
384
+ errors: [
385
+ {
386
+ action: "drop",
387
+ 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}`,
388
+ },
389
+ ],
390
+ };
391
+ }
392
+ if ("or" === val && scopes.length === 1) {
393
+ return {
394
+ success: false,
395
+ errors: [
396
+ {
397
+ action: "drop",
398
+ 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
+ },
400
+ ],
401
+ };
402
+ }
403
+ Object.assign(stream[i], {
404
+ typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
405
+ });
406
+ scope.add(stream[i].typ);
407
+ stack.push(stream[i]);
408
+ break;
409
+ }
410
+ }
411
+ break;
412
+ }
413
+ }
414
+ if (stack.length > 0) {
415
+ return {
416
+ success: false,
417
+ errors: [
418
+ {
419
+ action: "drop",
420
+ node: stack.at(-1),
421
+ message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
422
+ },
423
+ ],
424
+ };
425
+ }
426
+ stream.length = 0;
427
+ stream.push(...trimArray(tokens));
428
+ return { success, errors };
429
+ }
430
+
431
+ export { parseAtRuleSupportSyntax };