@tbela99/css-parser 1.4.11 → 1.6.0

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 (80) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +18 -11
  3. package/dist/index-umd-web.js +6558 -5310
  4. package/dist/index.cjs +6576 -5313
  5. package/dist/index.d.ts +805 -279
  6. package/dist/lib/ast/clone.js +13 -8
  7. package/dist/lib/ast/expand.js +65 -15
  8. package/dist/lib/ast/features/calc.js +19 -56
  9. package/dist/lib/ast/features/if.js +28 -4
  10. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  11. package/dist/lib/ast/features/prefix.js +52 -73
  12. package/dist/lib/ast/features/shorthand.js +11 -6
  13. package/dist/lib/ast/features/transform.js +6 -3
  14. package/dist/lib/ast/find.js +7 -5
  15. package/dist/lib/ast/math/expression.js +190 -32
  16. package/dist/lib/ast/minify.js +117 -49
  17. package/dist/lib/ast/node.js +52 -0
  18. package/dist/lib/ast/transform/compute.js +63 -4
  19. package/dist/lib/ast/transform/minify.js +6 -6
  20. package/dist/lib/ast/transform/perspective.js +1 -1
  21. package/dist/lib/ast/transform/rotate.js +1 -1
  22. package/dist/lib/ast/transform/scale.js +1 -1
  23. package/dist/lib/ast/transform/skew.js +1 -1
  24. package/dist/lib/ast/transform/translate.js +1 -1
  25. package/dist/lib/ast/transform/utils.js +46 -18
  26. package/dist/lib/ast/types.js +1 -1
  27. package/dist/lib/ast/walk.js +55 -11
  28. package/dist/lib/fs/resolve.js +68 -27
  29. package/dist/lib/parser/declaration/list.js +22 -7
  30. package/dist/lib/parser/declaration/map.js +40 -13
  31. package/dist/lib/parser/declaration/set.js +3 -1
  32. package/dist/lib/parser/linesmap.js +2 -12
  33. package/dist/lib/parser/parse.js +843 -912
  34. package/dist/lib/parser/source.js +16 -2
  35. package/dist/lib/parser/tokenize.js +1489 -725
  36. package/dist/lib/parser/utils/at-rule-container.js +29 -196
  37. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  38. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  39. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  40. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  41. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  42. package/dist/lib/parser/utils/at-rule.js +0 -18
  43. package/dist/lib/parser/utils/declaration.js +30 -95
  44. package/dist/lib/parser/utils/hash.js +4 -4
  45. package/dist/lib/parser/utils/selector.js +164 -141
  46. package/dist/lib/parser/utils/text.js +4 -2
  47. package/dist/lib/renderer/render.js +230 -125
  48. package/dist/lib/renderer/sourcemap/lib/codec.js +78 -0
  49. package/dist/lib/renderer/sourcemap/sourcemap.js +187 -34
  50. package/dist/lib/syntax/color/a98rgb.js +14 -4
  51. package/dist/lib/syntax/color/cmyk.js +10 -18
  52. package/dist/lib/syntax/color/color-mix.js +21 -34
  53. package/dist/lib/syntax/color/color.js +32 -49
  54. package/dist/lib/syntax/color/hsl.js +15 -15
  55. package/dist/lib/syntax/color/hwb.js +18 -17
  56. package/dist/lib/syntax/color/lab.js +17 -17
  57. package/dist/lib/syntax/color/lch.js +13 -13
  58. package/dist/lib/syntax/color/oklab.js +10 -11
  59. package/dist/lib/syntax/color/oklch.js +15 -18
  60. package/dist/lib/syntax/color/p3.js +18 -12
  61. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  62. package/dist/lib/syntax/color/rec2020.js +8 -4
  63. package/dist/lib/syntax/color/relative-color.js +26 -10
  64. package/dist/lib/syntax/color/srgb.js +5 -4
  65. package/dist/lib/syntax/color/utils/distance.js +1 -1
  66. package/dist/lib/syntax/color/xyz.js +2 -2
  67. package/dist/lib/syntax/color/xyzd50.js +2 -2
  68. package/dist/lib/syntax/constants.js +12 -2
  69. package/dist/lib/syntax/syntax.js +45 -258
  70. package/dist/lib/validation/config.json.js +3 -0
  71. package/dist/lib/validation/match.js +110 -27
  72. package/dist/node.js +55 -33
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.d.ts +16 -0
  76. package/dist/utils/sync.js +73 -0
  77. package/dist/web.js +37 -30
  78. package/package.json +1 -1
  79. package/dist/lib/renderer/sourcemap/lib/encode.js +0 -37
  80. package/llms.txt +0 -73
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import { tokensfuncDefMap, LOC, mFGT, mFLT } from '../../syntax/constants.js';
2
+ import { tokensfuncDefMap, LOCSTA, mFGT, mFLT, LOCEND, LOCSRCID } from '../../syntax/constants.js';
3
3
  import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
5
  import { getSyntaxRule } from '../../validation/config.js';
@@ -28,7 +28,9 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
28
28
  }, [[]]);
29
29
  const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
30
30
  if (!result.success) {
31
- errors.push(...result.errors);
31
+ for (const error of result.errors) {
32
+ errors.push(error);
33
+ }
32
34
  return {
33
35
  success: false,
34
36
  errors,
@@ -48,19 +50,6 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
48
50
  (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
49
51
  tokens.push(stream[i++]);
50
52
  }
51
- // if (i >= stream.length) {
52
- // return {
53
- // success: false,
54
- // errors: [
55
- // {
56
- // action: "drop",
57
- // node: context,
58
- // location: context[LOC],
59
- // message: `expecting <container-condition> at ${context[LOC]?.src}:${context?.[LOC]?.sta.lin}:${context[LOC]?.sta.col}`,
60
- // },
61
- // ],
62
- // };
63
- // }
64
53
  if (stream[i].typ === EnumToken.IdenTokenType) {
65
54
  tokens.push(stream[i++]);
66
55
  }
@@ -76,7 +65,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
76
65
  {
77
66
  action: "drop",
78
67
  node: stream[i],
79
- location: options.source.getSourceLocation(stream[i]?.[LOC].sta), // ?? context[LOC],
68
+ location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
80
69
  message: `expecting <container-condition>`,
81
70
  },
82
71
  ],
@@ -101,11 +90,10 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
101
90
  action: "drop",
102
91
  node: stream[i],
103
92
  message: `expecting <and>, <or> or comma`,
104
- location: options.source.getSourceLocation(stream[i]?.[LOC].sta),
93
+ location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
105
94
  });
106
95
  break;
107
96
  }
108
- // expectAndOr = false;
109
97
  }
110
98
  if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
111
99
  scopes.push((currentScope = new Set()));
@@ -138,174 +126,35 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
138
126
  success = false;
139
127
  errors.push({
140
128
  action: "drop",
141
- node: options.source.getSourceLocation(stream[i][LOC].sta),
129
+ node: stream[i],
130
+ location: options.source.getSourceLocation(stream[i][LOCSTA]),
142
131
  message: `<or> is not allowed outside of parentheses`,
143
132
  });
144
133
  break;
145
134
  }
146
- // if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
147
- // success = false;
148
- // errors.push({
149
- // action: "drop",
150
- // node: stream[i],
151
- // message: `cannot mix <and> and <or> at the same level at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
152
- // });
153
- // break;
154
- // }
155
135
  currentScope.add(stream[i].typ);
156
136
  stack.push(stream[i]);
157
137
  }
158
- // else if (scopes.length === 0) {
159
- // success = false;
160
- // errors.push({
161
- // action: "drop",
162
- // node: stream[i],
163
- // location: stream[i]?.[LOC],
164
- // message: `unexpected <ident> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
165
- // });
166
- // return {
167
- // success,
168
- // errors,
169
- // };
170
- // }
171
138
  }
172
139
  break;
173
140
  case EnumToken.EndParensTokenType:
174
- // feature
175
- // if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
176
- // // <mf-lt> | <mf-gt>
177
- // const index: number = tokens.indexOf(stack.at(-1)!);
178
- // const prevToken: Token = stack[stack.length - 2];
179
- // if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
180
- // if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
181
- // success = false;
182
- // errors.push({
183
- // action: "drop",
184
- // node: stream[i],
185
- // message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
186
- // });
187
- // break;
188
- // }
189
- // if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
190
- // success = false;
191
- // errors.push({
192
- // action: "drop",
193
- // node: stack.at(-1),
194
- // message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
195
- // });
196
- // break;
197
- // } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
198
- // success = false;
199
- // errors.push({
200
- // action: "drop",
201
- // node: stream[i],
202
- // message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
203
- // });
204
- // break;
205
- // }
206
- // // <style-range>
207
- // // const index: number = tokens.indexOf(stack.at(-1)!);
208
- // // <mf-lt> | <mf-gt>
209
- // const index2: number = tokens.indexOf(prevToken);
210
- // // '('
211
- // const index3: number = tokens.indexOf(stack.at(-3)!);
212
- // const left: Token[] = trimArray(tokens.slice(index3 + 1, index2));
213
- // const right: Token[] = trimArray(tokens.slice(index + 1, tokens.length - 1));
214
- // const names: Token[] = trimArray(tokens.slice(index2 + 1, index));
215
- // if (!isStyleFeatureValue(left)) {
216
- // success = false;
217
- // errors.push({
218
- // action: "drop",
219
- // node: left[0],
220
- // message: `expected <style-feature-value> at ${left[0]?.[LOC]?.src}:${left[0]?.[LOC]?.sta.lin}:${left[0]?.[LOC]?.sta.col}`,
221
- // });
222
- // break;
223
- // }
224
- // if (!isStyleFeatureValue(right)) {
225
- // success = false;
226
- // errors.push({
227
- // action: "drop",
228
- // node: right[0],
229
- // message: `expected <style-feature-value> at ${right[0]?.[LOC]?.src}:${right[0]?.[LOC]?.sta.lin}:${right[0]?.[LOC]?.sta.col}`,
230
- // });
231
- // break;
232
- // }
233
- // if (!isStyleFeatureValue(names)) {
234
- // success = false;
235
- // errors.push({
236
- // action: "drop",
237
- // node: names[0],
238
- // message: `expected <style-feature-value> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
239
- // });
240
- // break;
241
- // }
242
- // tokens.splice(index3 + 1, tokens.length - index3 - 2, {
243
- // typ: EnumToken.ContainerStyleRangeTokenType,
244
- // l: left,
245
- // op: names,
246
- // r: right,
247
- // [LOC]: { ...left[0][LOC]!, end: right.at(-1)![LOC]!.end },
248
- // } as ContainerStyleRangeToken);
249
- // // check <style()> or <scroll-state()>
250
- // stack.pop();
251
- // stack.pop();
252
- // } else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
253
- // success = false;
254
- // errors.push({
255
- // action: "drop",
256
- // node: stream[i],
257
- // location: stream[i]?.[LOC],
258
- // message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
259
- // });
260
- // break;
261
- // }
262
- // }
263
141
  if (mFGT.has(stack.at(-1)?.typ) ||
264
142
  mFLT.has(stack.at(-1)?.typ) ||
265
143
  stack.at(-1)?.typ === EnumToken.DelimTokenType ||
266
144
  stack.at(-1)?.typ === EnumToken.ColonTokenType) {
267
145
  stack[stack.length - 2].val?.toLowerCase?.();
268
- // if (
269
- // stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
270
- // !(
271
- // stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
272
- // ("style" === funcName || "scroll-state" === funcName)
273
- // )
274
- // ) {
275
- // success = false;
276
- // errors.push({
277
- // action: "drop",
278
- // node: stream[i],
279
- // location: stream[i]?.[LOC],
280
- // message: `unmatched2 ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
281
- // });
282
- // break;
283
- // }
284
146
  const index2 = tokens.indexOf(stack.at(-1));
285
147
  const index3 = tokens.indexOf(stack.at(-2));
286
148
  let names = trimArray(tokens.slice(index3 + 1, index2));
287
149
  let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
288
- // if (
289
- // stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
290
- // stack.at(-1)?.typ !== EnumToken.DelimTokenType
291
- // ) {
292
- // const filteredNames = names.filter(
293
- // (n) =>
294
- // n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
295
- // );
296
- // if (
297
- // filteredNames.length !== 1 ||
298
- // (filteredNames[0].typ !== EnumToken.IdenTokenType &&
299
- // filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
300
- // ) {
301
- // }
302
- // }
303
150
  tokens.splice(index3 + 1, tokens.length - index3 - 2, {
304
151
  typ: EnumToken.MediaQueryConditionTokenType,
305
152
  l: names,
306
153
  op: stack.pop(),
307
154
  r: values,
308
- [LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
155
+ [LOCSRCID]: names[0][LOCSRCID],
156
+ [LOCSTA]: names[0][LOCSTA],
157
+ [LOCEND]: values.at(-1)[LOCEND],
309
158
  });
310
159
  // check <style()> or <scroll-state()>
311
160
  }
@@ -315,13 +164,15 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
315
164
  typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
316
165
  chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
317
166
  });
318
- tokens[index][LOC] = { ...tokens[index][LOC], end: stream[i][LOC].end };
167
+ tokens[index][LOCSRCID] = tokens[index][LOCSRCID];
168
+ tokens[index][LOCSTA] = tokens[index][LOCSTA];
169
+ tokens[index][LOCEND] = stream[i][LOCEND];
319
170
  if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
320
171
  success = false;
321
172
  errors.push({
322
173
  action: "drop",
323
174
  node: stream[i],
324
- location: options.source.getSourceLocation(stream[i]?.[LOC].sta),
175
+ location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
325
176
  message: `expecting '<${tokens[index].val}-query>'`,
326
177
  });
327
178
  break;
@@ -336,14 +187,16 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
336
187
  tokens[index] = {
337
188
  typ: EnumToken.ParensTokenType,
338
189
  chi: tokens.slice(index + 1, tokens.length - 1),
339
- [LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
190
+ [LOCSRCID]: tokens[index][LOCSRCID],
191
+ [LOCSTA]: tokens[index][LOCSTA],
192
+ [LOCEND]: stream[i][LOCEND],
340
193
  };
341
194
  if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
342
195
  success = false;
343
196
  errors.push({
344
197
  action: "drop",
345
198
  node: stream[i],
346
- location: options.source.getSourceLocation(stream[i]?.[LOC].sta),
199
+ location: options.source.getSourceLocation(stream[i]?.[LOCSTA]),
347
200
  message: `expecting '<query-in-parens>'`,
348
201
  });
349
202
  break;
@@ -365,21 +218,12 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
365
218
  errors.push({
366
219
  action: "drop",
367
220
  node: tokens[k],
368
- location: options.source.getSourceLocation(tokens[k]?.[LOC].sta),
221
+ location: options.source.getSourceLocation(tokens[k]?.[LOCSTA]),
369
222
  message: `unexpected token 'not'`,
370
223
  });
371
224
  break;
372
225
  }
373
226
  }
374
- // const index = tokens.indexOf(stack.at(-1)!);
375
- // const slice = trimArray(tokens.slice(index + 1));
376
- // tokens[index] = {
377
- // typ: EnumToken.MediaQueryUnaryFeatureTokenType,
378
- // l: stack.pop()!,
379
- // r: slice,
380
- // [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end },
381
- // };
382
- // tokens.length = index + 1;
383
227
  }
384
228
  if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
385
229
  stack.at(-1)?.typ === EnumToken.OrTokenType) {
@@ -397,31 +241,19 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
397
241
  op: stack.pop(),
398
242
  l: left,
399
243
  r: right,
400
- [LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
244
+ [LOCSRCID]: left[0][LOCSRCID],
245
+ [LOCSTA]: left[0][LOCSTA],
246
+ [LOCEND]: right.at(-1)[LOCEND],
401
247
  };
402
248
  tokens.length = l + 1;
403
249
  expectAndOr = true;
404
250
  }
405
251
  break;
406
- // default:
407
- // if (tokensfuncDefMap.has(stream[i]?.typ)) {
408
- // stack.push(stream[i]);
409
- // scopes.push((currentScope = new Set()));
410
- // }
411
- // break;
412
252
  }
413
253
  if (!success) {
414
254
  break;
415
255
  }
416
256
  }
417
- // if (success && stack.length > 0) {
418
- // success = false;
419
- // errors.push({
420
- // action: "drop",
421
- // node: stack.at(-1),
422
- // message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
423
- // });
424
- // }
425
257
  if (!success) {
426
258
  return {
427
259
  success,
@@ -429,17 +261,18 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
429
261
  };
430
262
  }
431
263
  stream.length = 0;
432
- stream.push(...trimArray(tokens));
264
+ for (const token of trimArray(tokens)) {
265
+ stream.push(token);
266
+ }
433
267
  }
434
268
  }
435
269
  stream.length = 0;
436
270
  stream.push(...parts
437
271
  .filter((p) => p.length > 0 && p[0].typ !== EnumToken.InvalidMediaQueryTokenType)
438
272
  .reduce((acc, b) => {
439
- // if (acc.length > 0) {
440
- // acc.push({ typ: EnumToken.CommaTokenType });
441
- // }
442
- acc.push(...b);
273
+ for (const token of b) {
274
+ acc.push(token);
275
+ }
443
276
  return acc;
444
277
  }, []));
445
278
  return {
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
2
+ import { tokensfuncDefMap, LOCSTA } from '../../syntax/constants.js';
3
3
  import { equalsIgnoreCase } from './text.js';
4
4
 
5
5
  function matchGenericSyntax(stream, options) {
@@ -28,7 +28,7 @@ function matchGenericSyntax(stream, options) {
28
28
  action: "drop",
29
29
  message: `unexpected token ${EnumToken[token.typ]}`,
30
30
  node: token,
31
- location: options.source.getSourceLocation(token[LOC].sta),
31
+ location: options.source.getSourceLocation(token[LOCSTA]),
32
32
  });
33
33
  success = false;
34
34
  break;
@@ -43,7 +43,7 @@ function matchGenericSyntax(stream, options) {
43
43
  action: "drop",
44
44
  message: `unexpected token ${EnumToken[token.typ]}`,
45
45
  node: token,
46
- location: options.source.getSourceLocation(token[LOC].sta),
46
+ location: options.source.getSourceLocation(token[LOCSTA]),
47
47
  });
48
48
  success = false;
49
49
  break;
@@ -59,7 +59,7 @@ function matchGenericSyntax(stream, options) {
59
59
  action: "drop",
60
60
  message: `unexpected token ${EnumToken[token.typ]}`,
61
61
  node: token,
62
- location: options.source.getSourceLocation(token[LOC].sta),
62
+ location: options.source.getSourceLocation(token[LOCSTA]),
63
63
  });
64
64
  success = false;
65
65
  break;
@@ -75,7 +75,7 @@ function matchGenericSyntax(stream, options) {
75
75
  action: "drop",
76
76
  message: `unexpected token ${EnumToken[token.typ]}`,
77
77
  node: token,
78
- location: options.source.getSourceLocation(token[LOC].sta),
78
+ location: options.source.getSourceLocation(token[LOCSTA]),
79
79
  });
80
80
  success = false;
81
81
  break;
@@ -95,8 +95,7 @@ function matchGenericSyntax(stream, options) {
95
95
  action: "drop",
96
96
  message: `unexpected token ${EnumToken[stack.at(-1)?.typ]}`,
97
97
  node: stack.at(-1),
98
- // @ts-expect-error
99
- location: options.source.getSourceLocation(stack.at(-1)?.[LOC].sta),
98
+ location: options.source.getSourceLocation(stack.at(-1)?.[LOCSTA]),
100
99
  });
101
100
  success = false;
102
101
  }
@@ -2,7 +2,7 @@ import { EnumToken } from '../../ast/types.js';
2
2
  import { getSyntaxRule } from '../../validation/config.js';
3
3
  import { trimArray } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
- import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
5
+ import { tokensfuncDefMap, LOCEND, LOCSTA } from '../../syntax/constants.js';
6
6
  import { parseMediaqueryList } from './at-rule-media.js';
7
7
  import { parseAtRuleSupportSyntax } from './at-rule-support.js';
8
8
 
@@ -38,11 +38,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
38
38
  }
39
39
  }
40
40
  const slice = stream.slice(index + 1, k);
41
- // @ts-expect-error
42
- stream[0][LOC] = {
43
- ...stream[0][LOC],
44
- end: stream[1][LOC].end,
45
- };
41
+ stream[0][LOCEND] = stream[1][LOCEND];
46
42
  tokens.push(Object.assign({
47
43
  typ: tokensfuncDefMap.get(stream[0].typ),
48
44
  chi: trimArray(slice),
@@ -58,7 +54,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
58
54
  message: "Expected string or url()",
59
55
  syntax: "@import",
60
56
  node: stream[0],
61
- location: stream[0]?.[LOC],
57
+ location: options.source.getSourceLocation(stream[0]?.[LOCSTA]),
62
58
  },
63
59
  ],
64
60
  };
@@ -88,7 +84,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
88
84
  message: `Expected <layer-name>`,
89
85
  syntax: "@import",
90
86
  node: stream[index],
91
- location: options.source.getSourceLocation(stream[index]?.[LOC].sta),
87
+ location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
92
88
  },
93
89
  ],
94
90
  };
@@ -115,7 +111,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
115
111
  message: `Expected <layer-name>`,
116
112
  syntax: "@import",
117
113
  node: stream[index],
118
- location: options.source.getSourceLocation(stream[index]?.[LOC].sta),
114
+ location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
119
115
  },
120
116
  ],
121
117
  };
@@ -157,7 +153,9 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
157
153
  {
158
154
  const result = parseAtRuleSupportSyntax(tokens[tokens.length - 1].chi, context, options);
159
155
  if (!result.success && result.errors.length > 0) {
160
- errors.push(...result.errors);
156
+ for (const error of result.errors) {
157
+ errors.push(error);
158
+ }
161
159
  return {
162
160
  success: false,
163
161
  errors,
@@ -167,15 +165,21 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
167
165
  }
168
166
  const splice = stream.splice(index, stream.length - index);
169
167
  const sliced = parseMediaqueryList(splice, options);
170
- tokens.push(...splice);
168
+ for (const sp of splice) {
169
+ tokens.push(sp);
170
+ }
171
171
  if (sliced.errors.length > 0) {
172
- errors.push(...sliced.errors);
172
+ for (const error of sliced.errors) {
173
+ errors.push(error);
174
+ }
173
175
  }
174
176
  if (!sliced.success) {
175
177
  success = false;
176
178
  }
177
179
  stream.length = 0;
178
- stream.push(...trimArray(tokens));
180
+ for (const token of trimArray(tokens)) {
181
+ stream.push(token);
182
+ }
179
183
  return {
180
184
  success,
181
185
  errors,