@tbela99/css-parser 1.4.5 → 1.4.7

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 (47) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/README.md +2 -0
  3. package/dist/index-umd-web.js +6546 -6987
  4. package/dist/index.cjs +7784 -8223
  5. package/dist/index.d.ts +919 -51
  6. package/dist/lib/ast/clone.js +16 -23
  7. package/dist/lib/ast/expand.js +2 -2
  8. package/dist/lib/ast/features/if.js +88 -87
  9. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  10. package/dist/lib/ast/features/prefix.js +26 -22
  11. package/dist/lib/ast/features/transform.js +3 -3
  12. package/dist/lib/ast/find.js +17 -14
  13. package/dist/lib/ast/minify.js +97 -94
  14. package/dist/lib/ast/types.js +6 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +46 -44
  17. package/dist/lib/parser/declaration/list.js +9 -10
  18. package/dist/lib/parser/declaration/map.js +13 -18
  19. package/dist/lib/parser/parse.js +331 -506
  20. package/dist/lib/parser/tokenize.js +39 -33
  21. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  22. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  23. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  24. package/dist/lib/parser/utils/at-rule-media.js +286 -286
  25. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  26. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  27. package/dist/lib/parser/utils/at-rule.js +19 -16
  28. package/dist/lib/parser/utils/cache.js +33 -5
  29. package/dist/lib/parser/utils/declaration.js +260 -322
  30. package/dist/lib/parser/utils/hash.js +15 -15
  31. package/dist/lib/parser/utils/selector.js +182 -222
  32. package/dist/lib/parser/utils/token.js +4 -7
  33. package/dist/lib/renderer/render.js +150 -120
  34. package/dist/lib/syntax/color/alpha.js +1 -4
  35. package/dist/lib/syntax/color/color.js +5 -5
  36. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  37. package/dist/lib/syntax/color/utils/components.js +21 -22
  38. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  39. package/dist/lib/syntax/constants.js +22 -3
  40. package/dist/lib/syntax/syntax.js +252 -311
  41. package/dist/lib/validation/config.js +16 -17
  42. package/dist/lib/validation/match.js +1118 -1131
  43. package/dist/lib/validation/parser/parse.js +130 -286
  44. package/dist/node.js +16 -12
  45. package/dist/web.js +10 -8
  46. package/package.json +4 -4
  47. package/dist/lib/validation/utils/whitespace.js +0 -17
@@ -1,10 +1,8 @@
1
1
  import { getParsedSyntax, getSyntaxConfig } from './config.js';
2
- import { EnumToken, ColorType } from '../ast/types.js';
2
+ import { EnumToken } from '../ast/types.js';
3
3
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
4
- import { tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
5
- import { pseudoElements, isValue, isColor } from '../syntax/syntax.js';
6
- import { isDeclarationValue } from '../parser/utils/declaration.js';
7
- import { renderSyntax } from './parser/parse.js';
4
+ import { LOC, tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
5
+ import { isColor } from '../syntax/syntax.js';
8
6
  import { equalsIgnoreCase } from '../parser/utils/text.js';
9
7
  import { cloneNode } from '../ast/clone.js';
10
8
  import { parseTokens } from '../parser/parse.js';
@@ -26,9 +24,6 @@ function trimArray(tokens) {
26
24
  }
27
25
  return tokens;
28
26
  }
29
- function isMFName(featureName) {
30
- return featureName.startsWith("--") || featureName.toLowerCase() in config.mediaFeatures;
31
- }
32
27
  /**
33
28
  *
34
29
  * @param featureName
@@ -36,7 +31,7 @@ function isMFName(featureName) {
36
31
  */
37
32
  function getMFInfo(featureName) {
38
33
  // @ts-expect-error
39
- return config.mediaFeatures[featureName.toLowerCase()] ?? null;
34
+ return config.mediaFeatures[featureName.toLowerCase()];
40
35
  }
41
36
  /**
42
37
  *
@@ -49,9 +44,9 @@ function getMFInfo(featureName) {
49
44
  function isMFValue(featureName, tokens, isMFRange) {
50
45
  // mf-value: <number> | <dimension> | <ident> | <ratio>
51
46
  tokens = tokens.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
52
- if (tokens.length === 0) {
53
- return { valid: true, success: false };
54
- }
47
+ // if (tokens.length === 0) {
48
+ // return { valid: true, success: false };
49
+ // }
55
50
  // https://www.w3.org/TR/mediaqueries-5/#:~:text=Attempting%20to%20evaluate%20a%20min%2Fmax%20prefixed
56
51
  // https://www.w3.org/TR/mediaqueries-5/#custom-mq
57
52
  if (featureName.startsWith("--") || (isMFRange && /^((min)|(max))-/g.test(featureName))) {
@@ -63,16 +58,19 @@ function isMFValue(featureName, tokens, isMFRange) {
63
58
  }
64
59
  // @ts-expect-error
65
60
  const mediaFeature = config.mediaFeatures[featureName];
66
- if (tokens.length === 1 &&
67
- tokens[0].typ === EnumToken.MathFunctionTokenType &&
68
- tokens[0].val === "calc") {
69
- // todo: check calc tokens are of compatible types : resolution, ratio, length, integer, number?
70
- // https://github.com/web-platform-tests/wpt/blob/master/css/mediaqueries/mq-calc-sign-function-003.html
71
- return {
72
- valid: true,
73
- success: mediaFeature.type !== MediaFeatureType.KeywordType && mediaFeature.type !== MediaFeatureType.StringType,
74
- };
75
- }
61
+ // if (
62
+ // tokens.length === 1 &&
63
+ // tokens[0].typ === EnumToken.MathFunctionTokenType &&
64
+ // (tokens[0] as FunctionToken).val === "calc"
65
+ // ) {
66
+ // // todo: check calc tokens are of compatible types : resolution, ratio, length, integer, number?
67
+ // // https://github.com/web-platform-tests/wpt/blob/master/css/mediaqueries/mq-calc-sign-function-003.html
68
+ // return {
69
+ // valid: true,
70
+ // success:
71
+ // mediaFeature.type !== MediaFeatureType.KeywordType && mediaFeature.type !== MediaFeatureType.StringType,
72
+ // };
73
+ // }
76
74
  switch (mediaFeature.type) {
77
75
  case MediaFeatureType.BooleanType:
78
76
  return {
@@ -130,14 +128,16 @@ function isMFValue(featureName, tokens, isMFRange) {
130
128
  success: true,
131
129
  };
132
130
  }
133
- function isStyleRangeValue(tokens) {
134
- const filtered = tokens.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
135
- const result = isDeclarationValue(tokens);
136
- if (result.success) {
137
- result.success = filtered.length > 0;
138
- }
139
- return result;
140
- }
131
+ // export function isStyleRangeValue(tokens: Token[]): { success: boolean; errors: ErrorDescription[] } {
132
+ // const filtered: Token[] = tokens.filter(
133
+ // (token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType,
134
+ // );
135
+ // const result = isDeclarationValue(tokens);
136
+ // if (result.success) {
137
+ // result.success = filtered.length > 0;
138
+ // }
139
+ // return result;
140
+ // }
141
141
  function createValidationContext(tokens) {
142
142
  tokens = trimArray(tokens.filter((t) => t.typ !== EnumToken.CommentTokenType));
143
143
  if (tokens.at(-1)?.typ === EnumToken.ImportantTokenType) {
@@ -151,29 +151,31 @@ function createValidationContext(tokens) {
151
151
  if (this.index < 0) {
152
152
  return null;
153
153
  }
154
- while (this.tokens[this.index]?.typ == EnumToken.WhitespaceTokenType ||
155
- this.tokens[this.index]?.typ == EnumToken.CommentTokenType ||
156
- this.tokens[this.index]?.typ == EnumToken.CDOCOMMTokenType) {
157
- this.index++;
158
- }
154
+ // while (
155
+ // this.tokens[this.index]?.typ == EnumToken.WhitespaceTokenType ||
156
+ // this.tokens[this.index]?.typ == EnumToken.CommentTokenType ||
157
+ // this.tokens[this.index]?.typ == EnumToken.CDOCOMMTokenType
158
+ // ) {
159
+ // this.index++;
160
+ // }
159
161
  return this.tokens[this.index];
160
162
  },
161
- peek(offset = 0, skipWhitespace = true) {
163
+ peek(offset = 0) {
162
164
  let index = this.index;
163
165
  let token = this.tokens[++index];
164
- if (!skipWhitespace) {
165
- while (offset >= 0 && index < this.tokens.length) {
166
- while (token != null && token.typ === EnumToken.CommentTokenType) {
167
- token = this.tokens[++index];
168
- }
169
- if (offset === 0 || token == null) {
170
- return token;
171
- }
172
- offset--;
173
- token = this.tokens[++index];
174
- }
175
- return token;
176
- }
166
+ // if (!skipWhitespace) {
167
+ // while (offset >= 0 && index < this.tokens.length) {
168
+ // while (token != null && token.typ === EnumToken.CommentTokenType) {
169
+ // token = this.tokens[++index];
170
+ // }
171
+ // if (offset === 0 || token == null) {
172
+ // return token;
173
+ // }
174
+ // offset--;
175
+ // token = this.tokens[++index];
176
+ // }
177
+ // return token;
178
+ // }
177
179
  while (offset >= 0 && index < this.tokens.length) {
178
180
  while (token?.typ == EnumToken.WhitespaceTokenType ||
179
181
  token?.typ == EnumToken.CommentTokenType ||
@@ -218,17 +220,17 @@ function createValidationContext(tokens) {
218
220
  if (close !== EnumToken.EndParensTokenType && token?.typ === close) {
219
221
  counter--;
220
222
  }
221
- else if (open !== EnumToken.StartParensTokenType && token?.typ === open) {
222
- counter++;
223
- }
223
+ // else if (open !== EnumToken.StartParensTokenType && token?.typ === open) {
224
+ // counter++;
225
+ // }
224
226
  }
225
227
  if (matchCount <= 0 && counter <= 0) {
226
228
  break;
227
229
  }
228
230
  }
229
- if (tokens[0]?.typ === EnumToken.WhitespaceTokenType) {
230
- tokens.shift();
231
- }
231
+ // if (tokens[0]?.typ === EnumToken.WhitespaceTokenType) {
232
+ // tokens.shift();
233
+ // }
232
234
  return tokens;
233
235
  },
234
236
  // 2
@@ -259,22 +261,24 @@ function createValidationContext(tokens) {
259
261
  getRemainingTokens() {
260
262
  return this.tokens.slice(this.index + 1);
261
263
  },
262
- last() {
263
- let index = this.tokens.length - 1;
264
- let token = this.tokens[index];
265
- while ((this.index >= 0 && token?.typ === EnumToken.WhitespaceTokenType) ||
266
- token?.typ === EnumToken.CommentTokenType ||
267
- token?.typ === EnumToken.CDOCOMMTokenType ||
268
- token?.typ === EnumToken.InvalidCommentTokenType ||
269
- token?.typ === EnumToken.BadCommentTokenType ||
270
- token?.typ === EnumToken.BadStringTokenType) {
271
- token = this.tokens[--index];
272
- if (token == null) {
273
- break;
274
- }
275
- }
276
- return token;
277
- },
264
+ // last() {
265
+ // let index: number = this.tokens.length - 1;
266
+ // let token: Token = this.tokens[index];
267
+ // while (
268
+ // (this.index >= 0 && token?.typ === EnumToken.WhitespaceTokenType) ||
269
+ // token?.typ === EnumToken.CommentTokenType ||
270
+ // token?.typ === EnumToken.CDOCOMMTokenType ||
271
+ // token?.typ === EnumToken.InvalidCommentTokenType ||
272
+ // token?.typ === EnumToken.BadCommentTokenType ||
273
+ // token?.typ === EnumToken.BadStringTokenType
274
+ // ) {
275
+ // token = this.tokens[--index];
276
+ // if (token == null) {
277
+ // break;
278
+ // }
279
+ // }
280
+ // return token;
281
+ // },
278
282
  end() {
279
283
  this.index = this.tokens.length + 1;
280
284
  return this;
@@ -361,9 +365,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
361
365
  errors: [
362
366
  {
363
367
  action: "drop",
364
- message: `Unexpected token ${EnumToken[stream[i].typ]} at ${stream[i].loc.src}:${stream[i].loc.sta.lin}:${stream[i].loc.sta.col}`,
368
+ message: `Unexpected token ${EnumToken[stream[i].typ]} at ${stream[i][LOC].src}:${stream[i][LOC].sta.lin}:${stream[i][LOC].sta.col}`,
365
369
  node: stream[i],
366
- location: stream[i].loc,
370
+ location: stream[i][LOC],
367
371
  },
368
372
  ],
369
373
  };
@@ -372,9 +376,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
372
376
  }
373
377
  for (; i < stream.length; i++) {
374
378
  token = stream[i];
375
- if (token.typ === EnumToken.EOF) {
376
- break;
377
- }
379
+ // if (token.typ === EnumToken.EOF) {
380
+ // break;
381
+ // }
378
382
  if (token.typ === EnumToken.Star) {
379
383
  token.typ = EnumToken.UniversalSelectorTokenType;
380
384
  }
@@ -394,24 +398,26 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
394
398
  token.typ !== EnumToken.CDOCOMMTokenType) {
395
399
  stack.pop();
396
400
  }
397
- if (token.typ === EnumToken.LiteralTokenType && "+" === token.val) {
398
- Object.assign(token, { typ: EnumToken.NextSiblingCombinatorTokenType });
399
- continue;
400
- }
401
+ // if (token.typ === EnumToken.LiteralTokenType && "+" === (token as LiteralToken).val) {
402
+ // Object.assign(token, { typ: EnumToken.NextSiblingCombinatorTokenType });
403
+ // continue;
404
+ // }
401
405
  switch (token.typ) {
402
- case EnumToken.InvalidCommentTokenType:
403
- case EnumToken.BadCommentTokenType:
404
- case EnumToken.BadStringTokenType:
405
- break;
406
- case EnumToken.PseudoClassFuncTokenType: {
407
- const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(token.chi), options);
408
- if (!result.success) {
409
- success = false;
410
- if (result.errors.length > 0) {
411
- errors.push(...result.errors);
406
+ // case EnumToken.InvalidCommentTokenType:
407
+ // case EnumToken.BadCommentTokenType:
408
+ // case EnumToken.BadStringTokenType:
409
+ // break;
410
+ case EnumToken.PseudoClassFuncTokenType:
411
+ {
412
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(token.chi), options);
413
+ if (!result.success) {
414
+ success = false;
415
+ if (result.errors.length > 0) {
416
+ errors.push(...result.errors);
417
+ }
412
418
  }
413
419
  }
414
- }
420
+ break;
415
421
  case EnumToken.WhitespaceTokenType:
416
422
  case EnumToken.CommentTokenType:
417
423
  case EnumToken.CDOCOMMTokenType:
@@ -423,9 +429,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
423
429
  errors: [
424
430
  {
425
431
  action: "drop",
426
- message: `Nesting selector is not allowed at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
432
+ message: `Nesting selector is not allowed at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
427
433
  node: token,
428
- location: token.loc,
434
+ location: token[LOC],
429
435
  },
430
436
  ],
431
437
  };
@@ -433,19 +439,21 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
433
439
  break;
434
440
  case EnumToken.Plus:
435
441
  Object.assign(token, { typ: EnumToken.NextSiblingCombinatorTokenType });
436
- if (stack.length > 0 && nodes.includes(stack.at(-1)?.typ)) {
437
- return {
438
- success: false,
439
- errors: [
440
- {
441
- action: "drop",
442
- message: `Unexpected combinator ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
443
- node: token,
444
- location: token.loc,
445
- },
446
- ],
447
- };
448
- }
442
+ // if (stack.length > 0 && nodes.includes(stack.at(-1)?.typ)) {
443
+ // return {
444
+ // success: false,
445
+ // errors: [
446
+ // {
447
+ // action: "drop",
448
+ // message: `Unexpected combinator ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
449
+ // token[LOC]!.sta.col
450
+ // }`,
451
+ // node: token,
452
+ // location: token[LOC],
453
+ // },
454
+ // ],
455
+ // };
456
+ // }
449
457
  stack.push(token);
450
458
  break;
451
459
  case EnumToken.Tilda:
@@ -457,9 +465,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
457
465
  case EnumToken.DescendantCombinatorTokenType:
458
466
  case EnumToken.NextSiblingCombinatorTokenType:
459
467
  case EnumToken.SubsequentSiblingCombinatorTokenType:
460
- if (tokens.at(-1)?.typ === EnumToken.WhitespaceTokenType) {
461
- tokens.pop();
462
- }
468
+ // if (tokens.at(-1)?.typ === EnumToken.WhitespaceTokenType) {
469
+ // tokens.pop();
470
+ // }
463
471
  if (stream[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
464
472
  i++;
465
473
  }
@@ -472,9 +480,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
472
480
  errors: [
473
481
  {
474
482
  action: "drop",
475
- message: `Unexpected combinator ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
483
+ message: `Unexpected combinator ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
476
484
  node: token,
477
- location: token.loc,
485
+ location: token[LOC],
478
486
  },
479
487
  ],
480
488
  };
@@ -485,51 +493,22 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
485
493
  if (stack.length > 0 && stack.at(-1).typ === EnumToken.UniversalSelectorTokenType) {
486
494
  stack.pop();
487
495
  }
488
- if (tokens.length === 0 || stack.at(-1)?.typ == EnumToken.CommaTokenType) {
489
- return {
490
- success: false,
491
- errors: [
492
- {
493
- action: "drop",
494
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
495
- node: token,
496
- location: token.loc,
497
- },
498
- ],
499
- };
500
- }
496
+ // if (tokens.length === 0 || stack.at(-1)?.typ == EnumToken.CommaTokenType) {
497
+ // return {
498
+ // success: false,
499
+ // errors: [
500
+ // {
501
+ // action: "drop",
502
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
503
+ // token[LOC]!.sta.col
504
+ // }`,
505
+ // node: token,
506
+ // location: token[LOC],
507
+ // },
508
+ // ],
509
+ // };
510
+ // }
501
511
  stack.push(token);
502
- if (!nested) {
503
- let k = i + 1;
504
- while (k < stream.length &&
505
- (stream[k].typ === EnumToken.WhitespaceTokenType ||
506
- stream[k].typ === EnumToken.CommentTokenType)) {
507
- k++;
508
- }
509
- // :has(> a, ~b, +c)
510
- if (!tokensfuncDefMap.has(stack.at(-2)?.typ) && k < stream.length) {
511
- switch (stream[k].typ) {
512
- case EnumToken.Plus:
513
- case EnumToken.Tilda:
514
- case EnumToken.GtTokenType:
515
- case EnumToken.ColumnCombinatorTokenType:
516
- case EnumToken.ChildCombinatorTokenType:
517
- case EnumToken.NextSiblingCombinatorTokenType:
518
- case EnumToken.SubsequentSiblingCombinatorTokenType:
519
- return {
520
- success: false,
521
- errors: [
522
- {
523
- action: "drop",
524
- message: `Unexpected token ${EnumToken[stream[k].typ]} at ${stream[k].loc.src}:${stream[k].loc.sta.lin}:${stream[k].loc.sta.col}`,
525
- node: stream[k],
526
- location: stream[k].loc,
527
- },
528
- ],
529
- };
530
- }
531
- }
532
- }
533
512
  break;
534
513
  case EnumToken.Pipe:
535
514
  case EnumToken.DelimTokenType:
@@ -539,21 +518,27 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
539
518
  case EnumToken.StartMatchTokenType:
540
519
  case EnumToken.EndMatchTokenType:
541
520
  case EnumToken.DashMatchTokenType:
542
- if (stack.at(-1)?.typ !== EnumToken.AttrStartTokenType &&
543
- !(stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType &&
544
- stack.at(-2)?.typ === EnumToken.AttrStartTokenType)) {
545
- return {
546
- success: false,
547
- errors: [
548
- {
549
- action: "drop",
550
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
551
- node: token,
552
- location: token.loc,
553
- },
554
- ],
555
- };
556
- }
521
+ // if (
522
+ // stack.at(-1)?.typ !== EnumToken.AttrStartTokenType &&
523
+ // !(
524
+ // stack.at(-1)?.typ === EnumToken.UniversalSelectorTokenType &&
525
+ // stack.at(-2)?.typ === EnumToken.AttrStartTokenType
526
+ // )
527
+ // ) {
528
+ // return {
529
+ // success: false,
530
+ // errors: [
531
+ // {
532
+ // action: "drop",
533
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
534
+ // token[LOC]!.sta.col
535
+ // }`,
536
+ // node: token,
537
+ // location: token[LOC],
538
+ // },
539
+ // ],
540
+ // };
541
+ // }
557
542
  break;
558
543
  // case EnumToken.Star:
559
544
  // Object.assign(token, { typ: EnumToken.UniversalSelectorTokenType });
@@ -563,14 +548,14 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
563
548
  case EnumToken.PseudoElementTokenType:
564
549
  case EnumToken.PseudoClassTokenType:
565
550
  case EnumToken.ClassSelectorTokenType:
566
- if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
567
- stack.pop();
568
- }
551
+ // if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
552
+ // stack.pop();
553
+ // }
569
554
  break;
570
555
  case EnumToken.AttrStartTokenType:
571
- if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
572
- stack.pop();
573
- }
556
+ // if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
557
+ // stack.pop();
558
+ // }
574
559
  stack.push(token);
575
560
  break;
576
561
  case EnumToken.AttrEndTokenType:
@@ -583,9 +568,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
583
568
  errors: [
584
569
  {
585
570
  action: "drop",
586
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
571
+ message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
587
572
  node: token,
588
- location: token.loc,
573
+ location: token[LOC],
589
574
  },
590
575
  ],
591
576
  };
@@ -602,130 +587,150 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
602
587
  }
603
588
  slice.push(tokens[n]);
604
589
  }
605
- if (slice.length === 0) {
606
- return {
607
- success: false,
608
- errors: [
609
- {
610
- action: "drop",
611
- message: `Invalid selector attribute at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
612
- node: token,
613
- location: token.loc,
614
- },
615
- ],
616
- };
617
- }
590
+ // if (slice.length === 0) {
591
+ // return {
592
+ // success: false,
593
+ // errors: [
594
+ // {
595
+ // action: "drop",
596
+ // message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
597
+ // token[LOC]!.sta.col
598
+ // }`,
599
+ // node: token,
600
+ // location: token[LOC],
601
+ // },
602
+ // ],
603
+ // };
604
+ // }
618
605
  if (slice[1]?.typ === EnumToken.Pipe) {
619
- if (slice[0].typ !== EnumToken.UniversalSelectorTokenType &&
620
- slice[0].typ !== EnumToken.Star &&
621
- slice[0].typ !== EnumToken.IdenTokenType) {
622
- return {
623
- success: false,
624
- errors: [
625
- {
626
- action: "drop",
627
- message: `Invalid selector attribute at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
628
- node: token,
629
- location: token.loc,
630
- },
631
- ],
632
- };
633
- }
606
+ // if (
607
+ // slice[0].typ !== EnumToken.UniversalSelectorTokenType &&
608
+ // slice[0].typ !== EnumToken.Star &&
609
+ // slice[0].typ !== EnumToken.IdenTokenType
610
+ // ) {
611
+ // return {
612
+ // success: false,
613
+ // errors: [
614
+ // {
615
+ // action: "drop",
616
+ // message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
617
+ // token[LOC]!.sta.col
618
+ // }`,
619
+ // node: token,
620
+ // location: token[LOC],
621
+ // },
622
+ // ],
623
+ // };
624
+ // }
634
625
  slice.shift();
635
626
  }
636
627
  if (slice[0].typ === EnumToken.Pipe) {
637
- if (slice.length === 1) {
638
- return {
639
- success: false,
640
- errors: [
641
- {
642
- action: "drop",
643
- message: `Invalid selector attribute at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
644
- node: token,
645
- location: token.loc,
646
- },
647
- ],
648
- };
649
- }
650
- if (slice[1]?.typ !== EnumToken.IdenTokenType) {
651
- return {
652
- success: false,
653
- errors: [
654
- {
655
- action: "drop",
656
- message: `Invalid selector attribute at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
657
- node: token,
658
- location: token.loc,
659
- },
660
- ],
661
- };
662
- }
628
+ // if (slice.length === 1) {
629
+ // return {
630
+ // success: false,
631
+ // errors: [
632
+ // {
633
+ // action: "drop",
634
+ // message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
635
+ // token[LOC]!.sta.col
636
+ // }`,
637
+ // node: token,
638
+ // location: token[LOC],
639
+ // },
640
+ // ],
641
+ // };
642
+ // }
643
+ // if (slice[1]?.typ !== EnumToken.IdenTokenType) {
644
+ // return {
645
+ // success: false,
646
+ // errors: [
647
+ // {
648
+ // action: "drop",
649
+ // message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
650
+ // token[LOC]!.sta.col
651
+ // }`,
652
+ // node: token,
653
+ // location: token[LOC],
654
+ // },
655
+ // ],
656
+ // };
657
+ // }
663
658
  slice.shift();
664
659
  }
665
660
  if (slice.length === 1) {
666
- if (slice[0].typ !== EnumToken.IdenTokenType) {
667
- return {
668
- success: false,
669
- errors: [
670
- {
671
- action: "drop",
672
- message: `Invalid selector attribute at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
673
- node: token,
674
- location: token.loc,
675
- },
676
- ],
677
- };
678
- }
661
+ // if (slice[0].typ !== EnumToken.IdenTokenType) {
662
+ // return {
663
+ // success: false,
664
+ // errors: [
665
+ // {
666
+ // action: "drop",
667
+ // message: `Invalid selector attribute at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
668
+ // token[LOC]!.sta.col
669
+ // }`,
670
+ // node: token,
671
+ // location: token[LOC],
672
+ // },
673
+ // ],
674
+ // };
675
+ // }
679
676
  stack.pop();
680
677
  break;
681
678
  }
682
679
  slice.shift();
683
- if (slice[0].typ != EnumToken.DelimTokenType &&
684
- slice[0].typ !== EnumToken.DashMatchTokenType &&
685
- slice[0].typ !== EnumToken.EndMatchTokenType &&
686
- slice[0].typ !== EnumToken.IncludeMatchTokenType &&
687
- slice[0].typ !== EnumToken.StartMatchTokenType &&
688
- slice[0].typ !== EnumToken.ContainMatchTokenType) {
689
- return {
690
- success: false,
691
- errors: [
692
- {
693
- action: "drop",
694
- message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0].loc.src}:${slice[0].loc.sta.lin}:${slice[0].loc.sta.col}`,
695
- node: slice[0],
696
- location: slice[0].loc,
697
- },
698
- ],
699
- };
700
- }
680
+ // if (
681
+ // slice[0].typ != EnumToken.DelimTokenType &&
682
+ // slice[0].typ !== EnumToken.DashMatchTokenType &&
683
+ // slice[0].typ !== EnumToken.EndMatchTokenType &&
684
+ // slice[0].typ !== EnumToken.IncludeMatchTokenType &&
685
+ // slice[0].typ !== EnumToken.StartMatchTokenType &&
686
+ // slice[0].typ !== EnumToken.ContainMatchTokenType
687
+ // ) {
688
+ // return {
689
+ // success: false,
690
+ // errors: [
691
+ // {
692
+ // action: "drop",
693
+ // message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
694
+ // slice[0][LOC]!.sta.col
695
+ // }`,
696
+ // node: slice[0],
697
+ // location: slice[0][LOC],
698
+ // },
699
+ // ],
700
+ // };
701
+ // }
701
702
  slice.shift();
702
- if (slice.length === 0) {
703
- // expect iden or string
704
- return {
705
- success: false,
706
- errors: [
707
- {
708
- action: "drop",
709
- message: `Invalid selector attribute at ${slice[0].loc.src}:${slice[0].loc.sta.lin}:${slice[0].loc.sta.col}`,
710
- node: slice[0],
711
- location: slice[0].loc,
712
- },
713
- ],
714
- };
715
- }
716
- if (slice[0].typ !== EnumToken.IdenTokenType && slice[0].typ !== EnumToken.StringTokenType) {
717
- return {
718
- success: false,
719
- errors: [
720
- {
721
- action: "drop",
722
- message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0].loc.src}:${slice[0].loc.sta.lin}:${slice[0].loc.sta.col}`,
723
- node: slice[0],
724
- location: slice[0].loc,
725
- },
726
- ],
727
- };
728
- }
703
+ // if (slice.length === 0) {
704
+ // // expect iden or string
705
+ // return {
706
+ // success: false,
707
+ // errors: [
708
+ // {
709
+ // action: "drop",
710
+ // message: `Invalid selector attribute at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
711
+ // slice[0][LOC]!.sta.col
712
+ // }`,
713
+ // node: slice[0],
714
+ // location: slice[0][LOC],
715
+ // },
716
+ // ],
717
+ // };
718
+ // }
719
+ // if (slice[0].typ !== EnumToken.IdenTokenType && slice[0].typ !== EnumToken.StringTokenType) {
720
+ // return {
721
+ // success: false,
722
+ // errors: [
723
+ // {
724
+ // action: "drop",
725
+ // message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
726
+ // slice[0][LOC]!.sta.col
727
+ // }`,
728
+ // node: slice[0],
729
+ // location: slice[0][LOC],
730
+ // },
731
+ // ],
732
+ // };
733
+ // }
729
734
  if (slice[0]?.typ === EnumToken.StringTokenType &&
730
735
  /^[a-zA-Z0-9_-]+$/.test(slice[0].val.slice(1, -1))) {
731
736
  Object.assign(slice[0], {
@@ -745,112 +750,122 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
745
750
  errors: [
746
751
  {
747
752
  action: "drop",
748
- message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0].loc.src}:${slice[0].loc.sta.lin}:${slice[0].loc.sta.col}`,
753
+ message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC].src}:${slice[0][LOC].sta.lin}:${slice[0][LOC].sta.col}`,
749
754
  node: slice[0],
750
- location: slice[0].loc,
755
+ location: slice[0][LOC],
751
756
  },
752
757
  ],
753
758
  };
754
759
  }
755
760
  slice.shift();
756
- if (slice.length > 0) {
757
- return {
758
- success: false,
759
- errors: [
760
- {
761
- action: "drop",
762
- message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0].loc.src}:${slice[0].loc.sta.lin}:${slice[0].loc.sta.col}`,
763
- node: slice[0],
764
- location: slice[0].loc,
765
- },
766
- ],
767
- };
768
- }
761
+ // if (slice.length > 0) {
762
+ // return {
763
+ // success: false,
764
+ // errors: [
765
+ // {
766
+ // action: "drop",
767
+ // message: `Unexpected token ${EnumToken[slice[0].typ]} at ${slice[0][LOC]!.src}:${slice[0][LOC]!.sta.lin}:${
768
+ // slice[0][LOC]!.sta.col
769
+ // }`,
770
+ // node: slice[0],
771
+ // location: slice[0][LOC],
772
+ // },
773
+ // ],
774
+ // };
775
+ // }
769
776
  stack.pop();
770
777
  break;
771
778
  }
772
- case EnumToken.ColonTokenType:
773
- if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
774
- Object.assign(token, {
775
- typ: stream[i + 1].val === "page"
776
- ? EnumToken.PseudoPageTokenType
777
- : pseudoElements.includes(token.val)
778
- ? EnumToken.PseudoElementTokenType
779
- : EnumToken.PseudoClassTokenType,
780
- val: ":" + stream[i + 1].val,
781
- });
782
- token.loc.end = stream[++i].loc.end;
783
- break;
784
- }
785
- else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
786
- Object.assign(token, {
787
- typ: EnumToken.PseudoClassFunctionTokenDefType,
788
- val: ":" + stream[i + 1].val,
789
- });
790
- token.loc.end = stream[++i].loc.end;
791
- stack.push(token);
792
- break;
793
- }
794
- return {
795
- success: false,
796
- errors: [
797
- {
798
- action: "drop",
799
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
800
- node: token,
801
- location: token.loc,
802
- },
803
- ],
804
- };
805
- case EnumToken.DoubleColonTokenType:
806
- if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
807
- Object.assign(token, {
808
- typ: stream[i + 1].val === "page"
809
- ? EnumToken.PseudoPageTokenType
810
- : EnumToken.PseudoElementTokenType,
811
- val: "::" + stream[i + 1].val,
812
- });
813
- token.loc.end = stream[++i].loc.end;
814
- break;
815
- }
816
- else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
817
- Object.assign(token, {
818
- typ: EnumToken.PseudoClassFunctionTokenDefType,
819
- val: "::" + stream[i + 1].val,
820
- });
821
- token.loc.end = stream[++i].loc.end;
822
- stack.push(token);
823
- break;
824
- }
825
- return {
826
- success: false,
827
- errors: [
828
- {
829
- action: "drop",
830
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
831
- node: token,
832
- location: token.loc,
833
- },
834
- ],
835
- };
779
+ // case EnumToken.ColonTokenType:
780
+ // if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
781
+ // Object.assign(token, {
782
+ // typ:
783
+ // (stream[i + 1] as IdentToken).val === "page"
784
+ // ? EnumToken.PseudoPageTokenType
785
+ // : pseudoElements.includes((token as PseudoElementToken).val)
786
+ // ? EnumToken.PseudoElementTokenType
787
+ // : EnumToken.PseudoClassTokenType,
788
+ // val: ":" + (stream[i + 1] as IdentToken).val,
789
+ // });
790
+ // token[LOC]!.end = stream[++i][LOC]!.end;
791
+ // break;
792
+ // } else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
793
+ // Object.assign(token, {
794
+ // typ: EnumToken.PseudoClassFunctionTokenDefType,
795
+ // val: ":" + (stream[i + 1] as IdentToken).val,
796
+ // });
797
+ // token[LOC]!.end = stream[++i][LOC]!.end;
798
+ // stack.push(token);
799
+ // break;
800
+ // }
801
+ // return {
802
+ // success: false,
803
+ // errors: [
804
+ // {
805
+ // action: "drop",
806
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
807
+ // token[LOC]!.sta.col
808
+ // }`,
809
+ // node: token,
810
+ // location: token[LOC],
811
+ // },
812
+ // ],
813
+ // };
814
+ // case EnumToken.DoubleColonTokenType:
815
+ // if (stream[i + 1]?.typ === EnumToken.IdenTokenType) {
816
+ // Object.assign(token, {
817
+ // typ:
818
+ // (stream[i + 1] as IdentToken).val === "page"
819
+ // ? EnumToken.PseudoPageTokenType
820
+ // : EnumToken.PseudoElementTokenType,
821
+ // val: "::" + (stream[i + 1] as IdentToken).val,
822
+ // });
823
+ // token[LOC]!.end = stream[++i][LOC]!.end;
824
+ // break;
825
+ // } else if (stream[i + 1]?.typ === EnumToken.FunctionTokenDefType) {
826
+ // Object.assign(token, {
827
+ // typ: EnumToken.PseudoClassFunctionTokenDefType,
828
+ // val: "::" + (stream[i + 1] as IdentToken).val,
829
+ // });
830
+ // token[LOC]!.end = stream[++i][LOC]!.end;
831
+ // stack.push(token);
832
+ // break;
833
+ // }
834
+ // return {
835
+ // success: false,
836
+ // errors: [
837
+ // {
838
+ // action: "drop",
839
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${
840
+ // token[LOC]!.sta.col
841
+ // }`,
842
+ // node: token,
843
+ // location: token[LOC],
844
+ // },
845
+ // ],
846
+ // };
836
847
  case EnumToken.StartParensTokenType:
837
- if (tokens.at(-2)?.typ === EnumToken.PseudoClassTokenType ||
838
- tokens.at(-2)?.typ === EnumToken.PseudoElementTokenType) {
839
- stack.push(Object.assign(tokens.at(-2), {
840
- typ: EnumToken.PseudoClassFunctionTokenDefType,
841
- chi: [],
842
- }));
843
- // tokens.pop();
844
- break;
845
- }
848
+ // if (
849
+ // tokens.at(-2)?.typ === EnumToken.PseudoClassTokenType ||
850
+ // tokens.at(-2)?.typ === EnumToken.PseudoElementTokenType
851
+ // ) {
852
+ // stack.push(
853
+ // Object.assign(tokens.at(-2) as Token, {
854
+ // typ: EnumToken.PseudoClassFunctionTokenDefType,
855
+ // chi: [],
856
+ // }),
857
+ // );
858
+ // // tokens.pop();
859
+ // break;
860
+ // }
846
861
  return {
847
862
  success: false,
848
863
  errors: [
849
864
  {
850
865
  action: "drop",
851
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
866
+ message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
852
867
  node: token,
853
- location: token.loc,
868
+ location: token[LOC],
854
869
  },
855
870
  ],
856
871
  };
@@ -861,19 +876,19 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
861
876
  if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType ||
862
877
  stack.at(-1)?.typ === EnumToken.PseudoElementTokenType) {
863
878
  const token = stack.at(-1);
864
- if (!(stack.at(-1).val + "()" in config.selectors)) {
865
- return {
866
- errors: [
867
- {
868
- action: "drop",
869
- message: `Unknown class element ${token.val}`,
870
- node: token,
871
- location: token.loc,
872
- },
873
- ],
874
- success: false,
875
- };
876
- }
879
+ // if (!((stack.at(-1) as PseudoClassFunctionToken).val + "()" in config.selectors)) {
880
+ // return {
881
+ // errors: [
882
+ // {
883
+ // action: "drop",
884
+ // message: `Unknown class element ${(token as PseudoElementToken).val}`,
885
+ // node: token,
886
+ // location: token[LOC]!,
887
+ // },
888
+ // ],
889
+ // success: false,
890
+ // };
891
+ // }
877
892
  const index = tokens.indexOf(token);
878
893
  const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(tokens.slice(index + 1, tokens.length - 1)), options);
879
894
  if (!result.success) {
@@ -890,18 +905,18 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
890
905
  errors: [
891
906
  {
892
907
  action: "drop",
893
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
908
+ message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
894
909
  node: token,
895
- location: token.loc,
910
+ location: token[LOC],
896
911
  },
897
912
  ],
898
913
  };
899
914
  case EnumToken.NumberTokenType:
900
915
  case EnumToken.LiteralTokenType:
901
916
  case EnumToken.DimensionTokenType:
902
- if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
903
- stack.pop();
904
- }
917
+ // if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
918
+ // stack.pop();
919
+ // }
905
920
  if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType) {
906
921
  break;
907
922
  }
@@ -911,9 +926,9 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
911
926
  errors: [
912
927
  {
913
928
  action: "drop",
914
- message: `Unsupported selector token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
929
+ message: `Unsupported selector token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
915
930
  node: token,
916
- location: token.loc,
931
+ location: token[LOC],
917
932
  },
918
933
  ],
919
934
  };
@@ -936,23 +951,23 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
936
951
  errors: [
937
952
  {
938
953
  action: "drop",
939
- 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}`,
954
+ 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}`,
940
955
  node: stack.at(-1),
941
- location: stack.at(-1).loc,
956
+ location: stack.at(-1)[LOC],
942
957
  },
943
958
  ],
944
959
  };
945
960
  }
946
961
  stream.length = 0;
947
962
  stream.push(...tokens);
948
- if (!success && errors.length === 0) {
949
- errors.push({
950
- action: "drop",
951
- message: "Invalid selector",
952
- node: tokens[0],
953
- location: tokens[0].loc,
954
- });
955
- }
963
+ // if (!success && errors.length === 0) {
964
+ // errors.push({
965
+ // action: "drop",
966
+ // message: "Invalid selector",
967
+ // node: tokens[0],
968
+ // location: tokens[0][LOC]!,
969
+ // });
970
+ // }
956
971
  return { success, errors };
957
972
  }
958
973
  function matchAllSyntaxes(syntaxes, context, options) {
@@ -960,25 +975,28 @@ function matchAllSyntaxes(syntaxes, context, options) {
960
975
  ...options,
961
976
  visited: new Map(),
962
977
  });
963
- if (result.success && !result.context.done()) {
964
- const node = result.context.peek();
965
- return {
966
- ...result,
967
- success: false,
968
- token: context.peek(),
969
- errors: [
970
- ...result.errors,
971
- {
972
- action: "drop",
973
- message: `Unexpected token ${EnumToken[node?.typ]} at ${node.loc?.src}:${node.loc?.sta?.lin}:${node.loc?.sta?.col}`,
974
- node,
975
- syntax: result.syntaxToken ??
976
- syntaxes?.reduce?.((acc, b) => acc + renderSyntax(b), "")?.trim?.() ??
977
- null,
978
- },
979
- ],
980
- };
981
- }
978
+ // if (result.success && !result.context.done()) {
979
+ // const node = result.context.peek() as Token;
980
+ // return {
981
+ // ...result,
982
+ // success: false,
983
+ // token: context.peek(),
984
+ // errors: [
985
+ // ...result.errors,
986
+ // {
987
+ // action: "drop",
988
+ // message: `Unexpected token ${EnumToken[node?.typ]} at ${node![LOC]?.src}:${node![LOC]?.sta?.lin}:${
989
+ // node![LOC]?.sta?.col
990
+ // }`,
991
+ // node,
992
+ // syntax:
993
+ // result.syntaxToken ??
994
+ // syntaxes?.reduce?.((acc, b) => acc + renderSyntax(b), "")?.trim?.() ??
995
+ // null,
996
+ // },
997
+ // ],
998
+ // };
999
+ // }
982
1000
  if (syntaxes != null && result.success && result.syntaxToken != null) {
983
1001
  const index = syntaxes.indexOf(result.syntaxToken);
984
1002
  if (index != -1) {
@@ -988,9 +1006,9 @@ function matchAllSyntaxes(syntaxes, context, options) {
988
1006
  syntaxes[i].isRepeatable) {
989
1007
  continue;
990
1008
  }
991
- if (syntaxes[i].typ == ValidationTokenEnum.SemiColon && i === syntaxes.length - 1) {
992
- continue;
993
- }
1009
+ // if (syntaxes[i].typ == ValidationTokenEnum.SemiColon && i === syntaxes.length - 1) {
1010
+ // continue;
1011
+ // }
994
1012
  return {
995
1013
  ...result,
996
1014
  success: false,
@@ -1008,7 +1026,7 @@ function matchAllSyntaxes(syntaxes, context, options) {
1008
1026
  message: result.errors[0]?.message || "could not match syntax",
1009
1027
  node: result.token,
1010
1028
  syntax: result.syntaxToken,
1011
- location: result.token?.loc ?? context.tokens.at(-1)?.loc,
1029
+ location: result.token?.[LOC] ?? context.tokens.at(-1)?.[LOC],
1012
1030
  },
1013
1031
  ]
1014
1032
  : result.errors,
@@ -1043,22 +1061,22 @@ function matchListSyntax(syntax, context, options) {
1043
1061
  }
1044
1062
  }
1045
1063
  } while (tmpResult.success && !context.done());
1046
- if (result?.success && match != null) {
1047
- if (count < match.min.val || (Number.isFinite(match.max) && count > match.max.val)) {
1048
- return {
1049
- ...result,
1050
- success: false,
1051
- errors: [
1052
- {
1053
- action: "drop",
1054
- message: "could not match syntax",
1055
- node: context.peek(),
1056
- location: context.peek()?.loc,
1057
- },
1058
- ],
1059
- };
1060
- }
1061
- }
1064
+ // if (result?.success && match != null) {
1065
+ // if (count < match.min!.val || (Number.isFinite(match.max) && count > (match.max!.val as number))) {
1066
+ // return {
1067
+ // ...result,
1068
+ // success: false,
1069
+ // errors: [
1070
+ // {
1071
+ // action: "drop",
1072
+ // message: "could not match syntax",
1073
+ // node: context.peek(),
1074
+ // location: context.peek()?.[LOC]!,
1075
+ // },
1076
+ // ],
1077
+ // };
1078
+ // }
1079
+ // }
1062
1080
  return result == null
1063
1081
  ? {
1064
1082
  success: false,
@@ -1095,8 +1113,9 @@ function matchOccurenceSyntax(syntax, context, options) {
1095
1113
  }
1096
1114
  }
1097
1115
  } while (tmpResult.success && !context.done());
1098
- if (match != null &&
1099
- (count < match.min.val || (Number.isFinite(match.max?.val) && count > match.max.val))) {
1116
+ if (result == null ||
1117
+ (match != null &&
1118
+ (count < match.min.val || (Number.isFinite(match.max?.val) && count > match.max.val)))) {
1100
1119
  return {
1101
1120
  success: false,
1102
1121
  errors: [
@@ -1104,7 +1123,7 @@ function matchOccurenceSyntax(syntax, context, options) {
1104
1123
  action: "drop",
1105
1124
  message: "could not match syntax",
1106
1125
  node: context.peek(),
1107
- location: context.peek()?.loc,
1126
+ location: context.peek()?.[LOC],
1108
1127
  },
1109
1128
  ],
1110
1129
  syntaxToken: null,
@@ -1113,21 +1132,7 @@ function matchOccurenceSyntax(syntax, context, options) {
1113
1132
  token: null,
1114
1133
  };
1115
1134
  }
1116
- return (result ?? {
1117
- success: false,
1118
- errors: [
1119
- {
1120
- action: "drop",
1121
- message: "could not match syntax",
1122
- node: context.peek(),
1123
- location: context.peek().loc,
1124
- },
1125
- ],
1126
- syntaxToken: syntax,
1127
- valid: true,
1128
- context,
1129
- token: context.peek(),
1130
- });
1135
+ return result;
1131
1136
  }
1132
1137
  function matchSyntax(syntaxes, context, options) {
1133
1138
  if (syntaxes == null) {
@@ -1191,24 +1196,24 @@ function matchSyntax(syntaxes, context, options) {
1191
1196
  }
1192
1197
  if (token.typ === EnumToken.WildCardFunctionTokenType && token.val === "var") {
1193
1198
  result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(token.chi), options);
1194
- if ((result.success && result.context.done()) || isOptional) {
1199
+ if (result.success && result.context.done()) {
1195
1200
  context.next();
1196
1201
  continue;
1197
1202
  }
1198
- return {
1199
- ...result,
1200
- success: false,
1201
- token,
1202
- syntaxToken: syntaxes[i],
1203
- errors: [
1204
- {
1205
- action: "drop",
1206
- message: "could not match syntax",
1207
- node: context.peek(),
1208
- location: context.peek().loc,
1209
- },
1210
- ],
1211
- };
1203
+ // return {
1204
+ // ...result,
1205
+ // success: false,
1206
+ // token,
1207
+ // syntaxToken: syntaxes[i],
1208
+ // errors: [
1209
+ // {
1210
+ // action: "drop",
1211
+ // message: "could not match syntax",
1212
+ // node: context.peek(),
1213
+ // location: context.peek()![LOC]!,
1214
+ // },
1215
+ // ],
1216
+ // };
1212
1217
  }
1213
1218
  // custom function token
1214
1219
  if (token.typ === EnumToken.CustomFunctionTokenDefType) {
@@ -1259,10 +1264,10 @@ function matchSyntax(syntaxes, context, options) {
1259
1264
  }
1260
1265
  continue;
1261
1266
  }
1262
- if (isOptional) {
1263
- continue;
1264
- }
1265
- return result;
1267
+ // if (isOptional) {
1268
+ // continue;
1269
+ // }
1270
+ // return result;
1266
1271
  }
1267
1272
  if (syntaxes[i].isRepeatableAtLeastOnce || syntaxes[i].isRepeatable) {
1268
1273
  result = matchRepeatableSyntax(syntaxes[i], context.slice(), options);
@@ -1274,9 +1279,9 @@ function matchSyntax(syntaxes, context, options) {
1274
1279
  context.update(result.context.current());
1275
1280
  continue;
1276
1281
  }
1277
- if (isOptional) {
1278
- continue;
1279
- }
1282
+ // if (isOptional) {
1283
+ // continue;
1284
+ // }
1280
1285
  return result;
1281
1286
  }
1282
1287
  if (syntaxes[i].isList) {
@@ -1295,25 +1300,27 @@ function matchSyntax(syntaxes, context, options) {
1295
1300
  };
1296
1301
  }
1297
1302
  context.update(result.context.current());
1298
- let k = i + 1;
1299
- for (; k < syntaxes.length; k++) {
1300
- if (syntaxes[k].typ !== ValidationTokenEnum.Whitespace) {
1301
- break;
1302
- }
1303
- if (syntaxes[k]?.typ === ValidationTokenEnum.Comma) {
1304
- i = k;
1305
- }
1306
- }
1307
- continue;
1308
- }
1309
- if (isOptional) {
1310
- // eat the next ','
1311
- if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace ||
1312
- syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma) {
1313
- i++;
1314
- }
1303
+ // let k = i + 1;
1304
+ // for (; k < syntaxes.length; k++) {
1305
+ // if (syntaxes[k].typ !== ValidationTokenEnum.Whitespace) {
1306
+ // break;
1307
+ // }
1308
+ // if (syntaxes[k]?.typ === ValidationTokenEnum.Comma) {
1309
+ // i = k;
1310
+ // }
1311
+ // }
1315
1312
  continue;
1316
1313
  }
1314
+ // if (isOptional) {
1315
+ // // eat the next ','
1316
+ // if (
1317
+ // syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace ||
1318
+ // syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma
1319
+ // ) {
1320
+ // i++;
1321
+ // }
1322
+ // continue;
1323
+ // }
1317
1324
  return {
1318
1325
  success: false,
1319
1326
  valid: true,
@@ -1338,16 +1345,16 @@ function matchSyntax(syntaxes, context, options) {
1338
1345
  context.update(result.context.current());
1339
1346
  continue;
1340
1347
  }
1341
- if (isOptional) {
1342
- // eat the next ','
1343
- if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace) {
1344
- i++;
1345
- }
1346
- if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma) {
1347
- i++;
1348
- }
1349
- continue;
1350
- }
1348
+ // if (isOptional) {
1349
+ // // eat the next ','
1350
+ // if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Whitespace) {
1351
+ // i++;
1352
+ // }
1353
+ // if (syntaxes[i + 1]?.typ === ValidationTokenEnum.Comma) {
1354
+ // i++;
1355
+ // }
1356
+ // continue;
1357
+ // }
1351
1358
  return {
1352
1359
  success: false,
1353
1360
  valid: true,
@@ -1379,49 +1386,21 @@ function matchSyntax(syntaxes, context, options) {
1379
1386
  success = true;
1380
1387
  options.visited.get(token).delete(syntaxes[i]);
1381
1388
  context.next();
1382
- if (context.done()) {
1383
- return {
1384
- success: true,
1385
- valid: true,
1386
- token: null,
1387
- context,
1388
- syntaxToken: syntaxes[i + 1],
1389
- errors: [],
1390
- };
1391
- }
1392
- break;
1393
- }
1394
- if (isOptional) {
1395
- break;
1396
- }
1397
- return {
1398
- success: false,
1399
- valid: true,
1400
- token,
1401
- context,
1402
- syntaxToken: syntaxes[i],
1403
- errors: [],
1404
- };
1405
- case ValidationTokenEnum.Colon:
1406
- if (token.typ == EnumToken.ColonTokenType) {
1407
- success = true;
1408
- options.visited.get(token).delete(syntaxes[i]);
1409
- context.next();
1410
- if (context.done()) {
1411
- return {
1412
- success: true,
1413
- valid: true,
1414
- token: null,
1415
- context,
1416
- syntaxToken: syntaxes[i + 1],
1417
- errors: [],
1418
- };
1419
- }
1420
- break;
1421
- }
1422
- if (isOptional) {
1389
+ // if (context.done()) {
1390
+ // return {
1391
+ // success: true,
1392
+ // valid: true,
1393
+ // token: null,
1394
+ // context,
1395
+ // syntaxToken: syntaxes[i + 1],
1396
+ // errors: [],
1397
+ // };
1398
+ // }
1423
1399
  break;
1424
1400
  }
1401
+ // if (isOptional) {
1402
+ // break;
1403
+ // }
1425
1404
  return {
1426
1405
  success: false,
1427
1406
  valid: true,
@@ -1430,6 +1409,34 @@ function matchSyntax(syntaxes, context, options) {
1430
1409
  syntaxToken: syntaxes[i],
1431
1410
  errors: [],
1432
1411
  };
1412
+ // case ValidationTokenEnum.Colon:
1413
+ // if (token.typ == EnumToken.ColonTokenType) {
1414
+ // success = true;
1415
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1416
+ // context.next();
1417
+ // if (context.done()) {
1418
+ // return {
1419
+ // success: true,
1420
+ // valid: true,
1421
+ // token: null,
1422
+ // context,
1423
+ // syntaxToken: syntaxes[i + 1],
1424
+ // errors: [],
1425
+ // };
1426
+ // }
1427
+ // break;
1428
+ // }
1429
+ // if (isOptional) {
1430
+ // break;
1431
+ // }
1432
+ // return {
1433
+ // success: false,
1434
+ // valid: true,
1435
+ // token,
1436
+ // context,
1437
+ // syntaxToken: syntaxes[i],
1438
+ // errors: [],
1439
+ // };
1433
1440
  case ValidationTokenEnum.Keyword:
1434
1441
  if (token.typ == EnumToken.IdenTokenType &&
1435
1442
  token.val.toLowerCase() ===
@@ -1497,40 +1504,38 @@ function matchSyntax(syntaxes, context, options) {
1497
1504
  }
1498
1505
  break;
1499
1506
  }
1500
- case ValidationTokenEnum.AtRule:
1501
- if (token.typ == EnumToken.AtRuleTokenType) {
1502
- success = true;
1503
- options.visited.get(token).delete(syntaxes[i]);
1504
- context.next();
1505
- break;
1506
- }
1507
- if (isOptional) {
1508
- break;
1509
- }
1510
- return {
1511
- success: false,
1512
- valid: true,
1513
- token,
1514
- context,
1515
- syntaxToken: syntaxes[i],
1516
- errors: [],
1517
- };
1507
+ // case ValidationTokenEnum.AtRule:
1508
+ // if (token.typ == EnumToken.AtRuleTokenType) {
1509
+ // success = true;
1510
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1511
+ // context.next();
1512
+ // break;
1513
+ // }
1514
+ // if (isOptional) {
1515
+ // break;
1516
+ // }
1517
+ // return {
1518
+ // success: false,
1519
+ // valid: true,
1520
+ // token,
1521
+ // context,
1522
+ // syntaxToken: syntaxes[i],
1523
+ // errors: [],
1524
+ // };
1518
1525
  case ValidationTokenEnum.StringToken:
1519
- if (token.typ == EnumToken.StringTokenType || token.typ == EnumToken.UrlFunctionTokenType) {
1520
- success = true;
1521
- }
1522
- else if (token.typ === EnumToken.StringTokenType) {
1523
- success = token.val === syntaxes[i].val.slice(1, -1);
1524
- }
1525
- else if (token.typ === EnumToken.Add) {
1526
+ // if (token.typ == EnumToken.StringTokenType || token.typ == EnumToken.UrlFunctionTokenType) {
1527
+ // success = true;
1528
+ // } else if (token.typ === EnumToken.StringTokenType) {
1529
+ // success = (token as StringToken).val === (syntaxes[i] as ValidationStringToken).val.slice(1, -1);
1530
+ // } else
1531
+ if (token.typ === EnumToken.Add) {
1526
1532
  success = syntaxes[i].val.slice(1, -1) === "+";
1527
1533
  }
1528
- else if (token.typ === EnumToken.Mul) {
1529
- success = syntaxes[i].val.slice(1, -1) === "*";
1530
- }
1531
- else if (token.typ === EnumToken.Div) {
1532
- success = syntaxes[i].val.slice(1, -1) === "/";
1533
- }
1534
+ // else if (token.typ === EnumToken.Mul) {
1535
+ // success = (syntaxes[i] as ValidationStringToken).val.slice(1, -1) === "*";
1536
+ // } else if (token.typ === EnumToken.Div) {
1537
+ // success = (syntaxes[i] as ValidationStringToken).val.slice(1, -1) === "/";
1538
+ // }
1534
1539
  else if (token.typ === EnumToken.Sub) {
1535
1540
  success = syntaxes[i].val.slice(1, -1) === "-";
1536
1541
  }
@@ -1555,24 +1560,24 @@ function matchSyntax(syntaxes, context, options) {
1555
1560
  syntaxToken: syntaxes[i],
1556
1561
  errors: [],
1557
1562
  };
1558
- case ValidationTokenEnum.SemiColon:
1559
- if (token.typ == EnumToken.SemiColonTokenType) {
1560
- success = true;
1561
- options.visited.get(token).delete(syntaxes[i]);
1562
- context.next();
1563
- break;
1564
- }
1565
- if (isOptional) {
1566
- break;
1567
- }
1568
- return {
1569
- success: false,
1570
- valid: true,
1571
- token,
1572
- context,
1573
- syntaxToken: syntaxes[i],
1574
- errors: [],
1575
- };
1563
+ // case ValidationTokenEnum.SemiColon:
1564
+ // if (token.typ == EnumToken.SemiColonTokenType) {
1565
+ // success = true;
1566
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1567
+ // context.next();
1568
+ // break;
1569
+ // }
1570
+ // if (isOptional) {
1571
+ // break;
1572
+ // }
1573
+ // return {
1574
+ // success: false,
1575
+ // valid: true,
1576
+ // token,
1577
+ // context,
1578
+ // syntaxToken: syntaxes[i],
1579
+ // errors: [],
1580
+ // };
1576
1581
  case ValidationTokenEnum.PropertyType:
1577
1582
  result = matchProperty(syntaxes[i], context, options);
1578
1583
  if (!result.success) {
@@ -1626,26 +1631,25 @@ function matchSyntax(syntaxes, context, options) {
1626
1631
  if (result?.success) {
1627
1632
  success = true;
1628
1633
  options.visited.get(token).delete(syntaxes[i]);
1629
- if (result.context.done()) {
1630
- context.end();
1631
- return {
1632
- success: true,
1633
- valid: true,
1634
- token: null,
1635
- context,
1636
- syntaxToken: syntaxes[i + 1],
1637
- errors: [],
1638
- };
1639
- }
1640
- else {
1641
- context.update(result.context.current());
1642
- }
1634
+ // if (result!.context.done()) {
1635
+ // context.end();
1636
+ // return {
1637
+ // success: true,
1638
+ // valid: true,
1639
+ // token: null,
1640
+ // context,
1641
+ // syntaxToken: syntaxes[i + 1],
1642
+ // errors: [],
1643
+ // };
1644
+ // } else {
1645
+ context.update(result.context.current());
1646
+ // }
1643
1647
  break;
1644
1648
  }
1645
1649
  }
1646
- if (isOptional) {
1647
- break;
1648
- }
1650
+ // if (isOptional) {
1651
+ // break;
1652
+ // }
1649
1653
  return {
1650
1654
  success: false,
1651
1655
  valid: true,
@@ -1657,7 +1661,7 @@ function matchSyntax(syntaxes, context, options) {
1657
1661
  action: "drop",
1658
1662
  message: "could not match syntax",
1659
1663
  node: token,
1660
- location: token.loc,
1664
+ location: token[LOC],
1661
1665
  syntax: syntaxes[i],
1662
1666
  },
1663
1667
  ],
@@ -1715,9 +1719,9 @@ function matchSyntax(syntaxes, context, options) {
1715
1719
  }
1716
1720
  break;
1717
1721
  }
1718
- if (isOptional) {
1719
- break;
1720
- }
1722
+ // if (isOptional) {
1723
+ // break;
1724
+ // }
1721
1725
  return {
1722
1726
  success: false,
1723
1727
  valid: true,
@@ -1747,9 +1751,9 @@ function matchSyntax(syntaxes, context, options) {
1747
1751
  }
1748
1752
  break;
1749
1753
  }
1750
- if (isOptional) {
1751
- break;
1752
- }
1754
+ // if (isOptional) {
1755
+ // break;
1756
+ // }
1753
1757
  return {
1754
1758
  success: false,
1755
1759
  valid: true,
@@ -1758,38 +1762,47 @@ function matchSyntax(syntaxes, context, options) {
1758
1762
  syntaxToken: syntaxes[i],
1759
1763
  errors: [],
1760
1764
  };
1761
- case ValidationTokenEnum.PseudoClassFunctionToken:
1762
- if (!(token.val + "()" in config.selectors)) {
1763
- return {
1764
- success: false,
1765
- valid: true,
1766
- token,
1767
- context,
1768
- syntaxToken: syntaxes[i],
1769
- errors: [
1770
- {
1771
- action: "drop",
1772
- message: `Unknown pseudo-class selector ${token.val}()`,
1773
- node: token,
1774
- },
1775
- ],
1776
- };
1777
- }
1778
- result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, token.val + "()")?.[0]?.chi ?? [], createValidationContext(token.chi), options);
1779
- if (result.success) {
1780
- success = true;
1781
- options.visited.get(token).delete(syntaxes[i]);
1782
- context.next();
1783
- break;
1784
- }
1785
- return {
1786
- success: false,
1787
- valid: true,
1788
- token,
1789
- context,
1790
- syntaxToken: syntaxes[i],
1791
- errors: result.errors,
1792
- };
1765
+ // case ValidationTokenEnum.PseudoClassFunctionToken:
1766
+ // if (!((token as PseudoClassFunctionToken).val + "()" in config.selectors)) {
1767
+ // return {
1768
+ // success: false,
1769
+ // valid: true,
1770
+ // token,
1771
+ // context,
1772
+ // syntaxToken: syntaxes[i],
1773
+ // errors: [
1774
+ // {
1775
+ // action: "drop",
1776
+ // message: `Unknown pseudo-class selector ${(token as PseudoClassFunctionToken).val}()`,
1777
+ // node: token,
1778
+ // },
1779
+ // ],
1780
+ // };
1781
+ // }
1782
+ // result = matchSyntax(
1783
+ // ((
1784
+ // getParsedSyntax(
1785
+ // ValidationSyntaxGroupEnum.Selectors,
1786
+ // (token as PseudoClassFunctionToken).val + "()",
1787
+ // ) as [ValidationPseudoClassFunctionToken]
1788
+ // )?.[0]?.chi as ValidationToken[]) ?? [],
1789
+ // createValidationContext((token as PseudoClassFunctionToken).chi),
1790
+ // options,
1791
+ // );
1792
+ // if (result.success) {
1793
+ // success = true;
1794
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1795
+ // context.next();
1796
+ // break;
1797
+ // }
1798
+ // return {
1799
+ // success: false,
1800
+ // valid: true,
1801
+ // token,
1802
+ // context,
1803
+ // syntaxToken: syntaxes[i],
1804
+ // errors: result.errors,
1805
+ // };
1793
1806
  case ValidationTokenEnum.Function:
1794
1807
  if ((!tokensfuncDefMap.has(token.typ) &&
1795
1808
  !funcLike.includes(token.typ) &&
@@ -1813,23 +1826,23 @@ function matchSyntax(syntaxes, context, options) {
1813
1826
  }
1814
1827
  if (tokensfuncDefMap.has(token.typ)) {
1815
1828
  const range = context.peekRange();
1816
- if (range.at(-1)?.typ !== EnumToken.EndParensTokenType) {
1817
- const tk = range.at(-1);
1818
- return {
1819
- success: false,
1820
- valid: true,
1821
- token,
1822
- context,
1823
- syntaxToken: syntaxes[i],
1824
- errors: [
1825
- {
1826
- action: "drop",
1827
- message: `Expecting ')' at ${tk.loc?.src}:${tk.loc?.sta?.lin}:${tk.loc?.sta?.col}`,
1828
- node: token,
1829
- },
1830
- ],
1831
- };
1832
- }
1829
+ // if (range.at(-1)?.typ !== EnumToken.EndParensTokenType) {
1830
+ // const tk = range.at(-1) as Token;
1831
+ // return {
1832
+ // success: false,
1833
+ // valid: true,
1834
+ // token,
1835
+ // context,
1836
+ // syntaxToken: syntaxes[i],
1837
+ // errors: [
1838
+ // {
1839
+ // action: "drop",
1840
+ // message: `Expecting ')' at ${tk[LOC]?.src}:${tk[LOC]?.sta?.lin}:${tk[LOC]?.sta?.col}`,
1841
+ // node: token,
1842
+ // },
1843
+ // ],
1844
+ // };
1845
+ // }
1833
1846
  result = matchSyntax(syntaxes[i].chi, createValidationContext(range.slice(1, -1)), options);
1834
1847
  if (result.success && result.context.done()) {
1835
1848
  context.update(range.at(-1));
@@ -1846,9 +1859,9 @@ function matchSyntax(syntaxes, context, options) {
1846
1859
  break;
1847
1860
  }
1848
1861
  }
1849
- if (isOptional) {
1850
- break;
1851
- }
1862
+ // if (isOptional) {
1863
+ // break;
1864
+ // }
1852
1865
  return {
1853
1866
  success: false,
1854
1867
  valid: true,
@@ -1857,20 +1870,20 @@ function matchSyntax(syntaxes, context, options) {
1857
1870
  syntaxToken: syntaxes[i],
1858
1871
  errors: result.errors,
1859
1872
  };
1860
- case ValidationTokenEnum.LessThan:
1861
- if (token.typ === EnumToken.LtTokenType) {
1862
- options.visited.get(token).delete(syntaxes[i]);
1863
- context.next();
1864
- break;
1865
- }
1866
- return {
1867
- success: false,
1868
- valid: true,
1869
- token,
1870
- context,
1871
- syntaxToken: syntaxes[i],
1872
- errors: [],
1873
- };
1873
+ // case ValidationTokenEnum.LessThan:
1874
+ // if (token.typ === EnumToken.LtTokenType) {
1875
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1876
+ // context.next();
1877
+ // break;
1878
+ // }
1879
+ // return {
1880
+ // success: false,
1881
+ // valid: true,
1882
+ // token,
1883
+ // context,
1884
+ // syntaxToken: syntaxes[i],
1885
+ // errors: [],
1886
+ // };
1874
1887
  case ValidationTokenEnum.Separator:
1875
1888
  if (token.typ === EnumToken.LiteralTokenType && token.val === "/") {
1876
1889
  options.visited.get(token).delete(syntaxes[i]);
@@ -1921,9 +1934,9 @@ function matchSyntax(syntaxes, context, options) {
1921
1934
  context.next();
1922
1935
  break;
1923
1936
  }
1924
- if (isOptional) {
1925
- break;
1926
- }
1937
+ // if (isOptional) {
1938
+ // break;
1939
+ // }
1927
1940
  return {
1928
1941
  success: false,
1929
1942
  valid: true,
@@ -1938,9 +1951,9 @@ function matchSyntax(syntaxes, context, options) {
1938
1951
  context.next();
1939
1952
  break;
1940
1953
  }
1941
- if (isOptional) {
1942
- break;
1943
- }
1954
+ // if (isOptional) {
1955
+ // break;
1956
+ // }
1944
1957
  return {
1945
1958
  success: false,
1946
1959
  valid: true,
@@ -1949,47 +1962,53 @@ function matchSyntax(syntaxes, context, options) {
1949
1962
  syntaxToken: syntaxes[i],
1950
1963
  errors: [],
1951
1964
  };
1952
- case ValidationTokenEnum.DeclarationNameToken:
1953
- result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val) ?? [], context.slice(), options);
1954
- if (!result.success) {
1955
- return {
1956
- success: false,
1957
- valid: true,
1958
- token,
1959
- context,
1960
- syntaxToken: syntaxes[i],
1961
- errors: result.errors,
1962
- };
1963
- }
1964
- success = true;
1965
- options.visited.get(token).delete(syntaxes[i]);
1966
- if (result.context.done()) {
1967
- context.end();
1968
- return {
1969
- success,
1970
- valid: true,
1971
- token: null,
1972
- context,
1973
- syntaxToken: syntaxes[1 + i],
1974
- errors: [],
1975
- };
1976
- }
1977
- else {
1978
- context.update(result.context.current());
1979
- }
1980
- break;
1981
- case ValidationTokenEnum.DisallowWhitespace:
1982
- if (context.peek(0, false)?.typ === EnumToken.WhitespaceTokenType) {
1983
- return {
1984
- success: false,
1985
- valid: true,
1986
- token,
1987
- context,
1988
- syntaxToken: syntaxes[i],
1989
- errors: [],
1990
- };
1991
- }
1992
- break;
1965
+ // case ValidationTokenEnum.DeclarationNameToken:
1966
+ // result = matchSyntax(
1967
+ // (getParsedSyntax(
1968
+ // ValidationSyntaxGroupEnum.Declarations,
1969
+ // (syntaxes[i] as ValidationDeclarationToken).val,
1970
+ // ) as ValidationFunctionToken[] as ValidationToken[]) ?? [],
1971
+ // context.slice(),
1972
+ // options,
1973
+ // );
1974
+ // if (!result.success) {
1975
+ // return {
1976
+ // success: false,
1977
+ // valid: true,
1978
+ // token,
1979
+ // context,
1980
+ // syntaxToken: syntaxes[i],
1981
+ // errors: result.errors,
1982
+ // };
1983
+ // }
1984
+ // success = true;
1985
+ // (options.visited!.get(token) as Set<ValidationToken>)!.delete(syntaxes[i]);
1986
+ // if (result.context.done()) {
1987
+ // context.end();
1988
+ // return {
1989
+ // success,
1990
+ // valid: true,
1991
+ // token: null,
1992
+ // context,
1993
+ // syntaxToken: syntaxes[1 + i],
1994
+ // errors: [],
1995
+ // };
1996
+ // } else {
1997
+ // context.update(result.context.current() as Token);
1998
+ // }
1999
+ // break;
2000
+ // case ValidationTokenEnum.DisallowWhitespace:
2001
+ // if (context.peek(0, false)?.typ === EnumToken.WhitespaceTokenType) {
2002
+ // return {
2003
+ // success: false,
2004
+ // valid: true,
2005
+ // token,
2006
+ // context,
2007
+ // syntaxToken: syntaxes[i],
2008
+ // errors: [],
2009
+ // };
2010
+ // }
2011
+ // break;
1993
2012
  default:
1994
2013
  throw new Error(`Unexpected syntax ${ValidationTokenEnum[syntaxes[i].typ]}`);
1995
2014
  }
@@ -2080,11 +2099,9 @@ function matchAmpersandSyntax(syntax, context, options) {
2080
2099
  const syntaxes = [syntax.l, syntax.r];
2081
2100
  let result;
2082
2101
  let i;
2083
- let success = false;
2084
2102
  for (i = 0; i < syntaxes.length; i++) {
2085
2103
  result = matchSyntax(syntaxes[i], context.slice(), options);
2086
2104
  if (result.success) {
2087
- success = true;
2088
2105
  if (result.context.done()) {
2089
2106
  context.end();
2090
2107
  break;
@@ -2094,15 +2111,7 @@ function matchAmpersandSyntax(syntax, context, options) {
2094
2111
  i = -1;
2095
2112
  }
2096
2113
  }
2097
- return (
2098
- /* syntaxes.length === 0 ? */ result ?? {
2099
- success,
2100
- valid: true,
2101
- token: context.peek(),
2102
- context,
2103
- syntaxToken: syntax,
2104
- errors: [],
2105
- });
2114
+ return result;
2106
2115
  }
2107
2116
  function matchProperty(property, context, options) {
2108
2117
  let success = false;
@@ -2165,17 +2174,17 @@ function matchProperty(property, context, options) {
2165
2174
  };
2166
2175
  }
2167
2176
  switch (property.val) {
2168
- case "combinator":
2169
- {
2170
- const token = context.peek();
2171
- success =
2172
- token != null &&
2173
- (token.typ == EnumToken.NextSiblingCombinatorTokenType ||
2174
- token.typ == EnumToken.ChildCombinatorTokenType ||
2175
- token.typ == EnumToken.SubsequentSiblingCombinatorTokenType ||
2176
- token.typ == EnumToken.ColumnCombinatorTokenType);
2177
- }
2178
- break;
2177
+ // case "combinator":
2178
+ // {
2179
+ // const token = context.peek() as Token;
2180
+ // success =
2181
+ // token != null &&
2182
+ // (token.typ == EnumToken.NextSiblingCombinatorTokenType ||
2183
+ // token.typ == EnumToken.ChildCombinatorTokenType ||
2184
+ // token.typ == EnumToken.SubsequentSiblingCombinatorTokenType ||
2185
+ // token.typ == EnumToken.ColumnCombinatorTokenType);
2186
+ // }
2187
+ // break;
2179
2188
  case "declaration-value":
2180
2189
  {
2181
2190
  // consume a declaration value
@@ -2185,112 +2194,91 @@ function matchProperty(property, context, options) {
2185
2194
  // if semicolon or end curly brace is encountered, stop
2186
2195
  let expectToken = true;
2187
2196
  let token;
2188
- const stack = [];
2189
2197
  token = context.peek();
2190
- if (token?.typ == EnumToken.WhitespaceTokenType) {
2191
- context.next();
2192
- token = context.peek();
2193
- }
2194
- if (token?.typ == EnumToken.CommentTokenType) {
2195
- context.next();
2196
- token = context.peek();
2197
- }
2198
- if (token?.typ == EnumToken.CommaTokenType) {
2199
- context.next();
2200
- expectToken = true;
2201
- }
2198
+ // if (token?.typ == EnumToken.WhitespaceTokenType) {
2199
+ // context.next();
2200
+ // token = context.peek();
2201
+ // }
2202
+ // if (token?.typ == EnumToken.CommentTokenType) {
2203
+ // context.next();
2204
+ // token = context.peek();
2205
+ // }
2206
+ // if (token?.typ == EnumToken.CommaTokenType) {
2207
+ // context.next();
2208
+ // expectToken = true;
2209
+ // }
2202
2210
  while ((token = context.peek()) != null) {
2203
- if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
2204
- stack.push(token);
2205
- }
2206
- if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
2207
- context.next();
2208
- }
2211
+ if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) ;
2212
+ // if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
2213
+ // context.next();
2214
+ // }
2209
2215
  if (expectToken) {
2210
- if (token?.typ == EnumToken.CommaTokenType || token.typ == EnumToken.EndParensTokenType) {
2211
- return {
2212
- success: false,
2213
- valid: true,
2214
- token,
2215
- context,
2216
- syntaxToken: property,
2217
- errors: [
2218
- {
2219
- action: "drop",
2220
- message: `Unexpected token ${EnumToken[token?.typ]} at ${token.loc?.src}:${token.loc?.sta?.lin}:${token.loc?.sta?.col}`,
2221
- node: token,
2222
- location: token.loc,
2223
- },
2224
- ],
2225
- };
2226
- }
2216
+ // if (token?.typ == EnumToken.CommaTokenType || token.typ == EnumToken.EndParensTokenType) {
2217
+ // return {
2218
+ // success: false,
2219
+ // valid: true,
2220
+ // token,
2221
+ // context,
2222
+ // syntaxToken: property,
2223
+ // errors: [
2224
+ // {
2225
+ // action: "drop",
2226
+ // message: `Unexpected token ${EnumToken[token?.typ]} at ${token![LOC]?.src}:${token![LOC]?.sta?.lin}:${token![LOC]?.sta?.col}`,
2227
+ // node: token,
2228
+ // location: token[LOC],
2229
+ // },
2230
+ // ],
2231
+ // };
2232
+ // }
2227
2233
  expectToken = false;
2228
2234
  }
2229
2235
  if (token.typ == EnumToken.CommaTokenType) {
2230
2236
  expectToken = true;
2231
2237
  }
2232
- if (token.typ == EnumToken.EndParensTokenType) {
2233
- if (stack.length > 0) {
2234
- stack.pop();
2235
- }
2236
- else {
2237
- return {
2238
- success: false,
2239
- valid: true,
2240
- token,
2241
- context,
2242
- syntaxToken: property,
2243
- errors: [
2244
- {
2245
- action: "drop",
2246
- message: `Unexpected token ${EnumToken[token?.typ]} at ${token.loc?.src}:${token.loc?.sta?.lin}:${token.loc?.sta?.col}`,
2247
- node: token,
2248
- location: token.loc,
2249
- },
2250
- ],
2251
- };
2252
- }
2253
- }
2254
2238
  context.next();
2255
2239
  }
2256
- if (stack.length > 0) {
2257
- token = stack.at(-1);
2258
- return {
2259
- success: false,
2260
- valid: true,
2261
- token,
2262
- context,
2263
- syntaxToken: property,
2264
- errors: [
2265
- {
2266
- action: "drop",
2267
- message: `unbalanced parentheses ${EnumToken[token?.typ]} at ${token.loc?.src}:${token.loc?.sta?.lin}:${token.loc?.sta?.col}`,
2268
- node: token,
2269
- location: token.loc,
2270
- },
2271
- ],
2272
- };
2273
- }
2240
+ // if (stack.length > 0) {
2241
+ // token = stack.at(-1) as Token;
2242
+ // return {
2243
+ // success: false,
2244
+ // valid: true,
2245
+ // token,
2246
+ // context,
2247
+ // syntaxToken: property,
2248
+ // errors: [
2249
+ // {
2250
+ // action: "drop",
2251
+ // message: `unbalanced parentheses ${EnumToken[token?.typ]} at ${token![LOC]?.src}:${token![LOC]?.sta?.lin}:${token![LOC]?.sta?.col}`,
2252
+ // node: token,
2253
+ // location: token[LOC],
2254
+ // },
2255
+ // ],
2256
+ // };
2257
+ // }
2274
2258
  success = !expectToken;
2275
- if (!success) {
2276
- return {
2277
- success: false,
2278
- valid: true,
2279
- token: token ?? context.current(),
2280
- context,
2281
- syntaxToken: property,
2282
- errors: [],
2283
- };
2284
- }
2259
+ // if (!success) {
2260
+ // return {
2261
+ // success: false,
2262
+ // valid: true,
2263
+ // token: token ?? context.current(),
2264
+ // context,
2265
+ // syntaxToken: property,
2266
+ // errors: [],
2267
+ // };
2268
+ // }
2285
2269
  }
2286
2270
  break;
2287
2271
  case "calc-sum": {
2288
2272
  const token = context.peek();
2289
- if (token?.typ === EnumToken.ParensTokenType) {
2290
- const result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()")[0].chi, createValidationContext(token.chi), options);
2291
- success = result.success && result.context.done();
2292
- break;
2293
- }
2273
+ // if (token?.typ === EnumToken.ParensTokenType) {
2274
+ // const result = matchSyntax(
2275
+ // (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()") as ValidationFunctionToken[])[0].chi,
2276
+ // createValidationContext((token as ParensToken).chi),
2277
+ // options,
2278
+ // );
2279
+ // success = result.success && result.context.done();
2280
+ // break;
2281
+ // }
2294
2282
  if (token?.typ === EnumToken.BinaryExpressionTokenType) {
2295
2283
  let result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc-sum"), createValidationContext([token.l]), options);
2296
2284
  if (result.success) {
@@ -2319,22 +2307,22 @@ function matchProperty(property, context, options) {
2319
2307
  }
2320
2308
  break;
2321
2309
  }
2322
- case "at-keyword-token":
2323
- success = context.peek()?.typ === EnumToken.AtRuleTokenType;
2324
- break;
2310
+ // case "at-keyword-token":
2311
+ // success = context.peek()?.typ === EnumToken.AtRuleTokenType;
2312
+ // break;
2325
2313
  case "an+b":
2326
2314
  {
2327
2315
  let token = context.peek();
2328
- if (token == null) {
2329
- return {
2330
- success: false,
2331
- valid: true,
2332
- token: null,
2333
- context,
2334
- syntaxToken: property,
2335
- errors: [],
2336
- };
2337
- }
2316
+ // if (token == null) {
2317
+ // return {
2318
+ // success: false,
2319
+ // valid: true,
2320
+ // token: null,
2321
+ // context,
2322
+ // syntaxToken: property,
2323
+ // errors: [],
2324
+ // };
2325
+ // }
2338
2326
  if (token.typ === EnumToken.IdenTokenType &&
2339
2327
  ("even" === token.val || "odd" === token.val)) {
2340
2328
  success = true;
@@ -2349,19 +2337,19 @@ function matchProperty(property, context, options) {
2349
2337
  if (token.typ === EnumToken.LiteralTokenType || token.typ === EnumToken.IdenTokenType) {
2350
2338
  let match = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(token.val);
2351
2339
  success = match != null;
2352
- if (!success) {
2353
- success = /^(([+-]?[0-9]*)?n)?([+-])?$/.test(token.val);
2354
- if (success) {
2355
- token = context.peek(1);
2356
- success =
2357
- token?.typ === EnumToken.NumberTokenType &&
2358
- Number.isInteger(token.val) &&
2359
- !token.toString().includes(".") &&
2360
- token.sign == null;
2361
- context.next();
2362
- }
2363
- }
2364
- else if (match?.[3] == null) {
2340
+ // if (!success) {
2341
+ // success = /^(([+-]?[0-9]*)?n)?([+-])?$/.test((token as LiteralToken).val);
2342
+ // if (success) {
2343
+ // token = context.peek(1) as Token;
2344
+ // success =
2345
+ // token?.typ === EnumToken.NumberTokenType &&
2346
+ // Number.isInteger((token as NumberToken).val) &&
2347
+ // !(token as NumberToken).toString().includes(".") &&
2348
+ // (token as NumberToken).sign == null;
2349
+ // context.next();
2350
+ // }
2351
+ // } else
2352
+ if (match?.[3] == null) {
2365
2353
  token = context.peek(1);
2366
2354
  if (token?.typ === EnumToken.Add ||
2367
2355
  token?.typ === EnumToken.NextSiblingCombinatorTokenType ||
@@ -2373,12 +2361,12 @@ function matchProperty(property, context, options) {
2373
2361
  !token.toString().includes(".") &&
2374
2362
  token.sign == null;
2375
2363
  }
2376
- else if (token?.typ === EnumToken.NumberTokenType) {
2377
- success =
2378
- Number.isInteger(token.val) &&
2379
- !token.toString().includes(".") &&
2380
- token.sign != null;
2381
- }
2364
+ // else if (token?.typ === EnumToken.NumberTokenType) {
2365
+ // success =
2366
+ // Number.isInteger((token as NumberToken).val) &&
2367
+ // !(token as NumberToken).toString().includes(".") &&
2368
+ // (token as NumberToken).sign != null;
2369
+ // }
2382
2370
  if (success) {
2383
2371
  context.update(token);
2384
2372
  return {
@@ -2397,26 +2385,26 @@ function matchProperty(property, context, options) {
2397
2385
  success =
2398
2386
  Number.isInteger(token.val) &&
2399
2387
  !token.toString().includes(".");
2400
- if (!success) {
2401
- return {
2402
- success: false,
2403
- valid: true,
2404
- token: null,
2405
- context,
2406
- syntaxToken: property,
2407
- errors: [
2408
- {
2409
- action: "drop",
2410
- message: `expecting <dimension-token>`,
2411
- node: token,
2412
- location: token.loc,
2413
- },
2414
- ],
2415
- };
2416
- }
2417
- if (token == null) {
2418
- break;
2419
- }
2388
+ // if (!success) {
2389
+ // return {
2390
+ // success: false,
2391
+ // valid: true,
2392
+ // token: null,
2393
+ // context,
2394
+ // syntaxToken: property,
2395
+ // errors: [
2396
+ // {
2397
+ // action: "drop",
2398
+ // message: `expecting <dimension-token>`,
2399
+ // node: token,
2400
+ // location: token[LOC],
2401
+ // },
2402
+ // ],
2403
+ // };
2404
+ // }
2405
+ // if (token == null) {
2406
+ // break;
2407
+ // }
2420
2408
  token = context.peek(1);
2421
2409
  if (token == null) {
2422
2410
  break;
@@ -2434,9 +2422,9 @@ function matchProperty(property, context, options) {
2434
2422
  Object.assign(token, { typ: EnumToken.Add });
2435
2423
  }
2436
2424
  token = context.peek(2);
2437
- if (token == null) {
2438
- break;
2439
- }
2425
+ // if (token == null) {
2426
+ // break;
2427
+ // }
2440
2428
  if (token?.typ === EnumToken.NumberTokenType &&
2441
2429
  Number.isInteger(token.val) &&
2442
2430
  !token.toString().includes(".") &&
@@ -2449,33 +2437,33 @@ function matchProperty(property, context, options) {
2449
2437
  }
2450
2438
  }
2451
2439
  break;
2452
- case "number-token":
2453
- {
2454
- const token = context.peek();
2455
- success =
2456
- token?.typ === EnumToken.NumberTokenType &&
2457
- !token.val.toString().includes(".") &&
2458
- Number.isInteger(token.val);
2459
- }
2460
- break;
2461
- case "ndashdigit-ident":
2462
- {
2463
- const token = context.peek();
2464
- success =
2465
- (token?.typ === EnumToken.IdenTokenType || token?.typ === EnumToken.LiteralTokenType) &&
2466
- /^-?n[-+]\d+$/.test(token.val);
2467
- }
2468
- break;
2469
- case "dimension-token":
2470
- {
2471
- const token = context.peek();
2472
- success =
2473
- token?.typ === EnumToken.DimensionTokenType &&
2474
- token.unit === "n" &&
2475
- !token.val.toString().includes(".") &&
2476
- Number.isInteger(token.val);
2477
- }
2478
- break;
2440
+ // case "number-token":
2441
+ // {
2442
+ // const token = context.peek();
2443
+ // success =
2444
+ // token?.typ === EnumToken.NumberTokenType &&
2445
+ // !(token as DimensionToken).val.toString().includes(".") &&
2446
+ // Number.isInteger((token as DimensionToken).val);
2447
+ // }
2448
+ // break;
2449
+ // case "ndashdigit-ident":
2450
+ // {
2451
+ // const token = context.peek();
2452
+ // success =
2453
+ // (token?.typ === EnumToken.IdenTokenType || token?.typ === EnumToken.LiteralTokenType) &&
2454
+ // /^-?n[-+]\d+$/.test((token as IdentToken | LiteralToken).val);
2455
+ // }
2456
+ // break;
2457
+ // case "dimension-token":
2458
+ // {
2459
+ // const token = context.peek();
2460
+ // success =
2461
+ // token?.typ === EnumToken.DimensionTokenType &&
2462
+ // (token as DimensionToken).unit === "n" &&
2463
+ // !(token as DimensionToken).val.toString().includes(".") &&
2464
+ // Number.isInteger((token as DimensionToken).val);
2465
+ // }
2466
+ // break;
2479
2467
  case "quote":
2480
2468
  case "display-box":
2481
2469
  case "display-inside":
@@ -2498,29 +2486,29 @@ function matchProperty(property, context, options) {
2498
2486
  token.val.toLowerCase() in config.mediaFeatures;
2499
2487
  }
2500
2488
  break;
2501
- case "mf-comparison":
2502
- {
2503
- const token = context.peek();
2504
- success =
2505
- token?.typ === EnumToken.LtTokenType ||
2506
- token?.typ === EnumToken.LteTokenType ||
2507
- token?.typ === EnumToken.GtTokenType ||
2508
- token?.typ === EnumToken.GteTokenType ||
2509
- token?.typ === EnumToken.DelimTokenType;
2510
- }
2511
- break;
2512
- case "mf-gt":
2513
- {
2514
- const token = context.peek();
2515
- success = token?.typ === EnumToken.GtTokenType || token?.typ === EnumToken.GteTokenType;
2516
- }
2517
- break;
2518
- case "mf-lt":
2519
- {
2520
- const token = context.peek();
2521
- success = token?.typ === EnumToken.LtTokenType || token?.typ === EnumToken.LteTokenType;
2522
- }
2523
- break;
2489
+ // case "mf-comparison":
2490
+ // {
2491
+ // const token = context.peek();
2492
+ // success =
2493
+ // token?.typ === EnumToken.LtTokenType ||
2494
+ // token?.typ === EnumToken.LteTokenType ||
2495
+ // token?.typ === EnumToken.GtTokenType ||
2496
+ // token?.typ === EnumToken.GteTokenType ||
2497
+ // token?.typ === EnumToken.DelimTokenType;
2498
+ // }
2499
+ // break;
2500
+ // case "mf-gt":
2501
+ // {
2502
+ // const token = context.peek();
2503
+ // success = token?.typ === EnumToken.GtTokenType || token?.typ === EnumToken.GteTokenType;
2504
+ // }
2505
+ // break;
2506
+ // case "mf-lt":
2507
+ // {
2508
+ // const token = context.peek();
2509
+ // success = token?.typ === EnumToken.LtTokenType || token?.typ === EnumToken.LteTokenType;
2510
+ // }
2511
+ // break;
2524
2512
  case "dashed-ident":
2525
2513
  case "extension-name":
2526
2514
  case "custom-property-name":
@@ -2560,41 +2548,37 @@ function matchProperty(property, context, options) {
2560
2548
  }
2561
2549
  case "string": {
2562
2550
  const token = context.peek();
2563
- if (token == null) {
2564
- break;
2565
- }
2566
- success = token.typ === EnumToken.StringTokenType;
2551
+ // if (token == null) {
2552
+ // break;
2553
+ // }
2554
+ success = token?.typ === EnumToken.StringTokenType;
2567
2555
  break;
2568
2556
  }
2569
- case "wq-name":
2570
- // wq-name matches
2571
- // a
2572
- // |a
2573
- // *|a
2557
+ case "wq-name": // *|a // |a // a // wq-name matches
2574
2558
  // a|b
2575
- if (context.peek()?.typ == EnumToken.Pipe) {
2576
- const success = context.peek(1)?.typ == EnumToken.IdenTokenType;
2577
- return {
2578
- success,
2579
- valid: true,
2580
- token: success ? context.update(context.peek(1)).current() : context.peek(),
2581
- context,
2582
- syntaxToken: property,
2583
- errors: [],
2584
- };
2585
- }
2586
- else if (context.peek(1)?.typ == EnumToken.Pipe) {
2587
- const success = context.peek()?.typ === EnumToken.Star && context.peek(2)?.typ === EnumToken.IdenTokenType;
2588
- return {
2589
- success,
2590
- valid: true,
2591
- token: success ? context.update(context.peek(2)).current() : context.peek(),
2592
- context,
2593
- syntaxToken: property,
2594
- errors: [],
2595
- };
2596
- }
2597
- else {
2559
+ // if (context.peek()?.typ == EnumToken.Pipe) {
2560
+ // const success = context.peek(1)?.typ == EnumToken.IdenTokenType;
2561
+ // return {
2562
+ // success,
2563
+ // valid: true,
2564
+ // token: success ? context.update(context.peek(1) as Token).current() : context.peek(),
2565
+ // context,
2566
+ // syntaxToken: property,
2567
+ // errors: [],
2568
+ // };
2569
+ // } else if (context.peek(1)?.typ == EnumToken.Pipe) {
2570
+ // const success =
2571
+ // context.peek()?.typ === EnumToken.Star && context.peek(2)?.typ === EnumToken.IdenTokenType;
2572
+ // return {
2573
+ // success,
2574
+ // valid: true,
2575
+ // token: success ? context.update(context.peek(2) as Token).current() : context.peek(),
2576
+ // context,
2577
+ // syntaxToken: property,
2578
+ // errors: [],
2579
+ // };
2580
+ // } else
2581
+ {
2598
2582
  const success = context.peek()?.typ == EnumToken.IdenTokenType;
2599
2583
  return {
2600
2584
  success,
@@ -2605,28 +2589,28 @@ function matchProperty(property, context, options) {
2605
2589
  errors: [],
2606
2590
  };
2607
2591
  }
2608
- case "id-selector":
2609
- success = context.peek()?.typ == EnumToken.HashTokenType;
2610
- break;
2611
- case "class-selector":
2612
- success = context.peek()?.typ == EnumToken.ClassSelectorTokenType;
2613
- break;
2614
- case "pseudo-class-selector":
2615
- {
2616
- const token = context.peek();
2617
- success =
2618
- token?.typ == EnumToken.PseudoClassTokenType ||
2619
- token?.typ == EnumToken.PseudoClassFuncTokenType ||
2620
- token?.typ == EnumToken.PseudoElementTokenType;
2621
- }
2622
- break;
2592
+ // case "id-selector":
2593
+ // success = context.peek()?.typ == EnumToken.HashTokenType;
2594
+ // break;
2595
+ // case "class-selector":
2596
+ // success = context.peek()?.typ == EnumToken.ClassSelectorTokenType;
2597
+ // break;
2598
+ // case "pseudo-class-selector":
2599
+ // {
2600
+ // const token = context.peek();
2601
+ // success =
2602
+ // token?.typ == EnumToken.PseudoClassTokenType ||
2603
+ // token?.typ == EnumToken.PseudoClassFuncTokenType ||
2604
+ // token?.typ == EnumToken.PseudoElementTokenType;
2605
+ // }
2606
+ // break;
2623
2607
  case "number":
2624
2608
  {
2625
2609
  const token = context.peek();
2626
- if (token == null) {
2627
- break;
2628
- }
2629
- success = token.typ == EnumToken.NumberTokenType;
2610
+ // if (token == null) {
2611
+ // break;
2612
+ // }
2613
+ success = token?.typ == EnumToken.NumberTokenType;
2630
2614
  }
2631
2615
  break;
2632
2616
  case "zero": {
@@ -2643,9 +2627,9 @@ function matchProperty(property, context, options) {
2643
2627
  break;
2644
2628
  case "dimension": {
2645
2629
  const token = context.peek();
2646
- if (token == null) {
2647
- break;
2648
- }
2630
+ // if (token == null) {
2631
+ // break;
2632
+ // }
2649
2633
  success =
2650
2634
  token?.typ == EnumToken.DimensionTokenType ||
2651
2635
  token?.typ == EnumToken.AngleTokenType ||
@@ -2660,19 +2644,19 @@ function matchProperty(property, context, options) {
2660
2644
  case "angle":
2661
2645
  {
2662
2646
  const token = context.peek();
2663
- if (token == null) {
2664
- break;
2665
- }
2666
- success = token.typ === EnumToken.AngleTokenType;
2647
+ // if (token == null) {
2648
+ // break;
2649
+ // }
2650
+ success = token?.typ === EnumToken.AngleTokenType;
2667
2651
  }
2668
2652
  break;
2669
2653
  case "angle-percentage":
2670
2654
  {
2671
2655
  const token = context.peek();
2672
- if (token == null) {
2673
- break;
2674
- }
2675
- success = token.typ === EnumToken.AngleTokenType || token.typ === EnumToken.PercentageTokenType;
2656
+ // if (token == null) {
2657
+ // break;
2658
+ // }
2659
+ success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.PercentageTokenType;
2676
2660
  }
2677
2661
  break;
2678
2662
  case "percentage":
@@ -2687,13 +2671,13 @@ function matchProperty(property, context, options) {
2687
2671
  case "length-percentage":
2688
2672
  {
2689
2673
  const token = context.peek();
2690
- if (token == null) {
2691
- break;
2692
- }
2674
+ // if (token == null) {
2675
+ // break;
2676
+ // }
2693
2677
  success =
2694
- token.typ == EnumToken.PercentageTokenType ||
2695
- token.typ == EnumToken.LengthTokenType ||
2696
- (token.typ == EnumToken.NumberTokenType && token.val === 0);
2678
+ token?.typ == EnumToken.PercentageTokenType ||
2679
+ token?.typ == EnumToken.LengthTokenType ||
2680
+ (token?.typ == EnumToken.NumberTokenType && token?.val === 0);
2697
2681
  }
2698
2682
  break;
2699
2683
  case "flex":
@@ -2701,12 +2685,12 @@ function matchProperty(property, context, options) {
2701
2685
  break;
2702
2686
  case "length": {
2703
2687
  const token = context.peek();
2704
- if (token == null) {
2705
- break;
2706
- }
2688
+ // if (token == null) {
2689
+ // break;
2690
+ // }
2707
2691
  success =
2708
- token.typ == EnumToken.LengthTokenType ||
2709
- (token.typ == EnumToken.NumberTokenType && token.val === 0);
2692
+ token?.typ == EnumToken.LengthTokenType ||
2693
+ (token?.typ == EnumToken.NumberTokenType && token?.val === 0);
2710
2694
  break;
2711
2695
  }
2712
2696
  case "time":
@@ -2718,12 +2702,12 @@ function matchProperty(property, context, options) {
2718
2702
  success = token.typ == EnumToken.TimeTokenType;
2719
2703
  }
2720
2704
  break;
2721
- case "hex-color": {
2722
- const token = context.peek();
2723
- success =
2724
- token != null && token.typ == EnumToken.ColorTokenType && token.kin == ColorType.HEX;
2725
- break;
2726
- }
2705
+ // case "hex-color": {
2706
+ // const token = context.peek();
2707
+ // success =
2708
+ // token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
2709
+ // break;
2710
+ // }
2727
2711
  case "color":
2728
2712
  case "color-function":
2729
2713
  {
@@ -2799,10 +2783,10 @@ function matchProperty(property, context, options) {
2799
2783
  }
2800
2784
  }
2801
2785
  break;
2802
- case "url-token":
2803
- success =
2804
- context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
2805
- break;
2786
+ // case "url-token":
2787
+ // success =
2788
+ // context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
2789
+ // break;
2806
2790
  case "type-selector":
2807
2791
  case "compound-selector":
2808
2792
  case "complex-selector":
@@ -2827,13 +2811,15 @@ function matchProperty(property, context, options) {
2827
2811
  };
2828
2812
  }
2829
2813
  case "function-token":
2830
- if (context.peek()?.typ == EnumToken.IdenTokenType &&
2831
- context.peek(1, false)?.typ == EnumToken.StartParensTokenType) {
2832
- context.next();
2833
- context.next();
2834
- success = true;
2835
- break;
2836
- }
2814
+ // if (
2815
+ // context.peek()?.typ == EnumToken.IdenTokenType &&
2816
+ // context.peek(1, false)?.typ == EnumToken.StartParensTokenType
2817
+ // ) {
2818
+ // context.next();
2819
+ // context.next();
2820
+ // success = true;
2821
+ // break;
2822
+ // }
2837
2823
  if (tokensfuncDefMap.has(context.peek()?.typ)) {
2838
2824
  success = true;
2839
2825
  context.next();
@@ -2855,17 +2841,17 @@ function matchProperty(property, context, options) {
2855
2841
  config.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
2856
2842
  break;
2857
2843
  }
2858
- case "named-color": {
2859
- const token = context.peek();
2860
- success =
2861
- token != null &&
2862
- token.typ == EnumToken.ColorTokenType &&
2863
- (token.kin == ColorType.LIT ||
2864
- token.kin == ColorType.SYS ||
2865
- token.kin == ColorType.DPSYS ||
2866
- token.kin == ColorType.NON_STD);
2867
- break;
2868
- }
2844
+ // case "named-color": {
2845
+ // const token = context.peek();
2846
+ // success =
2847
+ // token != null &&
2848
+ // token.typ == EnumToken.ColorTokenType &&
2849
+ // ((token as ColorToken).kin == ColorType.LIT ||
2850
+ // (token as ColorToken).kin == ColorType.SYS ||
2851
+ // (token as ColorToken).kin == ColorType.DPSYS ||
2852
+ // (token as ColorToken).kin == ColorType.NON_STD);
2853
+ // break;
2854
+ // }
2869
2855
  case "size-feature": {
2870
2856
  const range = context.peekRange();
2871
2857
  const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
@@ -2896,20 +2882,20 @@ function matchProperty(property, context, options) {
2896
2882
  errors: [],
2897
2883
  };
2898
2884
  }
2899
- if (filteredRange.length === 3) {
2900
- success = isValue(filteredRange[2]);
2901
- if (success) {
2902
- context.update(filteredRange[2]);
2903
- return {
2904
- success,
2905
- valid: true,
2906
- token: filteredRange[2],
2907
- context,
2908
- syntaxToken: property,
2909
- errors: [],
2910
- };
2911
- }
2912
- }
2885
+ // if (filteredRange.length === 3) {
2886
+ // success = isValue(filteredRange[2]);
2887
+ // if (success) {
2888
+ // context.update(filteredRange[2]);
2889
+ // return {
2890
+ // success,
2891
+ // valid: true,
2892
+ // token: filteredRange[2],
2893
+ // context,
2894
+ // syntaxToken: property,
2895
+ // errors: [],
2896
+ // };
2897
+ // }
2898
+ // }
2913
2899
  break;
2914
2900
  }
2915
2901
  case "style-feature": {
@@ -2919,16 +2905,16 @@ function matchProperty(property, context, options) {
2919
2905
  // match <style-range>
2920
2906
  const range = context.peekRange();
2921
2907
  const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
2922
- if (filteredRange.length === 0) {
2923
- return {
2924
- success: false,
2925
- valid: true,
2926
- token: context.peek(),
2927
- context,
2928
- syntaxToken: property,
2929
- errors: [],
2930
- };
2931
- }
2908
+ // if (filteredRange.length === 0) {
2909
+ // return {
2910
+ // success: false,
2911
+ // valid: true,
2912
+ // token: context.peek(),
2913
+ // context,
2914
+ // syntaxToken: property,
2915
+ // errors: [],
2916
+ // };
2917
+ // }
2932
2918
  if (filteredRange.length === 1) {
2933
2919
  success =
2934
2920
  filteredRange[0].typ === EnumToken.IdenTokenType ||
@@ -2943,29 +2929,31 @@ function matchProperty(property, context, options) {
2943
2929
  errors: [],
2944
2930
  };
2945
2931
  }
2946
- if (filteredRange[1]?.typ === EnumToken.ColonTokenType ||
2947
- filteredRange[1]?.typ === EnumToken.DelimTokenType) {
2948
- const result = isDeclarationValue(filteredRange.slice(2));
2949
- if (result.success) {
2950
- context.update(filteredRange.at(-1));
2951
- return {
2952
- success: true,
2953
- valid: true,
2954
- token: filteredRange.at(-1),
2955
- context,
2956
- syntaxToken: property,
2957
- errors: [],
2958
- };
2959
- }
2960
- return {
2961
- success: false,
2962
- valid: false,
2963
- token: context.peek(),
2964
- context,
2965
- syntaxToken: property,
2966
- errors: result.errors,
2967
- };
2968
- }
2932
+ // if (
2933
+ // filteredRange[1]?.typ === EnumToken.ColonTokenType ||
2934
+ // filteredRange[1]?.typ === EnumToken.DelimTokenType
2935
+ // ) {
2936
+ // const result = isDeclarationValue(filteredRange.slice(2));
2937
+ // if (result.success) {
2938
+ // context.update(filteredRange.at(-1)!);
2939
+ // return {
2940
+ // success: true,
2941
+ // valid: true,
2942
+ // token: filteredRange.at(-1)!,
2943
+ // context,
2944
+ // syntaxToken: property,
2945
+ // errors: [],
2946
+ // };
2947
+ // }
2948
+ // return {
2949
+ // success: false,
2950
+ // valid: false,
2951
+ // token: context.peek(),
2952
+ // context,
2953
+ // syntaxToken: property,
2954
+ // errors: result.errors,
2955
+ // };
2956
+ // }
2969
2957
  return {
2970
2958
  success: false,
2971
2959
  valid: false,
@@ -2977,12 +2965,12 @@ function matchProperty(property, context, options) {
2977
2965
  }
2978
2966
  case "url": {
2979
2967
  const token = context.peek();
2980
- if (token == null) {
2981
- success = false;
2982
- break;
2983
- }
2968
+ // if (token == null) {
2969
+ // success = false;
2970
+ // break;
2971
+ // }
2984
2972
  let l;
2985
- if (token.typ == EnumToken.UrlFunctionTokenDefType) {
2973
+ if (token?.typ == EnumToken.UrlFunctionTokenDefType) {
2986
2974
  l = 0;
2987
2975
  let token;
2988
2976
  while ((token = context.peek(++l))) {
@@ -2994,11 +2982,11 @@ function matchProperty(property, context, options) {
2994
2982
  (token.typ == EnumToken.StringTokenType ||
2995
2983
  token.typ == EnumToken.IdenTokenType ||
2996
2984
  token.typ == EnumToken.UrlTokenTokenType)) {
2997
- if (token.typ === EnumToken.IdenTokenType) {
2998
- while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
2999
- l++;
3000
- }
3001
- }
2985
+ // if (token.typ === EnumToken.IdenTokenType) {
2986
+ // while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
2987
+ // l++;
2988
+ // }
2989
+ // }
3002
2990
  while ((token = context.peek(++l))) {
3003
2991
  if (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType) {
3004
2992
  break;
@@ -3085,7 +3073,7 @@ function matchRepeatableSyntax(syntax, context, options) {
3085
3073
  let result = null;
3086
3074
  let tmpResult;
3087
3075
  let success = !!isRepeatable;
3088
- let index = context.index;
3076
+ // let index: number = context.index;
3089
3077
  do {
3090
3078
  tmpResult = matchSyntax([rest], context.slice(), options);
3091
3079
  if (tmpResult.success) {
@@ -3095,16 +3083,15 @@ function matchRepeatableSyntax(syntax, context, options) {
3095
3083
  context.end();
3096
3084
  break;
3097
3085
  }
3098
- if (context.current() === tmpResult.context.current()) {
3099
- context.next();
3100
- }
3101
- else {
3102
- context.update(result.context.current());
3103
- }
3104
- if (index === context.index) {
3105
- break;
3106
- }
3107
- index = context.index;
3086
+ // if (context.current() === tmpResult.context.current()) {
3087
+ // context.next();
3088
+ // } else {
3089
+ context.update(result.context.current());
3090
+ // }
3091
+ // if (index === context.index) {
3092
+ // break;
3093
+ // }
3094
+ // index = context.index;
3108
3095
  }
3109
3096
  } while (tmpResult.success && !context.done());
3110
3097
  return {
@@ -3117,4 +3104,4 @@ function matchRepeatableSyntax(syntax, context, options) {
3117
3104
  };
3118
3105
  }
3119
3106
 
3120
- export { createValidationContext, funcTypes, getMFInfo, isMFName, isMFValue, isStyleRangeValue, matchAllSyntaxes, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
3107
+ export { createValidationContext, funcTypes, getMFInfo, isMFValue, matchAllSyntaxes, matchOccurenceSyntax, matchSelectorSyntax, trimArray };