@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,363 @@
1
+ import { EnumToken } from '../../ast/types.js';
2
+ import { renderValue } from '../../renderer/render.js';
3
+ import { trimArray } from '../../validation/match.js';
4
+ import { tokensfuncDefMap, definedPropertySettings, tokensfuncSet } from '../../syntax/constants.js';
5
+ import { parseMediaqueryList } from './at-rule-media.js';
6
+ import { parseAtRuleSupportSyntax } from './at-rule-support.js';
7
+ import { equalsIgnoreCase } from './text.js';
8
+
9
+ const validChildTypes = new Set([
10
+ EnumToken.WhenElseFunctionTokenDefType,
11
+ EnumToken.WhenElseFunctionTokenType,
12
+ EnumToken.WhenElseQueryConditionTokenType,
13
+ EnumToken.WhenElseUnaryConditionTokenType,
14
+ ]);
15
+ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
16
+ const tokens = [];
17
+ const stack = [];
18
+ let i = 0;
19
+ let success = true;
20
+ let expectAndOr = false;
21
+ let scope = new Set();
22
+ const errors = [];
23
+ const scopes = [scope];
24
+ while (i < stream.length &&
25
+ (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
26
+ tokens.push(stream[i]);
27
+ i++;
28
+ }
29
+ if (i >= stream.length) {
30
+ success = "else" === context.nam;
31
+ return {
32
+ success,
33
+ errors: success
34
+ ? []
35
+ : [
36
+ {
37
+ action: "drop",
38
+ node: stream[i],
39
+ location: stream[i]?.loc,
40
+ message: `expecting '<boolean-condition>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
41
+ },
42
+ ],
43
+ };
44
+ }
45
+ if (stream[i]?.typ !== EnumToken.WhenElseFunctionTokenDefType &&
46
+ stream[i]?.typ !== EnumToken.SupportsFunctionTokenDefType &&
47
+ stream[i]?.typ !== EnumToken.StartParensTokenType &&
48
+ 'val' in stream[i] &&
49
+ !(stream[i]?.typ === EnumToken.IdenTokenType &&
50
+ (equalsIgnoreCase(stream[i].val, "not") || equalsIgnoreCase(stream[i].val, "only")))) {
51
+ return {
52
+ success: false,
53
+ errors: [
54
+ {
55
+ action: "drop",
56
+ node: stream[i],
57
+ location: stream[i]?.loc,
58
+ message: `expecting '<boolean-condition>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
59
+ },
60
+ ],
61
+ };
62
+ }
63
+ for (; i < stream.length; i++) {
64
+ tokens.push(stream[i]);
65
+ if (stream[i].typ === EnumToken.StartParensTokenType) {
66
+ stack.push(stream[i]);
67
+ scopes.push((scope = new Set()));
68
+ continue;
69
+ }
70
+ if (expectAndOr) {
71
+ let k = i;
72
+ while (k < stream.length &&
73
+ (stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)) {
74
+ tokens.push(stream[k]);
75
+ k++;
76
+ }
77
+ if (k < stream.length) {
78
+ if (stream[k].typ !== EnumToken.EndParensTokenType &&
79
+ !(stream[k].typ === EnumToken.IdenTokenType &&
80
+ (equalsIgnoreCase(stream[k].val, "and") || equalsIgnoreCase(stream[k].val, "or")))) {
81
+ return {
82
+ success: false,
83
+ errors: [
84
+ {
85
+ action: "drop",
86
+ node: stream[k],
87
+ message: `expecting 'and' or 'or' at ${stream[k]?.loc?.src}:${stream[k]?.loc?.sta.lin}:${stream[k]?.loc?.sta.col}`,
88
+ location: stream[k].loc,
89
+ },
90
+ ],
91
+ };
92
+ }
93
+ }
94
+ expectAndOr = false;
95
+ }
96
+ switch (stream[i].typ) {
97
+ case EnumToken.EndParensTokenType:
98
+ {
99
+ if (stack.length === 0) {
100
+ return {
101
+ success: false,
102
+ errors: [
103
+ {
104
+ action: "drop",
105
+ node: stream[i],
106
+ message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
107
+ },
108
+ ],
109
+ };
110
+ }
111
+ if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
112
+ const index = tokens.indexOf(stack.at(-1));
113
+ const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
114
+ const filtered = slice.filter((token) => {
115
+ return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
116
+ });
117
+ if (filtered.length !== 1 ||
118
+ !(validChildTypes.has(filtered[0].typ) ||
119
+ tokensfuncDefMap.has(filtered[0].typ) ||
120
+ tokensfuncSet.has(filtered[0].typ))) {
121
+ const token = filtered[0] ?? slice[0] ?? stream[i];
122
+ return {
123
+ success: false,
124
+ errors: [
125
+ {
126
+ action: "drop",
127
+ node: token,
128
+ location: token.loc,
129
+ message: `expecting '<boolean-condition"}>' at ${token?.loc?.src}:${token?.loc?.sta.lin}:${token?.loc?.sta.col}`,
130
+ },
131
+ ],
132
+ };
133
+ }
134
+ tokens[index] = Object.defineProperty({
135
+ typ: EnumToken.ParensTokenType,
136
+ chi: slice,
137
+ }, "loc", {
138
+ ...definedPropertySettings,
139
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
140
+ });
141
+ stack.pop();
142
+ tokens.pop();
143
+ scopes.pop();
144
+ scope = scopes[scopes.length - 1];
145
+ expectAndOr = true;
146
+ }
147
+ if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
148
+ const index = tokens.indexOf(stack.at(-1));
149
+ tokens[index] = Object.defineProperty({
150
+ typ: EnumToken.SupportsQueryUnaryConditionTokenType,
151
+ l: stack.at(-1),
152
+ r: trimArray(tokens.splice(index + 1, i - index - 1)),
153
+ }, "loc", {
154
+ ...definedPropertySettings,
155
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
156
+ });
157
+ stack.pop();
158
+ }
159
+ if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
160
+ if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
161
+ return {
162
+ success: false,
163
+ errors: [
164
+ {
165
+ action: "drop",
166
+ node: stack.at(-2),
167
+ message: `expecting '(' at ${stack.at(-2)?.loc?.src}:${stack.at(-2)?.loc?.sta.lin}:${stack.at(-2)?.loc?.sta.col}`,
168
+ },
169
+ ],
170
+ };
171
+ }
172
+ const index = tokens.indexOf(stack.at(-1));
173
+ const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
174
+ const left = trimArray(tokens.slice(index2, index));
175
+ const notToken = left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
176
+ t.l.typ === EnumToken.NotTokenType);
177
+ if (notToken != null) {
178
+ return {
179
+ success: false,
180
+ errors: [
181
+ {
182
+ action: "drop",
183
+ node: stack.at(-1),
184
+ message: `unexpected token after 'not' expression at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
185
+ },
186
+ ],
187
+ };
188
+ }
189
+ tokens[index2] = Object.defineProperty({
190
+ typ: EnumToken.SupportsQueryConditionTokenType,
191
+ op: stack.at(-1),
192
+ l: left,
193
+ r: trimArray(tokens.slice(index + 1)),
194
+ }, "loc", {
195
+ ...definedPropertySettings,
196
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
197
+ });
198
+ tokens.length = index2 + 1;
199
+ stack.pop();
200
+ }
201
+ }
202
+ break;
203
+ case EnumToken.IdenTokenType:
204
+ {
205
+ const val = stream[i].val.toLowerCase();
206
+ if ("not" === val || "only" === val) {
207
+ stack.push(stream[i]);
208
+ Object.assign(stream[i], {
209
+ typ: "only" === val ? EnumToken.OnlyTokenType : EnumToken.NotTokenType,
210
+ });
211
+ break;
212
+ }
213
+ if ("and" === val || "or" === val) {
214
+ if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
215
+ return {
216
+ success: false,
217
+ errors: [
218
+ {
219
+ action: "drop",
220
+ 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}`,
221
+ },
222
+ ],
223
+ };
224
+ }
225
+ if ("or" === val && scopes.length === 1) {
226
+ return {
227
+ success: false,
228
+ errors: [
229
+ {
230
+ action: "drop",
231
+ message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
232
+ },
233
+ ],
234
+ };
235
+ }
236
+ Object.assign(stream[i], {
237
+ typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
238
+ });
239
+ scope.add(stream[i].typ);
240
+ stack.push(stream[i]);
241
+ break;
242
+ }
243
+ }
244
+ break;
245
+ case EnumToken.SupportsFunctionTokenDefType:
246
+ case EnumToken.WhenElseFunctionTokenDefType:
247
+ {
248
+ let matchCount = 1;
249
+ let j = i + 1;
250
+ for (; j < stream.length; j++) {
251
+ if (stream[j].typ === EnumToken.EndParensTokenType) {
252
+ matchCount--;
253
+ if (matchCount === 0) {
254
+ break;
255
+ }
256
+ }
257
+ else if (stream[j].typ === EnumToken.StartParensTokenType ||
258
+ tokensfuncDefMap.has(stream[j].typ)) {
259
+ matchCount++;
260
+ }
261
+ }
262
+ const slice = stream.slice(i, j + 1);
263
+ const funcName = stream[i].val.toLowerCase();
264
+ const tokenList = [
265
+ Object.defineProperty({ typ: EnumToken.StartParensTokenType }, "loc", {
266
+ ...definedPropertySettings,
267
+ value: { ...stream[i].loc, end: { ...stream[j]?.loc?.end } },
268
+ }),
269
+ ].concat(slice.slice(1));
270
+ if ("media" === funcName) {
271
+ const result = parseMediaqueryList(tokenList, options);
272
+ if (!result.success) {
273
+ return result;
274
+ }
275
+ }
276
+ else if ("supports" === funcName) {
277
+ const result = parseAtRuleSupportSyntax(tokenList, context, options);
278
+ if (!result.success) {
279
+ return result;
280
+ }
281
+ }
282
+ else if (stream[i].typ === EnumToken.SupportsFunctionTokenDefType) {
283
+ tokenList.splice(0, tokenList.length, ...slice);
284
+ const result = parseAtRuleSupportSyntax(stream.slice(i, j + 1), context, options);
285
+ if (!result.success) {
286
+ return result;
287
+ }
288
+ }
289
+ else {
290
+ errors.push({
291
+ action: "ignore",
292
+ message: `unknown <boolean-condition> function '${funcName}' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
293
+ node: stream[i],
294
+ location: stream[i].loc,
295
+ });
296
+ }
297
+ Object.defineProperty(Object.assign(stream[i], {
298
+ typ: tokensfuncDefMap.get(stream[i].typ),
299
+ chi: stream[i].typ === EnumToken.SupportsFunctionTokenDefType
300
+ ? trimArray(slice.slice(1, -1))
301
+ : tokenList[0].chi,
302
+ }), "loc", {
303
+ ...definedPropertySettings,
304
+ value: { ...stream[i].loc, end: { ...stream[j]?.loc?.end } },
305
+ });
306
+ if (stack.at(-1)?.typ === EnumToken.NotTokenType || stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
307
+ const index = tokens.indexOf(stack.at(-1));
308
+ tokens[index] = Object.defineProperty({
309
+ typ: EnumToken.WhenElseUnaryConditionTokenType,
310
+ l: stack.at(-1),
311
+ r: trimArray(tokens.slice(index + 1)),
312
+ }, "loc", {
313
+ ...definedPropertySettings,
314
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
315
+ });
316
+ tokens.length = index + 1;
317
+ stack.pop();
318
+ }
319
+ if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
320
+ const index = tokens.indexOf(stack.at(-1));
321
+ const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
322
+ tokens[index2] = Object.defineProperty({
323
+ typ: EnumToken.WhenElseQueryConditionTokenType,
324
+ op: stack.at(-1),
325
+ l: trimArray(tokens.slice(index2, index)),
326
+ r: trimArray(tokens.slice(index + 1)),
327
+ }, "loc", {
328
+ ...definedPropertySettings,
329
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
330
+ });
331
+ tokens.length = index2 + 1;
332
+ stack.pop();
333
+ }
334
+ i = j;
335
+ expectAndOr = true;
336
+ }
337
+ break;
338
+ default:
339
+ if (tokensfuncDefMap.has(stream[i].typ)) {
340
+ stack.push(stream[i]);
341
+ expectAndOr = true;
342
+ }
343
+ break;
344
+ }
345
+ }
346
+ if (stack.length > 0) {
347
+ return {
348
+ success: false,
349
+ errors: [
350
+ {
351
+ action: "drop",
352
+ node: stack.at(-1),
353
+ 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}`,
354
+ },
355
+ ],
356
+ };
357
+ }
358
+ stream.length = 0;
359
+ stream.push(...trimArray(tokens));
360
+ return { success, errors };
361
+ }
362
+
363
+ export { matchAtRuleWhenElseSyntax };
@@ -0,0 +1,31 @@
1
+ import { EnumToken } from '../../ast/types.js';
2
+ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
3
+ import { getSyntaxRule } from '../../validation/config.js';
4
+ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
5
+
6
+ function matchAtRuleSyntax(atRule, stream, options) {
7
+ const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRule.nam);
8
+ const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
9
+ trimArray(stream);
10
+ if (syntax.length === 0) {
11
+ const filtered = stream.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
12
+ if (filtered.length > 0) {
13
+ return {
14
+ success: false,
15
+ errors: [
16
+ {
17
+ action: "drop",
18
+ message: `unexpected token ${EnumToken[filtered[0].typ]} at ${filtered[0].loc.src}:${filtered[0].loc.sta.lin}:${filtered[0].loc.sta.col}`,
19
+ node: filtered[0],
20
+ location: filtered[0].loc,
21
+ },
22
+ ],
23
+ };
24
+ }
25
+ return { success: true, errors: [] };
26
+ }
27
+ const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
28
+ return { success, errors };
29
+ }
30
+
31
+ export { matchAtRuleSyntax };
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * @param fn
4
+ * @returns
5
+ */
6
+ function memoize(fn) {
7
+ const cache = new Map();
8
+ return function (...args) {
9
+ const key = args.flat().join();
10
+ if (cache.has(key)) {
11
+ return cache.get(key);
12
+ }
13
+ const result = fn(...args);
14
+ cache.set(key, result);
15
+ return result;
16
+ };
17
+ }
18
+
19
+ export { memoize };
@@ -1,6 +1,7 @@
1
1
  import config from '../../../config.json.js';
2
2
 
3
3
  Object.freeze(config);
4
+ // @ts-expect-error
4
5
  const getConfig = () => config;
5
6
 
6
7
  export { getConfig };