@tbela99/css-parser 1.2.0 → 1.3.1

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 (70) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +29 -11
  3. package/dist/index-umd-web.js +2041 -1967
  4. package/dist/index.cjs +2129 -1964
  5. package/dist/index.d.ts +1936 -77
  6. package/dist/lib/ast/expand.js +4 -65
  7. package/dist/lib/ast/features/calc.js +3 -27
  8. package/dist/lib/ast/features/inlinecssvariables.js +2 -21
  9. package/dist/lib/ast/features/prefix.js +2 -1
  10. package/dist/lib/ast/features/transform.js +4 -3
  11. package/dist/lib/ast/features/type.js +9 -0
  12. package/dist/lib/ast/math/expression.js +26 -149
  13. package/dist/lib/ast/math/math.js +9 -9
  14. package/dist/lib/ast/minify.js +82 -171
  15. package/dist/lib/ast/transform/compute.js +4 -37
  16. package/dist/lib/ast/transform/matrix.js +33 -34
  17. package/dist/lib/ast/transform/minify.js +32 -51
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +13 -13
  20. package/dist/lib/ast/transform/scale.js +8 -8
  21. package/dist/lib/ast/transform/skew.js +4 -4
  22. package/dist/lib/ast/transform/translate.js +8 -8
  23. package/dist/lib/ast/transform/utils.js +31 -39
  24. package/dist/lib/ast/types.js +459 -5
  25. package/dist/lib/ast/walk.js +18 -0
  26. package/dist/lib/fs/resolve.js +11 -3
  27. package/dist/lib/parser/declaration/map.js +1 -0
  28. package/dist/lib/parser/declaration/set.js +2 -2
  29. package/dist/lib/parser/parse.js +139 -32
  30. package/dist/lib/parser/tokenize.js +41 -93
  31. package/dist/lib/parser/utils/type.js +1 -1
  32. package/dist/lib/renderer/render.js +61 -30
  33. package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
  34. package/dist/lib/syntax/color/cmyk.js +2 -2
  35. package/dist/lib/syntax/color/color-mix.js +11 -12
  36. package/dist/lib/syntax/color/color.js +14 -7
  37. package/dist/lib/syntax/color/hsl.js +4 -4
  38. package/dist/lib/syntax/color/hwb.js +27 -8
  39. package/dist/lib/syntax/color/lab.js +4 -4
  40. package/dist/lib/syntax/color/lch.js +4 -4
  41. package/dist/lib/syntax/color/oklab.js +4 -4
  42. package/dist/lib/syntax/color/oklch.js +4 -4
  43. package/dist/lib/syntax/color/relativecolor.js +1 -1
  44. package/dist/lib/syntax/color/rgb.js +4 -4
  45. package/dist/lib/syntax/color/utils/components.js +15 -3
  46. package/dist/lib/syntax/color/utils/distance.js +15 -1
  47. package/dist/lib/syntax/syntax.js +18 -17
  48. package/dist/lib/syntax/utils.js +1 -1
  49. package/dist/lib/validation/at-rules/document.js +1 -1
  50. package/dist/lib/validation/at-rules/import.js +4 -4
  51. package/dist/lib/validation/at-rules/keyframes.js +0 -11
  52. package/dist/lib/validation/at-rules/supports.js +6 -6
  53. package/dist/lib/validation/config.js +0 -4
  54. package/dist/lib/validation/config.json.js +33 -30
  55. package/dist/lib/validation/parser/parse.js +0 -8
  56. package/dist/lib/validation/selector.js +0 -9
  57. package/dist/lib/validation/syntax.js +17 -135
  58. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
  59. package/dist/lib/validation/syntaxes/family-name.js +0 -32
  60. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
  61. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
  62. package/dist/lib/validation/syntaxes/url.js +0 -33
  63. package/dist/lib/validation/utils/list.js +0 -8
  64. package/dist/node.js +229 -0
  65. package/dist/web.js +158 -0
  66. package/package.json +14 -11
  67. package/dist/node/index.js +0 -57
  68. package/dist/node/load.js +0 -20
  69. package/dist/web/index.js +0 -66
  70. package/dist/web/load.js +0 -31
@@ -8,9 +8,11 @@ import '../parser/tokenize.js';
8
8
  import '../parser/utils/config.js';
9
9
  import { wildCardFuncs, isIdentColor, mathFuncs } from '../syntax/syntax.js';
10
10
  import { renderToken } from '../renderer/render.js';
11
- import { funcLike, colorsFunc } from '../syntax/color/utils/constants.js';
11
+ import '../renderer/sourcemap/lib/encode.js';
12
12
  import { getSyntaxConfig, getParsedSyntax, getSyntax } from './config.js';
13
13
  import './syntaxes/complex-selector.js';
14
+ import { funcLike, colorsFunc } from '../syntax/color/utils/constants.js';
15
+ import '../ast/features/type.js';
14
16
 
15
17
  const config = getSyntaxConfig();
16
18
  // @ts-ignore
@@ -42,15 +44,8 @@ function createContext(input) {
42
44
  },
43
45
  consume(token, howMany) {
44
46
  let newIndex = result.indexOf(token, this.index + 1);
45
- // if (newIndex == -1 || newIndex < this.index) {
46
- // return false;
47
- // }
48
47
  howMany ??= 0;
49
48
  let splice = 1;
50
- // if (result[newIndex - 1]?.typ == EnumToken.WhitespaceTokenType) {
51
- // splice++;
52
- // newIndex--;
53
- // }
54
49
  result.splice(this.index + 1, 0, ...result.splice(newIndex, splice + howMany));
55
50
  this.index += howMany + splice;
56
51
  return true;
@@ -72,10 +67,6 @@ function createContext(input) {
72
67
  this.index = index;
73
68
  return result[this.index] ?? null;
74
69
  },
75
- // tokens<Token>(): Token[] {
76
- //
77
- // return result as Token[];
78
- // },
79
70
  slice() {
80
71
  return result.slice(this.index + 1);
81
72
  },
@@ -83,16 +74,7 @@ function createContext(input) {
83
74
  const context = createContext(result.slice());
84
75
  context.index = this.index;
85
76
  return context;
86
- },
87
- // @ts-ignore
88
- // toJSON(): object {
89
- //
90
- // return {
91
- // index: this.index,
92
- // slice: this.slice(),
93
- // tokens: this.tokens()
94
- // }
95
- // }
77
+ }
96
78
  };
97
79
  }
98
80
  function evaluateSyntax(node, options) {
@@ -126,10 +108,6 @@ function evaluateSyntax(node, options) {
126
108
  if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
127
109
  let token = null;
128
110
  if ((token = result.context.next()) != null) {
129
- // if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
130
- //
131
- // continue;
132
- // }
133
111
  return {
134
112
  ...result,
135
113
  valid: SyntaxValidationResult.Drop,
@@ -145,13 +123,6 @@ function evaluateSyntax(node, options) {
145
123
  };
146
124
  }
147
125
  break;
148
- // case EnumToken.RuleNodeType:
149
- // case EnumToken.AtRuleNodeType:
150
- // case EnumToken.KeyframeAtRuleNodeType:
151
- // case EnumToken.KeyFrameRuleNodeType:
152
- // default:
153
- //
154
- // throw new Error(`Not implemented: ${node.typ}`);
155
126
  }
156
127
  return {
157
128
  valid: SyntaxValidationResult.Valid,
@@ -193,8 +164,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
193
164
  context
194
165
  };
195
166
  }
196
- // console.error(`>> ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
197
- // console.error(new Error('doEvaluateSyntax'));
198
167
  for (; i < syntaxes.length; i++) {
199
168
  syntax = syntaxes[i];
200
169
  if (context.done()) {
@@ -205,7 +174,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
205
174
  }
206
175
  token = context.peek();
207
176
  // if var() is the last token, then match the remaining syntax and return
208
- if (context.length == 1 && token.typ == EnumToken.FunctionTokenType && 'var'.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0) {
177
+ if (context.length == 1 && token.typ == EnumToken.FunctionTokenType && 'var' === token.val?.toLowerCase?.()) {
209
178
  return doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, 'var')?.[0]?.chi ?? [], createContext(token.chi), options);
210
179
  }
211
180
  if (syntax.typ == ValidationTokenEnum.Whitespace) {
@@ -312,16 +281,6 @@ function matchList(syntax, context, options) {
312
281
  while (!con.done() && con.peek()?.typ != EnumToken.CommaTokenType) {
313
282
  tokens.push(con.next());
314
283
  }
315
- // if (tokens.length == 0) {
316
- //
317
- // return {
318
- // valid: SyntaxValidationResult.Drop,
319
- // node: context.peek(),
320
- // syntax,
321
- // error: `could not match syntax: ${renderSyntax(syntax)}`,
322
- // context
323
- // }
324
- // }
325
284
  result = doEvaluateSyntax([syntax], createContext(tokens), {
326
285
  ...options,
327
286
  isList: false,
@@ -406,22 +365,6 @@ function match(syntax, context, options) {
406
365
  };
407
366
  }
408
367
  }
409
- // if (token.typ == EnumToken.WhitespaceTokenType) {
410
- //
411
- // context.next();
412
- //
413
- // // @ts-ignore
414
- // if (syntax?.typ == ValidationTokenEnum.Whitespace) {
415
- //
416
- // return {
417
- // valid: SyntaxValidationResult.Valid,
418
- // node: null,
419
- // syntax,
420
- // error: '',
421
- // context
422
- // }
423
- // }
424
- // }
425
368
  if (syntax.typ != ValidationTokenEnum.PropertyType && (token?.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val))) {
426
369
  const result = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi ?? [], createContext(token.chi), {
427
370
  ...options,
@@ -439,7 +382,7 @@ function match(syntax, context, options) {
439
382
  case ValidationTokenEnum.Keyword:
440
383
  success = (token.typ == EnumToken.IdenTokenType || token.typ == EnumToken.DashedIdenTokenType || isIdentColor(token)) &&
441
384
  (token.val == syntax.val ||
442
- syntax.val.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0 ||
385
+ syntax.val === token.val?.toLowerCase?.() ||
443
386
  // config.declarations.all
444
387
  allValues.includes(token.val.toLowerCase()));
445
388
  if (success) {
@@ -467,7 +410,6 @@ function match(syntax, context, options) {
467
410
  };
468
411
  }
469
412
  result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
470
- // console.error(`>>[]
471
413
  if (result.valid == SyntaxValidationResult.Valid) {
472
414
  context.next();
473
415
  result.context = context;
@@ -482,49 +424,12 @@ function match(syntax, context, options) {
482
424
  occurence: null,
483
425
  atLeastOnce: null
484
426
  });
485
- // case ValidationTokenEnum.Parens:
486
- //
487
- // token = context.peek() as Token;
488
- // if (token.typ != EnumToken.ParensTokenType) {
489
- //
490
- // break;
491
- // }
492
- //
493
- // success = doEvaluateSyntax((syntax as ValidationParensToken).chi as ValidationToken[], createContext((token as ParensToken).chi), {
494
- // ...options,
495
- // isRepeatable: null,
496
- // isList: null,
497
- // occurence: null,
498
- // atLeastOnce: null
499
- // } as ValidationOptions).valid == SyntaxValidationResult.Valid;
500
- // break;
501
427
  case ValidationTokenEnum.Comma:
502
428
  success = context.peek()?.typ == EnumToken.CommaTokenType;
503
429
  if (success) {
504
430
  context.next();
505
431
  }
506
432
  break;
507
- // case ValidationTokenEnum.Number:
508
- //
509
- // success = context.peek<Token>()?.typ == EnumToken.NumberTokenType;
510
- //
511
- // if (success) {
512
- //
513
- // context.next();
514
- // }
515
- //
516
- // break;
517
- //
518
- // case ValidationTokenEnum.Whitespace:
519
- //
520
- // success = context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType;
521
- //
522
- // if (success) {
523
- //
524
- // context.next();
525
- // }
526
- //
527
- // break;
528
433
  case ValidationTokenEnum.Separator:
529
434
  {
530
435
  const token = context.peek();
@@ -540,14 +445,7 @@ function match(syntax, context, options) {
540
445
  break;
541
446
  }
542
447
  if (syntax.typ == ValidationTokenEnum.Function) {
543
- success = funcLike.includes(token.typ) && syntax.val.localeCompare(token.val, undefined, { sensitivity: 'base' }) == 0 && doEvaluateSyntax(syntax.chi, createContext(token.chi), options).valid == SyntaxValidationResult.Valid;
544
- // console.error(`>> match: ${JSON.stringify({
545
- // syntax,
546
- // token,
547
- // // result,
548
- // tr2: syntax,
549
- // success
550
- // }, null, 1)}`);
448
+ success = funcLike.includes(token.typ) && syntax.val.toLowerCase() === token.val?.toLowerCase?.() && doEvaluateSyntax(syntax.chi, createContext(token.chi), options).valid == SyntaxValidationResult.Valid;
551
449
  if (success) {
552
450
  context.next();
553
451
  }
@@ -566,7 +464,6 @@ function match(syntax, context, options) {
566
464
  }
567
465
  break;
568
466
  }
569
- // throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)} : ${renderToken(context.peek() as Token)} : ${JSON.stringify(syntax, null, 1)} | ${JSON.stringify(context.peek(), null, 1)}`);
570
467
  }
571
468
  if (!success && token.typ == EnumToken.IdenTokenType && allValues.includes(token.val.toLowerCase())) {
572
469
  success = true;
@@ -679,7 +576,7 @@ function matchPropertyType(syntax, context, options) {
679
576
  token = context.peek();
680
577
  continue;
681
578
  }
682
- success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0');
579
+ success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0);
683
580
  if (!success) {
684
581
  break;
685
582
  }
@@ -729,14 +626,14 @@ function matchPropertyType(syntax, context, options) {
729
626
  success = token.typ == EnumToken.DashedIdenTokenType;
730
627
  break;
731
628
  case 'system-color':
732
- success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.SYS) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
629
+ success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.SYS) || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
733
630
  break;
734
631
  case 'deprecated-system-color':
735
- success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.DPSYS) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
632
+ success = (token.typ == EnumToken.ColorTokenType && token.kin == ColorType.DPSYS) || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
736
633
  break;
737
634
  case 'color':
738
635
  case 'color-base':
739
- success = token.typ == EnumToken.ColorTokenType || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('currentcolor', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.IdenTokenType && token.val.localeCompare('transparent', 'en', { sensitivity: 'base' }) == 0) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
636
+ success = token.typ == EnumToken.ColorTokenType || (token.typ == EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == EnumToken.IdenTokenType && 'transparent' === token.val.toLowerCase()) || (token.typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
740
637
  if (!success && token.typ == EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
741
638
  success = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi, createContext(token.chi), {
742
639
  ...options,
@@ -777,19 +674,19 @@ function matchPropertyType(syntax, context, options) {
777
674
  }
778
675
  break;
779
676
  case 'angle':
780
- success = token.typ == EnumToken.AngleTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
677
+ success = token.typ == EnumToken.AngleTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
781
678
  break;
782
679
  case 'length':
783
- success = token.typ == EnumToken.LengthTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
680
+ success = token.typ == EnumToken.LengthTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
784
681
  break;
785
682
  case 'percentage':
786
- success = token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
683
+ success = token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
787
684
  break;
788
685
  case 'length-percentage':
789
- success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
686
+ success = token.typ == EnumToken.LengthTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
790
687
  break;
791
688
  case 'resolution':
792
- success = token.typ == EnumToken.ResolutionTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == '0') || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
689
+ success = token.typ == EnumToken.ResolutionTokenType || token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0) || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
793
690
  break;
794
691
  case 'hash-token':
795
692
  success = token.typ == EnumToken.HashTokenType;
@@ -801,7 +698,7 @@ function matchPropertyType(syntax, context, options) {
801
698
  success = token.typ == EnumToken.TimeTokenType || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
802
699
  break;
803
700
  case 'zero':
804
- success = token.val == '0' || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
701
+ success = token.val == 0 || (token.typ == EnumToken.FunctionTokenType && token.val == 'calc');
805
702
  break;
806
703
  case 'pseudo-element-selector':
807
704
  success = token.typ == EnumToken.PseudoElementTokenType;
@@ -821,9 +718,6 @@ function matchPropertyType(syntax, context, options) {
821
718
  }
822
719
  }
823
720
  break;
824
- // default:
825
- //
826
- // throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)}\n${JSON.stringify(syntax, null, 1)}`);
827
721
  }
828
722
  if (!success &&
829
723
  token.typ == EnumToken.FunctionTokenType &&
@@ -859,12 +753,7 @@ function someOf(syntaxes, context, options) {
859
753
  let success = false;
860
754
  const matched = [];
861
755
  for (i = 0; i < syntaxes.length; i++) {
862
- // if (context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType) {
863
- //
864
- // context.next();
865
- // }
866
756
  result = doEvaluateSyntax(syntaxes[i], context.clone(), options);
867
- // console.error(`>> someOf: ${JSON.stringify({result}, null, 1)}`);
868
757
  if (result.valid == SyntaxValidationResult.Valid) {
869
758
  success = true;
870
759
  if (result.context.done()) {
@@ -877,8 +766,6 @@ function someOf(syntaxes, context, options) {
877
766
  // pick the best match
878
767
  matched.sort((a, b) => a.context.done() ? -1 : b.context.done() ? 1 : b.context.index - a.context.index);
879
768
  }
880
- // console.error(JSON.stringify({matched}, null, 1));
881
- // console.error(new Error('someOf'));
882
769
  return matched[0] ?? {
883
770
  valid: SyntaxValidationResult.Drop,
884
771
  node: context.peek(),
@@ -934,10 +821,6 @@ function allOf(syntax, context, options) {
934
821
  for (i = 0; i < slice.length; i++) {
935
822
  if (slice[i].typ == EnumToken.FunctionTokenType && wildCardFuncs.includes(slice[i].val.toLowerCase())) {
936
823
  vars.push(slice[i]);
937
- // if (slice[i + 1]?.typ == EnumToken.WhitespaceTokenType) {
938
- //
939
- // vars.push(slice[++i]);
940
- // }
941
824
  continue;
942
825
  }
943
826
  if (slice[i].typ == EnumToken.CommaTokenType || (slice[i].typ == EnumToken.LiteralTokenType && slice[i].val == '/')) {
@@ -964,7 +847,6 @@ function allOf(syntax, context, options) {
964
847
  }
965
848
  while (!cp.done()) {
966
849
  result = doEvaluateSyntax(syntax[i], cp.clone(), { ...options, isOptional: false });
967
- // console.error(`>> allOf: syntaxes[${i}]: ${syntax[i].length} ${syntax[i].reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${cp.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}\n>> ${JSON.stringify({result}, null, 1)}`);
968
850
  if (result.valid == SyntaxValidationResult.Valid) {
969
851
  let end = slice.indexOf(cp.current());
970
852
  if (end == -1) {
@@ -13,17 +13,6 @@ import { splitTokenList } from '../utils/list.js';
13
13
  function validateComplexSelectorList(tokens, root, options) {
14
14
  tokens = tokens.slice();
15
15
  consumeWhitespace(tokens);
16
- // if (tokens.length == 0) {
17
- //
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // context: [],
21
- // // @ts-ignore
22
- // node: root,
23
- // syntax: null,
24
- // error: 'expecting complex selector list'
25
- // }
26
- // }
27
16
  let result = null;
28
17
  for (const t of splitTokenList(tokens)) {
29
18
  result = validateSelector(t, root, options);
@@ -12,18 +12,6 @@ function validateFamilyName(tokens, atRule) {
12
12
  let node;
13
13
  tokens = tokens.slice();
14
14
  consumeWhitespace(tokens);
15
- // if (tokens.length == 0) {
16
- //
17
- // // @ts-ignore
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // matches: [],
21
- // node: atRule,
22
- // syntax: null,
23
- // error: 'expected at-rule prelude',
24
- // tokens
25
- // } as ValidationSyntaxResult;
26
- // }
27
15
  if (tokens.length == 0 || tokens[0].typ == EnumToken.CommaTokenType) {
28
16
  // @ts-ignore
29
17
  return {
@@ -36,26 +24,6 @@ function validateFamilyName(tokens, atRule) {
36
24
  };
37
25
  }
38
26
  while (tokens.length > 0) {
39
- // @ts-ignore
40
- // if (tokens[0].typ == EnumToken.CommaTokenType) {
41
- //
42
- // node = tokens.shift() as Token;
43
- //
44
- // consumeWhitespace(tokens);
45
- //
46
- // if (tokens.length == 0) {
47
- //
48
- // // @ts-ignore
49
- // return {
50
- // valid: SyntaxValidationResult.Drop,
51
- // matches: [],
52
- // node,
53
- // syntax: null,
54
- // error: 'unexpected token',
55
- // tokens
56
- // } as ValidationSyntaxResult;
57
- // }
58
- // }
59
27
  node = tokens[0];
60
28
  if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
61
29
  // @ts-ignore
@@ -11,17 +11,6 @@ import '../../renderer/sourcemap/lib/encode.js';
11
11
 
12
12
  function validateKeyframeSelector(tokens, options) {
13
13
  consumeWhitespace(tokens);
14
- // if (tokens.length == 0) {
15
- //
16
- // // @ts-ignore
17
- // return {
18
- // valid: SyntaxValidationResult.Drop,
19
- // context: [],
20
- // node: null,
21
- // syntax: null,
22
- // error: 'expected keyframe selector'
23
- // }
24
- // }
25
14
  for (const t of splitTokenList(tokens)) {
26
15
  if (t.length != 1 || (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val)))) {
27
16
  return {
@@ -13,33 +13,7 @@ import { splitTokenList } from '../utils/list.js';
13
13
  function validateRelativeSelectorList(tokens, root, options) {
14
14
  tokens = tokens.slice();
15
15
  consumeWhitespace(tokens);
16
- // if (tokens.length == 0) {
17
- //
18
- // return {
19
- // valid: SyntaxValidationResult.Drop,
20
- // matches: [],
21
- // // @ts-ignore
22
- // node: root,
23
- // // @ts-ignore
24
- // syntax: null,
25
- // error: 'expecting relative selector list',
26
- // tokens
27
- // }
28
- // }
29
16
  for (const t of splitTokenList(tokens)) {
30
- // if (t.length == 0) {
31
- //
32
- // return {
33
- // valid: SyntaxValidationResult.Drop,
34
- // matches: [],
35
- // // @ts-ignore
36
- // node: root,
37
- // // @ts-ignore
38
- // syntax: null,
39
- // error: 'unexpected comma',
40
- // tokens
41
- // }
42
- // }
43
17
  const result = validateRelativeSelector(t, root, options);
44
18
  if (result.valid == SyntaxValidationResult.Drop) {
45
19
  return result;
@@ -9,43 +9,10 @@ import '../../renderer/sourcemap/lib/encode.js';
9
9
  import { consumeWhitespace } from '../utils/whitespace.js';
10
10
 
11
11
  function validateURL(token) {
12
- // if (token.typ == EnumToken.UrlTokenTokenType) {
13
- //
14
- // // @ts-ignore
15
- // return {
16
- // valid: SyntaxValidationResult.Valid,
17
- // context: [],
18
- // node: token,
19
- // // @ts-ignore
20
- // syntax: 'url()',
21
- // error: ''
22
- // }
23
- // }
24
- // if (token.typ != EnumToken.UrlFunctionTokenType) {
25
- //
26
- // // @ts-ignore
27
- // return {
28
- // valid: SyntaxValidationResult.Drop,
29
- // context: [],
30
- // node: token,
31
- // // @ts-ignore
32
- // syntax: 'url()',
33
- // error: 'expected url()'
34
- // }
35
- // }
36
12
  const children = token.chi.slice();
37
13
  consumeWhitespace(children);
38
14
  if (children.length > 0 && [EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
39
15
  children.shift();
40
- // @ts-ignore
41
- // return {
42
- // valid: SyntaxValidationResult.Drop,
43
- // context: [],
44
- // node: children[0] ?? token,
45
- // // @ts-ignore
46
- // syntax: 'url()',
47
- // error: 'expected url-token'
48
- // }
49
16
  }
50
17
  consumeWhitespace(children);
51
18
  if (children.length > 0) {
@@ -10,10 +10,6 @@ import '../../renderer/sourcemap/lib/encode.js';
10
10
  function stripCommaToken(tokenList) {
11
11
  let result = [];
12
12
  for (let i = 0; i < tokenList.length; i++) {
13
- // if (tokenList[i].typ == EnumToken.CommaTokenType && last != null && last.typ == EnumToken.CommaTokenType) {
14
- //
15
- // return null;
16
- // }
17
13
  if (tokenList[i].typ != EnumToken.WhitespaceTokenType) {
18
14
  tokenList[i];
19
15
  }
@@ -26,10 +22,6 @@ function stripCommaToken(tokenList) {
26
22
  }
27
23
  function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
28
24
  return tokenList.reduce((acc, curr) => {
29
- // if (curr.typ == EnumToken.CommentTokenType) {
30
- //
31
- // return acc;
32
- // }
33
25
  if (split.includes(curr.typ)) {
34
26
  acc.push([]);
35
27
  }