@tbela99/css-parser 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/CHANGELOG.md +66 -1
  2. package/README.md +14 -7
  3. package/architecture.png +0 -0
  4. package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
  5. package/dist/{src/lib/ast → ast}/arena.js +304 -139
  6. package/dist/{src/lib/ast → ast}/cache.js +40 -24
  7. package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
  8. package/dist/{src/lib/ast → ast}/features/if.js +6 -6
  9. package/dist/ast/features/index.d.ts +7 -0
  10. package/dist/{src/lib/ast → ast}/features/index.js +3 -2
  11. package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
  12. package/dist/ast/features/mixin.js +953 -0
  13. package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
  14. package/dist/ast/features/shorthand.js +129 -0
  15. package/dist/ast/features/transform.js +188 -0
  16. package/dist/{src/lib/ast → ast}/features/type.js +2 -2
  17. package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
  18. package/dist/{src/lib/ast → ast}/math/math.js +2 -2
  19. package/dist/{src/lib/ast → ast}/minify.js +745 -201
  20. package/dist/ast/mixins/custom-function.js +393 -0
  21. package/dist/ast/mixins/utils.js +53 -0
  22. package/dist/ast/mixins/variables.js +678 -0
  23. package/dist/ast/strings.js +910 -0
  24. package/dist/ast/transform/compute.js +560 -0
  25. package/dist/ast/transform/matrix.js +67 -0
  26. package/dist/ast/transform/minify.js +325 -0
  27. package/dist/ast/transform/perspective.js +24 -0
  28. package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
  29. package/dist/ast/transform/scale.js +43 -0
  30. package/dist/ast/transform/skew.js +38 -0
  31. package/dist/ast/transform/translate.js +56 -0
  32. package/dist/ast/transform/utils.js +390 -0
  33. package/dist/{src/lib/ast → ast}/types.js +2 -2
  34. package/dist/{src/lib/ast → ast}/walk.js +2 -2
  35. package/dist/{src/data → data}/properties.json.js +86 -2
  36. package/dist/{src/data → data}/validation.json.js +30 -21
  37. package/dist/{src/lib/fs → fs}/resolve.js +2 -2
  38. package/dist/index-umd-web.js +19727 -10719
  39. package/dist/index.d.ts +738 -100
  40. package/dist/{src/node.js → node.js} +70 -52
  41. package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
  42. package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
  43. package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
  44. package/dist/{src/lib/parser → parser}/input.js +18 -3
  45. package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
  46. package/dist/{src/lib/parser → parser}/parse.js +444 -278
  47. package/dist/{src/lib/parser → parser}/source.js +3 -3
  48. package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
  49. package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
  50. package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
  51. package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
  52. package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
  53. package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
  54. package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
  55. package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
  56. package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
  57. package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
  58. package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
  59. package/dist/parser/utils/cache.js +53 -0
  60. package/dist/parser/utils/canonical.js +78 -0
  61. package/dist/parser/utils/codes.js +93 -0
  62. package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
  63. package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
  64. package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
  65. package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
  66. package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
  67. package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
  68. package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
  69. package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
  70. package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
  71. package/dist/{src/lib/printer → printer}/render.js +582 -153
  72. package/dist/printer/result.js +148 -0
  73. package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
  74. package/dist/printer/writer.js +252 -0
  75. package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
  76. package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
  77. package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
  78. package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
  79. package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
  80. package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
  81. package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
  82. package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
  83. package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
  84. package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
  85. package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
  86. package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
  87. package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
  88. package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
  89. package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
  90. package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
  91. package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
  92. package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
  93. package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
  94. package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
  95. package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
  96. package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
  97. package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
  98. package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
  99. package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
  100. package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
  101. package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
  102. package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
  103. package/dist/{src/types.js → types.js} +2 -2
  104. package/dist/{src/utils → utils}/sync.js +12 -7
  105. package/dist/validation/compiled/builtins.js +32 -0
  106. package/dist/validation/compiled/runtime.js +705 -0
  107. package/dist/validation/compiled/syntaxes.js +1620 -0
  108. package/dist/{src/lib/validation → validation}/config.js +63 -16
  109. package/dist/validation/first.js +574 -0
  110. package/dist/{src/lib/validation → validation}/match.js +376 -161
  111. package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
  112. package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
  113. package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
  114. package/dist/version.js +13 -0
  115. package/dist/{src/web.js → web.js} +68 -55
  116. package/package.json +15 -13
  117. package/dist/package.json.js +0 -10
  118. package/dist/src/lib/ast/features/shorthand.js +0 -95
  119. package/dist/src/lib/ast/features/transform.js +0 -90
  120. package/dist/src/lib/ast/transform/compute.js +0 -362
  121. package/dist/src/lib/ast/transform/matrix.js +0 -88
  122. package/dist/src/lib/ast/transform/minify.js +0 -267
  123. package/dist/src/lib/ast/transform/perspective.js +0 -16
  124. package/dist/src/lib/ast/transform/scale.js +0 -39
  125. package/dist/src/lib/ast/transform/skew.js +0 -30
  126. package/dist/src/lib/ast/transform/translate.js +0 -39
  127. package/dist/src/lib/ast/transform/utils.js +0 -287
  128. package/dist/src/lib/parser/utils/cache.js +0 -54
  129. package/dist/types.d.ts +0 -21
  130. package/dist/utils/sync.d.ts +0 -16
@@ -1,18 +1,20 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { TokenField } from '../ast/arena.js';
9
- import { getParsedSyntax, hasSyntax, getSyntax, getSyntaxConfig } from './config.js';
9
+ import { syntaxKey, getParsedSyntax, hasSyntax, getSyntax, getSyntaxConfig } from './config.js';
10
10
  import { EnumToken, ColorType } from '../ast/types.js';
11
- import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
12
- import { tokensfuncDefMap, tokensfuncSet, funcLike, mFLT, mFGT } from '../syntax/constants.js';
11
+ import { ValidationTokenEnum, ValidationSyntaxGroupEnum, MediaFeatureType } from './parser/typedef.js';
12
+ import { isFunctionDefType, isFunctionType, funcLike, tokensfuncDefMap, mFLT, mFGT } from '../syntax/constants.js';
13
13
  import { isColor } from '../syntax/syntax.js';
14
14
  import { equalsIgnoreCase, lowercase } from '../parser/utils/text.js';
15
15
  import { parseTokens } from '../parser/parse.js';
16
+ import { matchingAlternatives, isNullable, mayStartWith } from './first.js';
17
+ import { compiledMatcher, matchCompiled } from './compiled/runtime.js';
16
18
 
17
19
  const config = getSyntaxConfig();
18
20
  // @ts-expect-error
@@ -165,7 +167,7 @@ function isMFValue(arena, featureName, tokens, isMFRange) {
165
167
  valid: true,
166
168
  success: tokens.length === 1 &&
167
169
  arena.dataTypes[tokens[0]] === EnumToken.IdenTokenType &&
168
- mediaFeature.values.includes(arena.strings[arena.stringValue[tokens[0]]].toLowerCase()),
170
+ mediaFeature.values.includes(arena.resolveString(arena.stringValue[tokens[0]]).toLowerCase()),
169
171
  };
170
172
  case MediaFeatureType.LengthType:
171
173
  return {
@@ -209,7 +211,7 @@ function isMFValue(arena, featureName, tokens, isMFRange) {
209
211
  arena.dataTypes[tokens[0]] === EnumToken.NumberTokenType &&
210
212
  !arena.hasFraction(tokens[0]) &&
211
213
  arena.dataTypes[tokens[1]] === EnumToken.LiteralTokenType &&
212
- arena.strings[arena.stringValue[tokens[1]]] === "/" &&
214
+ arena.resolveString(arena.stringValue[tokens[1]]) === "/" &&
213
215
  arena.dataTypes[tokens[2]] === EnumToken.NumberTokenType &&
214
216
  !arena.hasFraction(tokens[2])),
215
217
  };
@@ -267,6 +269,8 @@ class ValidationTokenContext {
267
269
  let token = this.tokens[index];
268
270
  // track balanced parens
269
271
  let matchCount = 0;
272
+ // track balanced curly braces: `{a, b}` is a single comma containing value (mixin arguments)
273
+ let blockCount = 0;
270
274
  const tokens = [];
271
275
  while (index + 1 < this.tokens.length &&
272
276
  this.arena.dataTypes[this.tokens[index + 1]] === EnumToken.WhitespaceTokenType) {
@@ -275,16 +279,22 @@ class ValidationTokenContext {
275
279
  while (index + 1 < this.tokens.length) {
276
280
  token = this.tokens[++index];
277
281
  if (this.arena.dataTypes[token] === EnumToken.StartParensTokenType ||
278
- tokensfuncDefMap.has(this.arena.dataTypes[token])) {
282
+ isFunctionDefType(this.arena.dataTypes[token])) {
279
283
  matchCount++;
280
284
  }
281
285
  else if (this.arena.dataTypes[token] === EnumToken.EndParensTokenType) {
282
286
  matchCount--;
283
287
  }
288
+ else if (this.arena.dataTypes[token] === EnumToken.BlockStartTokenType) {
289
+ blockCount++;
290
+ }
291
+ else if (this.arena.dataTypes[token] === EnumToken.BlockEndTokenType && blockCount > 0) {
292
+ blockCount--;
293
+ }
284
294
  if (matchCount >= 0) {
285
295
  tokens.push(token);
286
296
  }
287
- if (matchCount === 0) {
297
+ if (matchCount === 0 && blockCount === 0) {
288
298
  if (close !== EnumToken.EndParensTokenType && this.arena.dataTypes[token] === close) {
289
299
  counter--;
290
300
  }
@@ -305,7 +315,7 @@ class ValidationTokenContext {
305
315
  while (index + 1 < this.tokens.length) {
306
316
  token = this.tokens[++index];
307
317
  if (this.arena.dataTypes[token] === EnumToken.StartParensTokenType ||
308
- tokensfuncDefMap.has(this.arena.dataTypes[token])) {
318
+ isFunctionDefType(this.arena.dataTypes[token])) {
309
319
  matchCount++;
310
320
  }
311
321
  else if (this.arena.dataTypes[token] === EnumToken.EndParensTokenType) {
@@ -372,9 +382,9 @@ class ValidationTokenContext {
372
382
  * @param tokens
373
383
  * @returns
374
384
  */
375
- function createValidationContext(arena, tokens) {
385
+ function createValidationContext(arena, tokens, start = 0, end = tokens.length) {
376
386
  const filtered = [];
377
- for (let i = 0; i < tokens.length; i++) {
387
+ for (let i = Math.max(0, start); i < end; i++) {
378
388
  if (arena.dataTypes[tokens[i]] !== EnumToken.CommentTokenType) {
379
389
  filtered.push(tokens[i]);
380
390
  }
@@ -441,7 +451,7 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
441
451
  arena.dataTypes[token] = EnumToken.UniversalSelectorTokenType;
442
452
  }
443
453
  tokens.push(token);
444
- if (tokensfuncDefMap.has(arena.dataTypes[token])) {
454
+ if (isFunctionDefType(arena.dataTypes[token])) {
445
455
  if (stack.length > 0 && selectorNodeTypes.includes(arena.dataTypes[stack[stack.length - 1]])) {
446
456
  stack.pop();
447
457
  }
@@ -459,7 +469,7 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
459
469
  switch (arena.dataTypes[token]) {
460
470
  case EnumToken.PseudoClassFuncTokenType:
461
471
  {
462
- const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi ?? [], createValidationContext(arena, arena.tokens(token)), options);
472
+ const result = matchAllSyntaxes(arena, selectorFunctionSyntax(arena, token)?.[0]?.chi ?? [], createValidationContext(arena, arena.tokens(token)), options);
463
473
  if (!result.success) {
464
474
  success = false;
465
475
  if (result.errors.length > 0) {
@@ -500,9 +510,12 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
500
510
  case EnumToken.Tilda:
501
511
  case EnumToken.GtTokenType:
502
512
  arena.dataTypes[token] = selectorEnumMap.get(arena.dataTypes[token]);
513
+ case EnumToken.UniversalSelectorTokenType:
514
+ // `*` is a type selector, not a combinator: the whitespace that follows it is a descendant
515
+ // combinator and is kept. `.a * .b` is not `.a .b`
516
+ break;
503
517
  case EnumToken.ColumnCombinatorTokenType:
504
518
  case EnumToken.ChildCombinatorTokenType:
505
- case EnumToken.UniversalSelectorTokenType:
506
519
  case EnumToken.DescendantCombinatorTokenType:
507
520
  case EnumToken.NextSiblingCombinatorTokenType:
508
521
  case EnumToken.SubsequentSiblingCombinatorTokenType:
@@ -608,9 +621,9 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
608
621
  slice.shift();
609
622
  slice.shift();
610
623
  if (arena.dataTypes[slice[0]] === EnumToken.StringTokenType &&
611
- /^[a-zA-Z0-9_-]+$/.test(arena.strings[arena.stringValue[slice[0]]].slice(1, -1))) {
612
- // inlined: arena.setStr(slice[0], arena.strings[arena.stringValue[slice[0]]].slice(1, -1))
613
- arena.stringValue[slice[0]] = arena.internString(arena.strings[arena.stringValue[slice[0]]].slice(1, -1));
624
+ /^[a-zA-Z0-9_-]+$/.test(arena.resolveString(arena.stringValue[slice[0]]).slice(1, -1))) {
625
+ // inlined: arena.setStr(slice[0], arena.resolveString(arena.stringValue[slice[0]]).slice(1, -1))
626
+ arena.stringValue[slice[0]] = arena.internString(arena.resolveString(arena.stringValue[slice[0]]).slice(1, -1));
614
627
  arena.dataTypes[slice[0]] = EnumToken.IdenTokenType;
615
628
  }
616
629
  slice.shift();
@@ -619,8 +632,8 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
619
632
  break;
620
633
  }
621
634
  if (arena.dataTypes[slice[0]] !== EnumToken.IdenTokenType ||
622
- (arena.strings[arena.stringValue[slice[0]]] !== "i" &&
623
- arena.strings[arena.stringValue[slice[0]]] !== "s")) {
635
+ (arena.resolveString(arena.stringValue[slice[0]]) !== "i" &&
636
+ arena.resolveString(arena.stringValue[slice[0]]) !== "s")) {
624
637
  return {
625
638
  success: false,
626
639
  errors: [
@@ -670,7 +683,9 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
670
683
  arena.dataTypes[stack.at(-1)] === EnumToken.PseudoElementTokenType) {
671
684
  const token = stack.at(-1);
672
685
  const index = tokens.indexOf(token);
673
- const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi ?? [], createValidationContext(arena, tokens.slice(index + 1, tokens.length - 1)), options);
686
+ // the syntax is looked up once per function name, the tokens are read in place
687
+ const result = matchAllSyntaxes(arena, selectorFunctionSyntax(arena, token)?.[0]
688
+ ?.chi ?? [], createValidationContext(arena, tokens, index + 1, tokens.length - 1), options);
674
689
  if (!result.success) {
675
690
  success = false;
676
691
  if (result.errors.length > 0) {
@@ -754,18 +769,61 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
754
769
  ],
755
770
  };
756
771
  }
757
- stream.length = 0;
772
+ // the tokens are written in place: the stream has at least as many tokens. `stream.length = 0` would release its
773
+ // backing store, the pushes would allocate it again
758
774
  for (let i = 0; i < tokens.length; i++) {
759
- stream.push(tokens[i]);
775
+ stream[i] = tokens[i];
760
776
  }
777
+ stream.length = tokens.length;
761
778
  return { success, errors };
762
779
  }
763
780
  /**
764
781
  * declaration validations (successful and failed), by string table of the arena, by syntax and by hash of the value
765
- * encoding (see {@link encodeToken}). the encoding contains interned string ids: the string table is the key, it is
766
- * replaced when the arena is compacted and the ids change (see {@link AstArena.compact})
782
+ * encoding (see {@link encodeToken}). the encoding contains interned string ids: the identity of the string ids is the
783
+ * key, it is replaced when the arena is compacted and the ids change (see {@link AstArena.stringEpoch})
767
784
  */
768
785
  const declarationValidations = new WeakMap();
786
+ /**
787
+ * the validation cache of the string table of an arena
788
+ * @param arena
789
+ * @param create create the cache when missing
790
+ */
791
+ function validationCache(arena, create) {
792
+ let cache = declarationValidations.get(arena.stringEpoch);
793
+ if (cache === undefined) {
794
+ if (!create) {
795
+ return null;
796
+ }
797
+ cache = { bySyntax: new Map(), pool: new Float64Array(1024), used: 0 };
798
+ declarationValidations.set(arena.stringEpoch, cache);
799
+ }
800
+ return cache;
801
+ }
802
+ /**
803
+ * copy the current encoding into the pool of the cache (see {@link ValidationCache.pool})
804
+ * @param arena
805
+ * @returns the offset of the encoding in the pool
806
+ */
807
+ function storeEncoding(arena) {
808
+ const cache = validationCache(arena, true);
809
+ const offset = cache.used;
810
+ if (offset + encodingLength > cache.pool.length) {
811
+ let length = cache.pool.length * 2;
812
+ while (length < offset + encodingLength) {
813
+ length *= 2;
814
+ }
815
+ const pool = new Float64Array(length);
816
+ pool.set(cache.pool.subarray(0, offset));
817
+ cache.pool = pool;
818
+ }
819
+ const pool = cache.pool;
820
+ // a loop: subarray() would allocate a view
821
+ for (let i = 0; i < encodingLength; i++) {
822
+ pool[offset + i] = encoding[i];
823
+ }
824
+ cache.used = offset + encodingLength;
825
+ return offset;
826
+ }
769
827
  /**
770
828
  * shared result of a declaration whose validation is cached
771
829
  */
@@ -785,6 +843,10 @@ const cachedValidMatch = Object.freeze({
785
843
  let encoding = new Float64Array(512);
786
844
  let encodingLength = 0;
787
845
  let encodingHash = 0;
846
+ /**
847
+ * true if the encoded value contains a token the compiled matchers do not handle (var(), a custom function call, ...): the interpreter validates the value, see {@link compiledVerdict}
848
+ */
849
+ let encodingBail = false;
788
850
  /**
789
851
  * append a value to the encoding and update its hash
790
852
  * @param value
@@ -800,14 +862,27 @@ function encode(value) {
800
862
  }
801
863
  /**
802
864
  * encode a token and its descendants. the validation only depends on these fields: two values with the same encoding
803
- * are validated the same way
865
+ * are validated the same way. the errors of a failed validation do not depend on the content of the strings either:
866
+ * they reference the tokens by position and their messages only contain token types
804
867
  * @param arena
805
868
  * @param token
806
869
  */
807
870
  function encodeToken(arena, token) {
808
- encode(arena.dataTypes[token]);
871
+ const typ = arena.dataTypes[token];
872
+ if (typ === EnumToken.WildCardFunctionTokenType ||
873
+ typ === EnumToken.WildCardFunctionTokenDefType ||
874
+ typ === EnumToken.CustomFunctionTokenType ||
875
+ typ === EnumToken.CustomFunctionTokenDefType ||
876
+ typ === EnumToken.BadCdoTokenType ||
877
+ typ === EnumToken.BadCommentTokenType ||
878
+ typ === EnumToken.BadStringTokenType) {
879
+ encodingBail = true;
880
+ }
881
+ encode(typ);
809
882
  encode(arena.name[token]);
810
- encode(arena.stringValue[token]);
883
+ // the validation does not read the content of the strings (only their type): `content: "\f101"` and
884
+ // `content: "\f102"` are validated once
885
+ encode(typ === EnumToken.StringTokenType ? 0 : arena.stringValue[token]);
811
886
  encode(arena.numericValue[token]);
812
887
  encode(arena.unit[token]);
813
888
  encode(arena.colorType[token]);
@@ -833,14 +908,11 @@ function encodeToken(arena, token) {
833
908
  * @param create create the bucket when missing
834
909
  */
835
910
  function cachedValidations(arena, syntaxes, create) {
836
- let bySyntax = declarationValidations.get(arena.strings);
837
- if (bySyntax == null) {
838
- if (!create) {
839
- return null;
840
- }
841
- bySyntax = new Map();
842
- declarationValidations.set(arena.strings, bySyntax);
911
+ const cache = validationCache(arena, create);
912
+ if (cache === null) {
913
+ return null;
843
914
  }
915
+ const bySyntax = cache.bySyntax;
844
916
  let byHash = bySyntax.get(syntaxes);
845
917
  if (byHash == null) {
846
918
  if (!create) {
@@ -864,11 +936,12 @@ function cachedValidations(arena, syntaxes, create) {
864
936
  function findValidation(arena, syntaxes) {
865
937
  const bucket = cachedValidations(arena, syntaxes, false);
866
938
  if (bucket != null) {
939
+ const pool = validationCache(arena, false).pool;
867
940
  for (let i = 0; i < bucket.length; i++) {
868
- const candidate = bucket[i].encoding;
869
- if (candidate.length === encodingLength) {
941
+ const offset = bucket[i].offset;
942
+ if (bucket[i].length === encodingLength) {
870
943
  let k = 0;
871
- while (k < encodingLength && candidate[k] === encoding[k]) {
944
+ while (k < encodingLength && pool[offset + k] === encoding[k]) {
872
945
  k++;
873
946
  }
874
947
  if (k === encodingLength) {
@@ -883,14 +956,15 @@ function findValidation(arena, syntaxes) {
883
956
  * cache the validation of an encoding for the syntax
884
957
  * @param arena
885
958
  * @param syntaxes
886
- * @param value encoding
959
+ * @param offset offset of the encoding in the pool of the cache, see {@link storeEncoding}
960
+ * @param length length of the encoding
887
961
  * @param hash encoding hash
888
962
  * @param valid
889
963
  * @param errors errors of a failed validation, null when unknown
890
964
  */
891
- function cacheValidation(arena, syntaxes, value, hash, valid, errors) {
965
+ function cacheValidation(arena, syntaxes, offset, length, hash, valid, errors) {
892
966
  encodingHash = hash;
893
- cachedValidations(arena, syntaxes, true).push({ encoding: value, valid, errors });
967
+ cachedValidations(arena, syntaxes, true).push({ offset, length, valid, errors });
894
968
  }
895
969
  /**
896
970
  * the value tokens and their descendants, in the encoding order (see {@link encodeToken})
@@ -961,10 +1035,9 @@ function bindErrors(arena, tokens, errors, options) {
961
1035
  }
962
1036
  }
963
1037
  }
964
- const copy = { ...error };
965
- delete copy.node;
966
- delete copy.location;
967
- result.push({ error: copy, node, location });
1038
+ // the node and the location keep their place in the keys: they are replaced when the errors are rebuilt, the
1039
+ // rebuilt errors have the same shape as the errors of a validation
1040
+ result.push({ error: { ...error }, node, location });
968
1041
  }
969
1042
  return result;
970
1043
  }
@@ -1005,6 +1078,36 @@ function valueTokens(arena, tokens) {
1005
1078
  }
1006
1079
  return result;
1007
1080
  }
1081
+ /**
1082
+ * the compiled matchers of the syntaxes, null when the syntaxes are not compiled
1083
+ */
1084
+ const compiledMatchers = new WeakMap();
1085
+ /**
1086
+ * true if the value is valid according to the compiled matcher of the syntax. false: the interpreter must validate it
1087
+ * (the value may be valid). the value must be encoded (see {@link encodeToken})
1088
+ * @param arena
1089
+ * @param syntaxes
1090
+ * @param tokens
1091
+ * @param options
1092
+ */
1093
+ function compiledVerdict(arena, syntaxes, tokens, options) {
1094
+ if (encodingBail) {
1095
+ return false;
1096
+ }
1097
+ let matcher = compiledMatchers.get(syntaxes);
1098
+ if (matcher === undefined) {
1099
+ const key = syntaxKey(syntaxes);
1100
+ matcher = key === null ? null : compiledMatcher(key);
1101
+ compiledMatchers.set(syntaxes, matcher);
1102
+ }
1103
+ if (matcher === null) {
1104
+ return false;
1105
+ }
1106
+ if (!matchCompiled(arena, matcher, tokens, options)) {
1107
+ return false;
1108
+ }
1109
+ return true;
1110
+ }
1008
1111
  /**
1009
1112
  * validate the value of a declaration. a value that has already been validated for the same syntax in the same arena
1010
1113
  * (same encoding, see {@link encodeToken}) is not validated again: `width: 10px` is validated once, whatever the number
@@ -1017,10 +1120,15 @@ function valueTokens(arena, tokens) {
1017
1120
  function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
1018
1121
  encodingLength = 0;
1019
1122
  encodingHash = 0x811c9dc5;
1123
+ encodingBail = false;
1020
1124
  for (let i = 0; i < tokens.length; i++) {
1021
1125
  encodeToken(arena, tokens[i]);
1022
1126
  }
1023
1127
  const cached = findValidation(arena, syntaxes);
1128
+ if (cached == null && compiledVerdict(arena, syntaxes, tokens, options)) {
1129
+ cacheValidation(arena, syntaxes, storeEncoding(arena), encodingLength, encodingHash, true, null);
1130
+ return cachedValidMatch;
1131
+ }
1024
1132
  if (cached != null) {
1025
1133
  if (cached.valid) {
1026
1134
  return cachedValidMatch;
@@ -1036,12 +1144,13 @@ function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
1036
1144
  };
1037
1145
  }
1038
1146
  }
1039
- // the encoding is copied before the validation, which may encode other values
1040
- const value = encoding.slice(0, encodingLength);
1147
+ // the encoding is stored before the validation, which may encode other values
1148
+ const length = encodingLength;
1149
+ const offset = storeEncoding(arena);
1041
1150
  const hash = encodingHash;
1042
1151
  const result = matchAllSyntaxes(arena, syntaxes, createValidationContext(arena, tokens), options);
1043
1152
  if (result.success) {
1044
- cacheValidation(arena, syntaxes, value, hash, true, null);
1153
+ cacheValidation(arena, syntaxes, offset, length, hash, true, null);
1045
1154
  }
1046
1155
  else {
1047
1156
  const errors = bindErrors(arena, valueTokens(arena, tokens), result.errors, options);
@@ -1050,7 +1159,7 @@ function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
1050
1159
  cached.errors = errors;
1051
1160
  }
1052
1161
  else {
1053
- cacheValidation(arena, syntaxes, value, hash, false, errors);
1162
+ cacheValidation(arena, syntaxes, offset, length, hash, false, errors);
1054
1163
  }
1055
1164
  }
1056
1165
  return result;
@@ -1067,6 +1176,7 @@ function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
1067
1176
  function isValidDeclarationValue(arena, syntaxes, declaration, options) {
1068
1177
  encodingLength = 0;
1069
1178
  encodingHash = 0x811c9dc5;
1179
+ encodingBail = false;
1070
1180
  for (let token = arena.firstToken[declaration]; token !== 0; token = arena.nextSibling[token]) {
1071
1181
  encodeToken(arena, token);
1072
1182
  }
@@ -1074,14 +1184,66 @@ function isValidDeclarationValue(arena, syntaxes, declaration, options) {
1074
1184
  if (cached != null) {
1075
1185
  return cached.valid;
1076
1186
  }
1077
- // the encoding is copied before the validation, which may encode other values
1078
- const value = encoding.slice(0, encodingLength);
1187
+ if (compiledVerdict(arena, syntaxes, arena.tokens(declaration), options)) {
1188
+ cacheValidation(arena, syntaxes, storeEncoding(arena), encodingLength, encodingHash, true, null);
1189
+ return true;
1190
+ }
1191
+ // the encoding is stored before the validation, which may encode other values
1192
+ const length = encodingLength;
1193
+ const offset = storeEncoding(arena);
1079
1194
  const hash = encodingHash;
1080
1195
  const valid = matchAllSyntaxes(arena, syntaxes, createValidationContext(arena, arena.tokens(declaration)), options).success;
1081
1196
  // the errors are not needed: they are computed if a declaration with the same value is validated by the parser
1082
- cacheValidation(arena, syntaxes, value, hash, valid, null);
1197
+ cacheValidation(arena, syntaxes, offset, length, hash, valid, null);
1083
1198
  return valid;
1084
1199
  }
1200
+ /**
1201
+ * the syntaxes being matched and the token they are matched at (a stack, see {@link enterSyntax}): a syntax that is
1202
+ * matched again at the same token while it is being matched is a cyclic definition. the matched syntaxes are set to
1203
+ * null. the entries of a call of {@link matchAllSyntaxes} start at {@link visitedBase}
1204
+ */
1205
+ let visitedTokens = new Int32Array(256);
1206
+ /**
1207
+ * see {@link visitedTokens}
1208
+ */
1209
+ const visitedSyntaxes = [];
1210
+ /**
1211
+ * number of entries of {@link visitedTokens}
1212
+ */
1213
+ let visitedLength = 0;
1214
+ /**
1215
+ * first entry of the current call of {@link matchAllSyntaxes}
1216
+ */
1217
+ let visitedBase = 0;
1218
+ /**
1219
+ * true if a syntax is being matched at a token
1220
+ * @param token
1221
+ * @param syntax
1222
+ */
1223
+ function isVisited(token, syntax) {
1224
+ for (let i = visitedBase; i < visitedLength; i++) {
1225
+ if (visitedTokens[i] === token && visitedSyntaxes[i] === syntax) {
1226
+ return true;
1227
+ }
1228
+ }
1229
+ return false;
1230
+ }
1231
+ /**
1232
+ * record that a syntax is being matched at a token
1233
+ * @param token
1234
+ * @param syntax
1235
+ * @returns the entry, released when the syntax is no longer being matched (`visitedLength = entry`)
1236
+ */
1237
+ function enterSyntax(token, syntax) {
1238
+ if (visitedLength === visitedTokens.length) {
1239
+ const tokens = new Int32Array(visitedTokens.length * 2);
1240
+ tokens.set(visitedTokens);
1241
+ visitedTokens = tokens;
1242
+ }
1243
+ visitedTokens[visitedLength] = token;
1244
+ visitedSyntaxes[visitedLength] = syntax;
1245
+ return visitedLength++;
1246
+ }
1085
1247
  /**
1086
1248
  * matches all syntaxes
1087
1249
  * @param arena
@@ -1091,17 +1253,19 @@ function isValidDeclarationValue(arena, syntaxes, declaration, options) {
1091
1253
  * @returns
1092
1254
  */
1093
1255
  function matchAllSyntaxes(arena, syntaxes, context, options) {
1094
- // the visited syntaxes are tracked per call. the options are not copied: the previous map is restored
1095
- const visited = options.visited;
1256
+ // the syntaxes being matched are tracked per call: the syntaxes being matched by the caller are not seen
1257
+ const base = visitedBase;
1258
+ const length = visitedLength;
1096
1259
  // the result object is passed to the matching functions, which fill it
1097
1260
  const out = createMatch();
1098
1261
  let result;
1099
- options.visited = new Map();
1262
+ visitedBase = visitedLength;
1100
1263
  try {
1101
1264
  result = matchSyntax(arena, syntaxes, context, options, out);
1102
1265
  }
1103
1266
  finally {
1104
- options.visited = visited;
1267
+ visitedBase = base;
1268
+ visitedLength = length;
1105
1269
  }
1106
1270
  if (syntaxes != null && result.success && result.syntaxToken != null) {
1107
1271
  const index = syntaxes.indexOf(result.syntaxToken);
@@ -1288,46 +1452,6 @@ function matchOccurenceSyntax(arena, syntax, context, options) {
1288
1452
  * @param options
1289
1453
  * @returns
1290
1454
  */
1291
- /**
1292
- * the syntaxes that may match no token, see {@link isNullable}
1293
- */
1294
- const nullableSyntaxes = new WeakMap();
1295
- /**
1296
- * true if the syntax may match no token: `<a>?`, `<a>*`, `[ <a>? <b>? ]`, `[ [ and <a> ]* | [ or <a> ]* ]`
1297
- * @param syntax
1298
- */
1299
- function isNullable(syntax) {
1300
- if (syntax.typ === ValidationTokenEnum.Whitespace) {
1301
- return true;
1302
- }
1303
- // `[ <a>? <b>? ]!`: at least one token
1304
- if (syntax.isMandatatoryGroup) {
1305
- return false;
1306
- }
1307
- if (syntax.isOptional || syntax.isRepeatable || syntax.match?.min?.val === 0) {
1308
- return true;
1309
- }
1310
- let nullable = nullableSyntaxes.get(syntax);
1311
- if (nullable == null) {
1312
- switch (syntax.typ) {
1313
- case ValidationTokenEnum.Bracket:
1314
- nullable = syntax.chi.every(isNullable);
1315
- break;
1316
- case ValidationTokenEnum.PipeToken:
1317
- nullable = syntax.chi.some((syntaxes) => syntaxes.every(isNullable));
1318
- break;
1319
- case ValidationTokenEnum.AmpersandToken:
1320
- nullable =
1321
- syntax.l.every(isNullable) &&
1322
- syntax.r.every(isNullable);
1323
- break;
1324
- default:
1325
- nullable = false;
1326
- }
1327
- nullableSyntaxes.set(syntax, nullable);
1328
- }
1329
- return nullable;
1330
- }
1331
1455
  /**
1332
1456
  * index of the first syntax that must be matched, starting at index. -1 if the remaining syntaxes may match no token
1333
1457
  * @param syntaxes
@@ -1341,6 +1465,23 @@ function findMandatorySyntax(syntaxes, index) {
1341
1465
  }
1342
1466
  return -1;
1343
1467
  }
1468
+ /**
1469
+ * true if a token is a literal number or dimension of a syntax: `0`, `90deg`. the unit is case-insensitive
1470
+ * @param arena
1471
+ * @param token
1472
+ * @param syntax
1473
+ */
1474
+ function isLiteralNumber(arena, token, syntax) {
1475
+ if (arena.hasFraction(token) || arena.numericValue[token] !== syntax.val) {
1476
+ return false;
1477
+ }
1478
+ if (syntax.typ === ValidationTokenEnum.Number) {
1479
+ return arena.dataTypes[token] === EnumToken.NumberTokenType;
1480
+ }
1481
+ const type = EnumToken[syntax.unit];
1482
+ return (arena.dataTypes[token] === type &&
1483
+ equalsIgnoreCase(arena.resolveString(arena.unit[token]), syntax.unitText));
1484
+ }
1344
1485
  /**
1345
1486
  * true if a numeric token is in the range of the syntax: `<integer [1,∞]>`
1346
1487
  * @param arena
@@ -1370,12 +1511,49 @@ function isInRange(arena, token, syntax) {
1370
1511
  }
1371
1512
  return success;
1372
1513
  }
1514
+ /**
1515
+ * the validation syntax of a function token (`name()`): looked up once per function name
1516
+ * @param arena
1517
+ * @param token
1518
+ */
1519
+ function functionSyntax(arena, token) {
1520
+ syntaxArena = arena;
1521
+ return arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
1522
+ }
1523
+ /**
1524
+ * the arena of the function names read by {@link computeFunctionSyntax} and {@link computeSelectorFunctionSyntax}:
1525
+ * the functions passed to the string table are not closures (no allocation per call)
1526
+ */
1527
+ let syntaxArena = null;
1528
+ /**
1529
+ * see {@link functionSyntax}
1530
+ * @param id
1531
+ */
1532
+ function computeFunctionSyntax(id) {
1533
+ return getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxArena.resolveString(id) + "()");
1534
+ }
1535
+ /**
1536
+ * see {@link selectorFunctionSyntax}
1537
+ * @param id
1538
+ */
1539
+ function computeSelectorFunctionSyntax(id) {
1540
+ return getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, syntaxArena.resolveString(id) + "()");
1541
+ }
1542
+ /**
1543
+ * the validation syntax of a selector function token (`:name()`): looked up once per function name
1544
+ * @param arena
1545
+ * @param token
1546
+ */
1547
+ function selectorFunctionSyntax(arena, token) {
1548
+ syntaxArena = arena;
1549
+ return arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
1550
+ }
1373
1551
  /**
1374
1552
  * the wildcard functions being matched with a syntax, see {@link matchWildCardFunction}
1375
1553
  */
1376
1554
  const wildCardProbes = new Map();
1377
1555
  /**
1378
- * var(), env() and if() may be substituted by any number of values. the function is matched:
1556
+ * var(), env(), if() and the custom function calls may be substituted by any number of values. the function is matched:
1379
1557
  * - as a part of the syntax at index: `var(--color) 65%` is matched by `<linear-color-stop>` (`<color>` is the function)
1380
1558
  * - as the syntax at index, or as all the remaining syntaxes when it is the last token
1381
1559
  *
@@ -1494,7 +1672,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1494
1672
  let isOptional;
1495
1673
  if (context.tokens.length === 1 &&
1496
1674
  arena.dataTypes[context.tokens[0]] === EnumToken.IdenTokenType &&
1497
- isCssWideKeyword(arena.strings[arena.stringValue[context.tokens[0]]])) {
1675
+ isCssWideKeyword(arena.resolveString(arena.stringValue[context.tokens[0]]))) {
1498
1676
  context.end();
1499
1677
  return setMatch(out, true, true, context.peek(), context, null, noErrors);
1500
1678
  }
@@ -1524,9 +1702,9 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1524
1702
  break;
1525
1703
  }
1526
1704
  if (arena.dataTypes[token] === EnumToken.WildCardFunctionTokenType &&
1527
- arena.strings[arena.stringValue[token]] === "var" &&
1705
+ arena.resolveString(arena.stringValue[token]) === "var" &&
1528
1706
  wildCardProbes.get(token) !== syntaxes[i]) {
1529
- result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi, createValidationContext(arena, arena.tokens(token)), options, out);
1707
+ result = matchSyntax(arena, functionSyntax(arena, token)?.[0]?.chi, createValidationContext(arena, arena.tokens(token)), options, out);
1530
1708
  if (result.success && result.context.done()) {
1531
1709
  const wildCardResult = matchWildCardFunction(arena, syntaxes, i, context, token, token, options, out);
1532
1710
  if (wildCardResult == null) {
@@ -1535,12 +1713,27 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1535
1713
  return wildCardResult;
1536
1714
  }
1537
1715
  }
1716
+ // a custom function call (`--fn()`) is substituted by the result of the function: like var(), it may be
1717
+ // substituted by any number of values
1718
+ if ((arena.dataTypes[token] === EnumToken.CustomFunctionTokenType ||
1719
+ arena.dataTypes[token] === EnumToken.CustomFunctionTokenDefType) &&
1720
+ wildCardProbes.get(token) !== syntaxes[i]) {
1721
+ const wildCardResult = matchWildCardFunction(arena, syntaxes, i, context, token,
1722
+ // the arguments of the call are not validated: they are the arguments of the custom function
1723
+ arena.dataTypes[token] === EnumToken.CustomFunctionTokenDefType
1724
+ ? trimArray(arena, context.peekRange()).at(-1)
1725
+ : token, options, out);
1726
+ if (wildCardResult == null) {
1727
+ continue;
1728
+ }
1729
+ return wildCardResult;
1730
+ }
1538
1731
  if (
1539
1732
  // @ts-ignore
1540
1733
  arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType &&
1541
1734
  wildCardProbes.get(token) !== syntaxes[i]) {
1542
1735
  const range = trimArray(arena, context.peekRange());
1543
- result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi, createValidationContext(arena, range.slice(1, -1)), options, out);
1736
+ result = matchSyntax(arena, functionSyntax(arena, token)?.[0]?.chi, createValidationContext(arena, range, 1, range.length - 1), options, out);
1544
1737
  if (result.success) {
1545
1738
  const wildCardResult = matchWildCardFunction(arena, syntaxes, i, context, token, range.at(-1), options, out);
1546
1739
  if (wildCardResult == null) {
@@ -1567,7 +1760,6 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1567
1760
  if (syntaxes[i].isList) {
1568
1761
  result = matchListSyntax(arena, syntaxes[i], context.slice(), options);
1569
1762
  if (result.success) {
1570
- options.visited.get(token)?.delete?.(syntaxes[i]);
1571
1763
  if (result.context.done()) {
1572
1764
  context.end();
1573
1765
  return setDoneMatch(out, syntaxes, i + 1, true, null, context, result.errors);
@@ -1583,7 +1775,6 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1583
1775
  if (syntaxes[i].match != null) {
1584
1776
  result = matchOccurenceSyntax(arena, syntaxes[i], context.slice(), options);
1585
1777
  if (result.success) {
1586
- options.visited.get(token).delete(syntaxes[i]);
1587
1778
  if (result.context.done()) {
1588
1779
  context.end();
1589
1780
  return setDoneMatch(out, syntaxes, i + 1, result.valid, result.token, context, result.errors);
@@ -1596,14 +1787,12 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1596
1787
  }
1597
1788
  return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
1598
1789
  }
1599
- if (!options.visited.has(token)) {
1600
- options.visited.set(token, new Set());
1601
- }
1602
- if (options.visited.get(token).has(syntaxes[i])) {
1790
+ if (isVisited(token, syntaxes[i])) {
1603
1791
  // cyclic definition
1604
1792
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1605
1793
  }
1606
- options.visited.get(token).add(syntaxes[i]);
1794
+ // the syntax is being matched at the token, until it is matched (see visitedSyntaxes)
1795
+ const visit = enterSyntax(token, syntaxes[i]);
1607
1796
  success = false;
1608
1797
  try {
1609
1798
  switch (syntaxes[i].typ) {
@@ -1621,17 +1810,17 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1621
1810
  case ValidationTokenEnum.Comma:
1622
1811
  if (arena.dataTypes[token] === EnumToken.CommaTokenType) {
1623
1812
  success = true;
1624
- options.visited.get(token).delete(syntaxes[i]);
1813
+ visitedSyntaxes[visit] = null;
1625
1814
  context.next();
1626
1815
  break;
1627
1816
  }
1628
1817
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1629
1818
  case ValidationTokenEnum.Keyword:
1630
1819
  if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
1631
- lowercase(arena.strings[arena.stringValue[token]]) ===
1820
+ lowercase(arena.resolveString(arena.stringValue[token])) ===
1632
1821
  lowercase(syntaxes[i].val)) {
1633
1822
  success = true;
1634
- options.visited.get(token).delete(syntaxes[i]);
1823
+ visitedSyntaxes[visit] = null;
1635
1824
  context.next();
1636
1825
  break;
1637
1826
  }
@@ -1643,7 +1832,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1643
1832
  result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val), context, options, out);
1644
1833
  if (result.success) {
1645
1834
  success = true;
1646
- options.visited.get(token).delete(syntaxes[i]);
1835
+ visitedSyntaxes[visit] = null;
1647
1836
  if (result.context.done()) {
1648
1837
  context.end();
1649
1838
  return setDoneMatch(out, syntaxes, i + 1, result.valid, token, context, result.errors);
@@ -1702,7 +1891,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1702
1891
  }
1703
1892
  else if (arena.dataTypes[token] === EnumToken.LiteralTokenType) {
1704
1893
  success =
1705
- arena.strings[arena.stringValue[token]] ===
1894
+ arena.resolveString(arena.stringValue[token]) ===
1706
1895
  syntaxes[i].val.slice(1, -1);
1707
1896
  }
1708
1897
  else if (arena.dataTypes[token] === EnumToken.Plus) {
@@ -1725,7 +1914,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1725
1914
  return setMatch(out, false, true, context.current() ?? token, context, syntaxes[i], noErrors);
1726
1915
  }
1727
1916
  success = true;
1728
- options.visited.get(token).delete(syntaxes[i]);
1917
+ visitedSyntaxes[visit] = null;
1729
1918
  if (result.context.done()) {
1730
1919
  if (!isInRange(arena, token, syntaxes[i])) {
1731
1920
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
@@ -1741,9 +1930,15 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1741
1930
  {
1742
1931
  // each alternative is matched in the same scratch result, the best match is copied
1743
1932
  const scratch = createMatch();
1933
+ const alternatives = syntaxes[i].chi;
1934
+ // the alternatives that may match the token, in order (see matchingAlternatives()): the other
1935
+ // alternatives cannot match it. null: all the alternatives
1936
+ const candidates = matchingAlternatives(arena, alternatives, token);
1937
+ const count = candidates === null ? alternatives.length : candidates.length;
1744
1938
  let best = null;
1745
1939
  let tmp = null;
1746
- for (const syntax of syntaxes[i].chi) {
1940
+ for (let k = 0; k < count; k++) {
1941
+ const syntax = alternatives[candidates === null ? k : candidates[k]];
1747
1942
  tmp = matchSyntax(arena, syntax, context.slice(), options, scratch);
1748
1943
  if (tmp.success) {
1749
1944
  // an alternative that consumes the tokens is skipped if mandatory syntaxes remain
@@ -1762,7 +1957,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1762
1957
  result = best;
1763
1958
  if (result?.success) {
1764
1959
  success = true;
1765
- options.visited.get(token).delete(syntaxes[i]);
1960
+ visitedSyntaxes[visit] = null;
1766
1961
  context.update(result.context.current());
1767
1962
  break;
1768
1963
  }
@@ -1781,7 +1976,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1781
1976
  result = matchSyntax(arena, syntaxes[i].chi, context.slice(), options, out);
1782
1977
  if (result.success) {
1783
1978
  success = true;
1784
- options.visited.get(token).delete(syntaxes[i]);
1979
+ visitedSyntaxes[visit] = null;
1785
1980
  if (result.context.done()) {
1786
1981
  context.end();
1787
1982
  return setDoneMatch(out, syntaxes, i + 1, true, null, context, noErrors);
@@ -1799,7 +1994,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1799
1994
  result = matchColumnSyntax(arena, syntaxes[i], context.slice(), options);
1800
1995
  if (result.success) {
1801
1996
  success = true;
1802
- options.visited.get(token).delete(syntaxes[i]);
1997
+ visitedSyntaxes[visit] = null;
1803
1998
  if (result.context.done()) {
1804
1999
  context.end();
1805
2000
  return setDoneMatch(out, syntaxes, i + 1, true, null, context, noErrors);
@@ -1814,7 +2009,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1814
2009
  result = matchAmpersandSyntax(arena, syntaxes[i], context.slice(), options);
1815
2010
  if (result.success) {
1816
2011
  success = true;
1817
- options.visited.get(token).delete(syntaxes[i]);
2012
+ visitedSyntaxes[visit] = null;
1818
2013
  if (result.context.done()) {
1819
2014
  context.end();
1820
2015
  return setDoneMatch(out, syntaxes, i + 1, true, null, context, noErrors);
@@ -1826,10 +2021,10 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1826
2021
  }
1827
2022
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1828
2023
  case ValidationTokenEnum.Function:
1829
- if ((!tokensfuncDefMap.has(arena.dataTypes[token]) &&
2024
+ if ((!isFunctionDefType(arena.dataTypes[token]) &&
1830
2025
  !funcLike.includes(arena.dataTypes[token]) &&
1831
2026
  !funcTypes.includes(arena.dataTypes[token])) ||
1832
- !equalsIgnoreCase(syntaxes[i].val, arena.strings[arena.stringValue[token]].toLowerCase())) {
2027
+ !equalsIgnoreCase(syntaxes[i].val, arena.resolveString(arena.stringValue[token]).toLowerCase())) {
1833
2028
  return setMatch(out, false, true, token, context, syntaxes[i], [
1834
2029
  {
1835
2030
  action: "drop",
@@ -1838,12 +2033,12 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1838
2033
  },
1839
2034
  ]);
1840
2035
  }
1841
- if (tokensfuncDefMap.has(arena.dataTypes[token])) {
2036
+ if (isFunctionDefType(arena.dataTypes[token])) {
1842
2037
  const range = context.peekRange();
1843
- result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, range.slice(1, -1)), options, out);
2038
+ result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, range, 1, range.length - 1), options, out);
1844
2039
  if (result.success && result.context.done()) {
1845
2040
  context.update(range.at(-1));
1846
- options.visited.get(token).delete(syntaxes[i]);
2041
+ visitedSyntaxes[visit] = null;
1847
2042
  break;
1848
2043
  }
1849
2044
  }
@@ -1851,38 +2046,52 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1851
2046
  result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, arena.tokens(token)), options, out);
1852
2047
  if (result.success && result.context.done()) {
1853
2048
  success = true;
1854
- options.visited.get(token).delete(syntaxes[i]);
2049
+ visitedSyntaxes[visit] = null;
1855
2050
  context.next();
1856
2051
  break;
1857
2052
  }
1858
2053
  }
1859
2054
  return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
2055
+ case ValidationTokenEnum.Number:
2056
+ case ValidationTokenEnum.Dimension:
2057
+ // a literal number or dimension: `-moz-force-broken-image-icon: 0 | 1`,
2058
+ // `glyph-orientation-vertical: auto | 0deg | 90deg | 0 | 90`
2059
+ if (isLiteralNumber(arena, token, syntaxes[i])) {
2060
+ success = true;
2061
+ visitedSyntaxes[visit] = null;
2062
+ context.next();
2063
+ break;
2064
+ }
2065
+ if (isOptional) {
2066
+ break;
2067
+ }
2068
+ return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1860
2069
  case ValidationTokenEnum.Separator:
1861
2070
  if (arena.dataTypes[token] === EnumToken.LiteralTokenType &&
1862
- arena.strings[arena.stringValue[token]] === "/") {
1863
- options.visited.get(token).delete(syntaxes[i]);
2071
+ arena.resolveString(arena.stringValue[token]) === "/") {
2072
+ visitedSyntaxes[visit] = null;
1864
2073
  context.next();
1865
2074
  break;
1866
2075
  }
1867
2076
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1868
2077
  case ValidationTokenEnum.FunctionDefinition:
1869
- if (arena.strings[arena.stringValue[token]] &&
1870
- equalsIgnoreCase(arena.strings[arena.stringValue[token]], syntaxes[i].val)) {
1871
- if (tokensfuncDefMap.has(arena.dataTypes[token])) {
2078
+ if (arena.resolveString(arena.stringValue[token]) &&
2079
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), syntaxes[i].val)) {
2080
+ if (isFunctionDefType(arena.dataTypes[token])) {
1872
2081
  const children = trimArray(arena, context.peekRange());
1873
- result = matchSyntax(arena, (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(arena, children.slice(1, -1)), options, out);
2082
+ result = matchSyntax(arena, (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(arena, children, 1, children.length - 1), options, out);
1874
2083
  if (result.success && result.context.done()) {
1875
2084
  success = true;
1876
- options.visited.get(token).delete(syntaxes[i]);
2085
+ visitedSyntaxes[visit] = null;
1877
2086
  context.update(children.at(-1));
1878
2087
  break;
1879
2088
  }
1880
2089
  }
1881
- else if (tokensfuncSet.has(arena.dataTypes[token])) {
2090
+ else if (isFunctionType(arena.dataTypes[token])) {
1882
2091
  result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()") ?? [], createValidationContext(arena, [token]), options, out);
1883
2092
  if (result.success && result.context.done()) {
1884
2093
  success = true;
1885
- options.visited.get(token).delete(syntaxes[i]);
2094
+ visitedSyntaxes[visit] = null;
1886
2095
  context.next();
1887
2096
  break;
1888
2097
  }
@@ -1891,21 +2100,21 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1891
2100
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1892
2101
  case ValidationTokenEnum.OpenParenthesis:
1893
2102
  if (arena.dataTypes[token] === EnumToken.StartParensTokenType) {
1894
- options.visited.get(token).delete(syntaxes[i]);
2103
+ visitedSyntaxes[visit] = null;
1895
2104
  context.next();
1896
2105
  break;
1897
2106
  }
1898
2107
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1899
2108
  case ValidationTokenEnum.OpenCurlyBrace:
1900
2109
  if (arena.dataTypes[token] === EnumToken.BlockStartTokenType) {
1901
- options.visited.get(token).delete(syntaxes[i]);
2110
+ visitedSyntaxes[visit] = null;
1902
2111
  context.next();
1903
2112
  break;
1904
2113
  }
1905
2114
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
1906
2115
  case ValidationTokenEnum.CloseParenthesis:
1907
2116
  if (arena.dataTypes[token] === EnumToken.EndParensTokenType) {
1908
- options.visited.get(token).delete(syntaxes[i]);
2117
+ visitedSyntaxes[visit] = null;
1909
2118
  context.next();
1910
2119
  break;
1911
2120
  }
@@ -1917,7 +2126,8 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
1917
2126
  finally {
1918
2127
  // the syntax is no longer being matched: a token may be matched again with the same syntax (the
1919
2128
  // alternatives of an optional group, ...). only the syntaxes being matched detect a cyclic definition
1920
- options.visited.get(token)?.delete(syntaxes[i]);
2129
+ visitedSyntaxes[visit] = null;
2130
+ visitedLength = visit;
1921
2131
  }
1922
2132
  if (success && !isInRange(arena, token, syntaxes[i])) {
1923
2133
  return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
@@ -1995,10 +2205,15 @@ function searchUnorderedSyntaxes(arena, syntaxes, remaining, all, base, context,
1995
2205
  const key = remaining[k] + ":" + position;
1996
2206
  let next = cache.get(key);
1997
2207
  if (next === undefined) {
1998
- const result = matchSyntax(arena, syntaxes[remaining[k]], context.slice(), options);
1999
2208
  next = null;
2209
+ // a syntax that cannot start with the token matches no token (see mayStartWith())
2210
+ const result = mayStartWith(arena, syntaxes[remaining[k]], context.peek())
2211
+ ? matchSyntax(arena, syntaxes[remaining[k]], context.slice(), options)
2212
+ : null;
2000
2213
  // the syntax matched some tokens
2001
- if (result.success && (result.context.done() || result.context.current() !== context.current())) {
2214
+ if (result != null &&
2215
+ result.success &&
2216
+ (result.context.done() || result.context.current() !== context.current())) {
2002
2217
  next = context.slice();
2003
2218
  if (result.context.done()) {
2004
2219
  next.end();
@@ -2082,7 +2297,7 @@ function peekFeatureTokens(arena, context) {
2082
2297
  let depth = 0;
2083
2298
  for (let index = context.index + 1; index < context.tokens.length; index++) {
2084
2299
  const token = context.tokens[index];
2085
- if (arena.dataTypes[token] === EnumToken.StartParensTokenType || tokensfuncDefMap.has(arena.dataTypes[token])) {
2300
+ if (arena.dataTypes[token] === EnumToken.StartParensTokenType || isFunctionDefType(arena.dataTypes[token])) {
2086
2301
  depth++;
2087
2302
  }
2088
2303
  else if (arena.dataTypes[token] === EnumToken.EndParensTokenType && depth-- === 0) {
@@ -2122,11 +2337,11 @@ function matchProperty(arena, property, context, options) {
2122
2337
  "calc-product",
2123
2338
  ].includes(property.val);
2124
2339
  if (checkCalc && !["number", "zero", "integer", "percentage", "length-percentage"].includes(property.val)) {
2125
- checkCalc = arena.strings[arena.stringValue[token]] === "calc";
2340
+ checkCalc = arena.resolveString(arena.stringValue[token]) === "calc";
2126
2341
  }
2127
2342
  if (checkCalc) {
2128
2343
  let result;
2129
- const syntax = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.strings[arena.stringValue[token]] + "()")?.[0]?.chi;
2344
+ const syntax = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.resolveString(arena.stringValue[token]) + "()")?.[0]?.chi;
2130
2345
  if (t === EnumToken.MathFunctionTokenType) {
2131
2346
  result = matchSyntax(arena, syntax, createValidationContext(arena, arena.tokens(token)), options);
2132
2347
  if (result.success && result.context.done()) {
@@ -2143,7 +2358,7 @@ function matchProperty(arena, property, context, options) {
2143
2358
  }
2144
2359
  else {
2145
2360
  const range = context.peekRange();
2146
- result = matchSyntax(arena, syntax, createValidationContext(arena, range.slice(1, -1)), options);
2361
+ result = matchSyntax(arena, syntax, createValidationContext(arena, range, 1, range.length - 1), options);
2147
2362
  if (result.success) {
2148
2363
  context.update(range.at(-1));
2149
2364
  return {
@@ -2183,7 +2398,7 @@ function matchProperty(arena, property, context, options) {
2183
2398
  success = false;
2184
2399
  while ((token = context.peek()) != null) {
2185
2400
  if (arena.dataTypes[token] === EnumToken.StartParensTokenType ||
2186
- tokensfuncDefMap.has(arena.dataTypes[token])) {
2401
+ isFunctionDefType(arena.dataTypes[token])) {
2187
2402
  stack.push(token);
2188
2403
  }
2189
2404
  if (expectToken) {
@@ -2255,8 +2470,8 @@ function matchProperty(arena, property, context, options) {
2255
2470
  if (
2256
2471
  // inlined: arena.typeOf(token)
2257
2472
  arena.dataTypes[token] === EnumToken.IdenTokenType &&
2258
- ("even" === arena.strings[arena.stringValue[token]] ||
2259
- "odd" === arena.strings[arena.stringValue[token]])) {
2473
+ ("even" === arena.resolveString(arena.stringValue[token]) ||
2474
+ "odd" === arena.resolveString(arena.stringValue[token]))) {
2260
2475
  success = true;
2261
2476
  break;
2262
2477
  }
@@ -2270,7 +2485,7 @@ function matchProperty(arena, property, context, options) {
2270
2485
  // inlined: arena.typeOf(token)
2271
2486
  if (arena.dataTypes[token] === EnumToken.LiteralTokenType ||
2272
2487
  arena.dataTypes[token] === EnumToken.IdenTokenType) {
2273
- let match = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(arena.strings[arena.stringValue[token]]);
2488
+ let match = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(arena.resolveString(arena.stringValue[token]));
2274
2489
  success = match != null;
2275
2490
  // `n + 1`: the sign and the number follow the ident
2276
2491
  if (success && match?.[3] == null) {
@@ -2321,7 +2536,7 @@ function matchProperty(arena, property, context, options) {
2321
2536
  if (
2322
2537
  // inlined: arena.typeOf(token)
2323
2538
  arena.dataTypes[token] === EnumToken.DimensionTokenType &&
2324
- arena.strings[arena.unit[token]] === "n") {
2539
+ arena.resolveString(arena.unit[token]) === "n") {
2325
2540
  success = Number.isInteger(arena.numericValue[token]);
2326
2541
  token = context.peek(1);
2327
2542
  if (token == null) {
@@ -2368,7 +2583,7 @@ function matchProperty(arena, property, context, options) {
2368
2583
  // inlined: arena.typeOf(token)
2369
2584
  success =
2370
2585
  arena.dataTypes[token] === EnumToken.IdenTokenType &&
2371
- values.has(arena.strings[arena.stringValue[token]].toLowerCase());
2586
+ values.has(arena.resolveString(arena.stringValue[token]).toLowerCase());
2372
2587
  break;
2373
2588
  }
2374
2589
  case "mf-name":
@@ -2377,7 +2592,7 @@ function matchProperty(arena, property, context, options) {
2377
2592
  success =
2378
2593
  // inlined: arena.typeOf(token)
2379
2594
  arena.dataTypes[token] === EnumToken.IdenTokenType &&
2380
- arena.strings[arena.stringValue[token]].toLowerCase() in config.mediaFeatures;
2595
+ arena.resolveString(arena.stringValue[token]).toLowerCase() in config.mediaFeatures;
2381
2596
  }
2382
2597
  break;
2383
2598
  case "dashed-ident":
@@ -2398,7 +2613,7 @@ function matchProperty(arena, property, context, options) {
2398
2613
  arena.dataTypes[token] === EnumToken.DashedIdenTokenType;
2399
2614
  // inlined: arena.typeOf(token)
2400
2615
  if (success && arena.dataTypes[token] === EnumToken.IdenTokenType) {
2401
- const val = arena.strings[arena.stringValue[token]].toLowerCase();
2616
+ const val = arena.resolveString(arena.stringValue[token]).toLowerCase();
2402
2617
  success = "none" !== val && !allValues.includes(val);
2403
2618
  }
2404
2619
  break;
@@ -2576,7 +2791,7 @@ function matchProperty(arena, property, context, options) {
2576
2791
  const token = context.peek();
2577
2792
  success =
2578
2793
  arena.dataTypes[token] === EnumToken.DimensionTokenType &&
2579
- equalsIgnoreCase(arena.strings[arena.unit[token]], property.val === "decibel" ? "dB" : "st");
2794
+ equalsIgnoreCase(arena.resolveString(arena.unit[token]), property.val === "decibel" ? "dB" : "st");
2580
2795
  break;
2581
2796
  }
2582
2797
  case "time":
@@ -2596,7 +2811,7 @@ function matchProperty(arena, property, context, options) {
2596
2811
  const token = context.peek();
2597
2812
  const errors = [];
2598
2813
  // inlined: arena.typeOf(token)
2599
- if (tokensfuncDefMap.has((token == null ? null : arena.dataTypes[token]))) {
2814
+ if (isFunctionDefType((token == null ? null : arena.dataTypes[token]))) {
2600
2815
  const range = context.peekRange();
2601
2816
  const newRange = range.map((t) => arena.clone(t, true));
2602
2817
  parseTokens(arena, newRange, { parseColor: true }, errors);
@@ -2659,7 +2874,7 @@ function matchProperty(arena, property, context, options) {
2659
2874
  }
2660
2875
  case "function-token":
2661
2876
  // inlined: arena.typeOf(context.peek()). the type of a null id is undefined: not a key of the map either
2662
- if (tokensfuncDefMap.has(arena.dataTypes[context.peek()])) {
2877
+ if (isFunctionDefType(arena.dataTypes[context.peek()])) {
2663
2878
  // the token is consumed below
2664
2879
  success = true;
2665
2880
  break;
@@ -2678,8 +2893,8 @@ function matchProperty(arena, property, context, options) {
2678
2893
  // inlined: arena.typeOf(token)
2679
2894
  arena.dataTypes[token] === EnumToken.IdenTokenType &&
2680
2895
  // @ts-expect-error
2681
- config.languages.some((t) => t === arena.strings[arena.stringValue[token]] ||
2682
- arena.strings[arena.stringValue[token]].startsWith(t + "-"));
2896
+ config.languages.some((t) => t === arena.resolveString(arena.stringValue[token]) ||
2897
+ arena.resolveString(arena.stringValue[token]).startsWith(t + "-"));
2683
2898
  break;
2684
2899
  }
2685
2900
  case "size-feature": {
@@ -2803,7 +3018,7 @@ function matchProperty(arena, property, context, options) {
2803
3018
  // `type(<number> | <transform-function>)`: the css type syntax
2804
3019
  if ((arena.dataTypes[token] === EnumToken.FunctionTokenDefType ||
2805
3020
  arena.dataTypes[token] === EnumToken.FunctionTokenType) &&
2806
- equalsIgnoreCase(arena.strings[arena.stringValue[token]], "type")) {
3021
+ equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), "type")) {
2807
3022
  if (arena.dataTypes[token] === EnumToken.FunctionTokenDefType) {
2808
3023
  context.update(context.peekRange().at(-1));
2809
3024
  }
@@ -2828,7 +3043,7 @@ function matchProperty(arena, property, context, options) {
2828
3043
  if (multiplier != null &&
2829
3044
  (arena.dataTypes[multiplier] === EnumToken.Plus ||
2830
3045
  (arena.dataTypes[multiplier] === EnumToken.LiteralTokenType &&
2831
- arena.strings[arena.stringValue[multiplier]] === "#"))) {
3046
+ arena.resolveString(arena.stringValue[multiplier]) === "#"))) {
2832
3047
  context.next();
2833
3048
  }
2834
3049
  return {
@@ -2899,7 +3114,7 @@ function matchProperty(arena, property, context, options) {
2899
3114
  if (!success &&
2900
3115
  // inlined: arena.typeOf(context.peek())
2901
3116
  arena.dataTypes[context.peek()] === EnumToken.IdenTokenType &&
2902
- allValues.includes(arena.strings[arena.stringValue[context.peek()]])) {
3117
+ allValues.includes(arena.resolveString(arena.stringValue[context.peek()]))) {
2903
3118
  success = true;
2904
3119
  }
2905
3120
  if (success) {
@@ -2961,4 +3176,4 @@ function matchRepeatableSyntax(arena, syntax, context, options) {
2961
3176
  };
2962
3177
  }
2963
3178
 
2964
- export { createValidationContext, funcTypes, getMFInfo, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
3179
+ export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, selectorFunctionSyntax, trimArray };