@tbela99/css-parser 1.6.9 → 1.8.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 (103) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +1139 -529
  4. package/dist/index.cjs +1138 -528
  5. package/dist/index.d.ts +259 -8
  6. package/dist/package.json.js +2 -2
  7. package/dist/src/data/properties.json.js +1 -1
  8. package/dist/src/data/validation.json.js +11 -2
  9. package/dist/src/lib/ast/clone.js +1 -1
  10. package/dist/src/lib/ast/expand.js +1 -1
  11. package/dist/src/lib/ast/features/calc.js +1 -1
  12. package/dist/src/lib/ast/features/if.js +1 -1
  13. package/dist/src/lib/ast/features/index.js +1 -1
  14. package/dist/src/lib/ast/features/inlinecssvariables.js +6 -5
  15. package/dist/src/lib/ast/features/prefix.js +1 -1
  16. package/dist/src/lib/ast/features/shorthand.js +39 -22
  17. package/dist/src/lib/ast/features/transform.js +1 -1
  18. package/dist/src/lib/ast/features/type.js +1 -1
  19. package/dist/src/lib/ast/find.js +26 -21
  20. package/dist/src/lib/ast/math/expression.js +4 -1
  21. package/dist/src/lib/ast/math/math.js +1 -1
  22. package/dist/src/lib/ast/minify.js +31 -3
  23. package/dist/src/lib/ast/node.js +1 -1
  24. package/dist/src/lib/ast/transform/compute.js +1 -1
  25. package/dist/src/lib/ast/transform/matrix.js +1 -1
  26. package/dist/src/lib/ast/transform/minify.js +1 -1
  27. package/dist/src/lib/ast/transform/perspective.js +1 -1
  28. package/dist/src/lib/ast/transform/rotate.js +1 -1
  29. package/dist/src/lib/ast/transform/scale.js +1 -1
  30. package/dist/src/lib/ast/transform/skew.js +1 -1
  31. package/dist/src/lib/ast/transform/translate.js +1 -1
  32. package/dist/src/lib/ast/transform/utils.js +1 -1
  33. package/dist/src/lib/ast/types.js +5 -1
  34. package/dist/src/lib/ast/walk.js +319 -94
  35. package/dist/src/lib/fs/resolve.js +1 -1
  36. package/dist/src/lib/parser/declaration/list.js +35 -1
  37. package/dist/src/lib/parser/declaration/map.js +2 -2
  38. package/dist/src/lib/parser/declaration/set.js +1 -1
  39. package/dist/src/lib/parser/linesmap.js +1 -1
  40. package/dist/src/lib/parser/parse.js +504 -177
  41. package/dist/src/lib/parser/source.js +1 -1
  42. package/dist/src/lib/parser/tokenize.js +23 -3
  43. package/dist/src/lib/parser/utils/angle.js +1 -1
  44. package/dist/src/lib/parser/utils/at-rule-container.js +1 -1
  45. package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  46. package/dist/src/lib/parser/utils/at-rule-generic.js +1 -1
  47. package/dist/src/lib/parser/utils/at-rule-import.js +1 -1
  48. package/dist/src/lib/parser/utils/at-rule-media.js +2 -2
  49. package/dist/src/lib/parser/utils/at-rule-support.js +2 -2
  50. package/dist/src/lib/parser/utils/at-rule-when-else.js +1 -1
  51. package/dist/src/lib/parser/utils/at-rule.js +1 -1
  52. package/dist/src/lib/parser/utils/base64.js +1 -1
  53. package/dist/src/lib/parser/utils/cache.js +1 -1
  54. package/dist/src/lib/parser/utils/config.js +1 -1
  55. package/dist/src/lib/parser/utils/declaration.js +1 -1
  56. package/dist/src/lib/parser/utils/eq.js +1 -1
  57. package/dist/src/lib/parser/utils/hash.js +1 -1
  58. package/dist/src/lib/parser/utils/selector.js +1 -1
  59. package/dist/src/lib/parser/utils/text.js +1 -1
  60. package/dist/src/lib/parser/utils/token.js +12 -4
  61. package/dist/src/lib/parser/utils/type.js +1 -1
  62. package/dist/src/lib/printer/render.js +6 -3
  63. package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
  64. package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
  65. package/dist/src/lib/syntax/color/a98rgb.js +1 -1
  66. package/dist/src/lib/syntax/color/alpha.js +1 -1
  67. package/dist/src/lib/syntax/color/cmyk.js +1 -1
  68. package/dist/src/lib/syntax/color/color-mix.js +1 -1
  69. package/dist/src/lib/syntax/color/color.js +1 -1
  70. package/dist/src/lib/syntax/color/hex.js +1 -1
  71. package/dist/src/lib/syntax/color/hsl.js +1 -1
  72. package/dist/src/lib/syntax/color/hwb.js +1 -1
  73. package/dist/src/lib/syntax/color/lab.js +1 -1
  74. package/dist/src/lib/syntax/color/lch.js +1 -1
  75. package/dist/src/lib/syntax/color/oklab.js +1 -1
  76. package/dist/src/lib/syntax/color/oklch.js +1 -1
  77. package/dist/src/lib/syntax/color/p3.js +1 -1
  78. package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
  79. package/dist/src/lib/syntax/color/rec2020.js +1 -1
  80. package/dist/src/lib/syntax/color/relative-color.js +1 -1
  81. package/dist/src/lib/syntax/color/rgb.js +1 -1
  82. package/dist/src/lib/syntax/color/srgb.js +1 -1
  83. package/dist/src/lib/syntax/color/utils/color-type.js +1 -1
  84. package/dist/src/lib/syntax/color/utils/colorspace.js +1 -1
  85. package/dist/src/lib/syntax/color/utils/components.js +1 -1
  86. package/dist/src/lib/syntax/color/utils/distance.js +1 -1
  87. package/dist/src/lib/syntax/color/utils/make-color.js +1 -1
  88. package/dist/src/lib/syntax/color/utils/matrix.js +1 -1
  89. package/dist/src/lib/syntax/color/xyz.js +1 -1
  90. package/dist/src/lib/syntax/color/xyzd50.js +1 -1
  91. package/dist/src/lib/syntax/constants.js +1 -1
  92. package/dist/src/lib/syntax/syntax.js +1 -1
  93. package/dist/src/lib/validation/config.js +20 -3
  94. package/dist/src/lib/validation/match.js +105 -200
  95. package/dist/src/lib/validation/parser/parse.js +8 -3
  96. package/dist/src/lib/validation/parser/typedef.js +1 -1
  97. package/dist/src/lib/validation/utils/list.js +1 -1
  98. package/dist/src/node.js +2 -1
  99. package/dist/src/types.js +1 -1
  100. package/dist/src/utils/sync.js +1 -1
  101. package/dist/src/web.js +2 -1
  102. package/package.json +8 -7
  103. package/CONTRIBUTING.md +0 -119
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  (function (global, factory) {
@@ -697,6 +697,10 @@
697
697
  * CSS type token
698
698
  */
699
699
  EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
700
+ /**
701
+ * user defined dimension token type
702
+ */
703
+ EnumToken[EnumToken["UserDefinedDimensionTokenType"] = 145] = "UserDefinedDimensionTokenType";
700
704
  /* aliases */
701
705
  /**
702
706
  * alias for time token type
@@ -5721,7 +5725,16 @@
5721
5725
  syntax: " @bottom-right-corner { <declaration-list> }"
5722
5726
  },
5723
5727
  "@function": {
5724
- syntax: " @function <dashed-ident>(<function-parameter>#?) [returns <css-type>]? { <declaration-rule-list> }"
5728
+ syntax: " @function <dashed-function> <function-parameter>#?) [returns <css-type>]? { <declaration-rule-list> }"
5729
+ },
5730
+ "@mixin": {
5731
+ syntax: " @mixin [<dashed-function> <function-parameter>#? ) | <ident-token> ]{<block-contents>}"
5732
+ },
5733
+ "@apply": {
5734
+ syntax: " @apply [ <dashed-ident> | <dashed-function> ] [ { <declaration-list> } ]?;"
5735
+ },
5736
+ "@contents": {
5737
+ syntax: " @contents [ { <declaration-list> } ]?;"
5725
5738
  },
5726
5739
  "@left-top": {
5727
5740
  syntax: " @left-top { <declaration-list> }"
@@ -9687,7 +9700,6 @@
9687
9700
  */
9688
9701
  WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
9689
9702
  })(exports.WalkerEvent || (exports.WalkerEvent = {}));
9690
- const maxQueueLength = 25000;
9691
9703
  /**
9692
9704
  * Walk ast nodes
9693
9705
  * @param node initial node
@@ -9770,7 +9782,6 @@
9770
9782
  let isNumeric = false;
9771
9783
  let children = true;
9772
9784
  let attributes = false;
9773
- let i = 0;
9774
9785
  if (options != null && typeof options == "object") {
9775
9786
  filter = options.filter;
9776
9787
  reverse = options.reverse;
@@ -9790,12 +9801,11 @@
9790
9801
  }
9791
9802
  },
9792
9803
  };
9793
- while ((node = parents[i++])) {
9794
- if (i > maxQueueLength) {
9795
- parents.splice(0, maxQueueLength);
9796
- i -= maxQueueLength;
9797
- }
9798
- let option = null;
9804
+ let option = null;
9805
+ let source = [];
9806
+ while (parents.length > 0) {
9807
+ node = parents.pop();
9808
+ // enter node
9799
9809
  if (filter != null) {
9800
9810
  // @ts-expect-error
9801
9811
  option = filter(node);
@@ -9816,36 +9826,175 @@
9816
9826
  yield result;
9817
9827
  }
9818
9828
  if (attributes) {
9819
- if (node[TOKENS] != null) {
9820
- // @ts-expect-error
9821
- parents.splice(i, 0, ...(reverse ? node[TOKENS].toReversed() : node[TOKENS]));
9822
- for (const child of node[TOKENS]) {
9823
- if (child[PARENT] != node) {
9824
- child[PARENT] = node;
9829
+ source.length = 0;
9830
+ if (Array.isArray(node[TOKENS])) {
9831
+ if (reverse) {
9832
+ for (const token of node[TOKENS]) {
9833
+ parents.push(token);
9834
+ token[PARENT] = node;
9835
+ }
9836
+ }
9837
+ else {
9838
+ for (let i = node[TOKENS].length - 1; i >= 0; i--) {
9839
+ parents.push(node[TOKENS][i]);
9840
+ node[TOKENS][i][PARENT] = node;
9825
9841
  }
9826
9842
  }
9827
- // @ts-expect-error
9828
9843
  }
9829
- else if (Array.isArray(node.val)) {
9830
- // @ts-expect-error
9831
- for (const val of node.val) {
9832
- if (val[PARENT] != node) {
9833
- val[PARENT] = node;
9844
+ else if (node.typ == exports.EnumToken.DeclarationNodeType) {
9845
+ if (reverse) {
9846
+ for (const token of node.val) {
9847
+ parents.push(token);
9848
+ token[PARENT] = node;
9849
+ }
9850
+ }
9851
+ else {
9852
+ for (let i = node.val.length - 1; i >= 0; i--) {
9853
+ parents.push(node.val[i]);
9854
+ node.val[i][PARENT] = node;
9855
+ }
9856
+ }
9857
+ }
9858
+ else {
9859
+ source.length = 0;
9860
+ switch (node.typ) {
9861
+ case exports.EnumToken.BinaryExpressionTokenType:
9862
+ case exports.EnumToken.IfElseConditionTokenType:
9863
+ source.push(node.l);
9864
+ node.l[PARENT] = node;
9865
+ source.push(node.r);
9866
+ node.r[PARENT] = node;
9867
+ break;
9868
+ case exports.EnumToken.MatchExpressionTokenType:
9869
+ source.push(node.l);
9870
+ node.l[PARENT] = node;
9871
+ source.push(node.op);
9872
+ node.op[PARENT] = node;
9873
+ source.push(node.r);
9874
+ node.r[PARENT] = node;
9875
+ break;
9876
+ case exports.EnumToken.SupportsQueryConditionTokenType:
9877
+ case exports.EnumToken.MediaQueryConditionTokenType:
9878
+ for (let i = 0; i < node.l.length; i++) {
9879
+ const element = node.l[i];
9880
+ source.push(element);
9881
+ element[PARENT] = node;
9882
+ }
9883
+ source.push(node.op);
9884
+ node.op[PARENT] = node;
9885
+ for (let i = 0; i < node.r.length; i++) {
9886
+ const element = node.r[i];
9887
+ source.push(element);
9888
+ element[PARENT] = node;
9889
+ }
9890
+ break;
9891
+ case exports.EnumToken.WhenElseQueryConditionTokenType:
9892
+ source.push(node.l);
9893
+ node.l[PARENT] = node;
9894
+ for (let i = 0; i < node.r.length; i++) {
9895
+ const element = node.r[i];
9896
+ source.push(element);
9897
+ element[PARENT] = node;
9898
+ }
9899
+ break;
9900
+ case exports.EnumToken.ComposesSelectorNodeType:
9901
+ for (let i = 0; i < node.l.length; i++) {
9902
+ const element = node.l[i];
9903
+ source.push(element);
9904
+ element[PARENT] = node;
9905
+ }
9906
+ if (node.r != null) {
9907
+ source.push(node.r);
9908
+ node.r[PARENT] = node;
9909
+ }
9910
+ break;
9911
+ case exports.EnumToken.IfConditionTokenType:
9912
+ for (let i = 0; i < node.l.length; i++) {
9913
+ const element = node.l[i];
9914
+ source.push(element);
9915
+ element[PARENT] = node;
9916
+ }
9917
+ for (let i = 0; i < node.r.length; i++) {
9918
+ const element = node.r[i];
9919
+ source.push(element);
9920
+ element[PARENT] = node;
9921
+ }
9922
+ break;
9923
+ case exports.EnumToken.ContainerStyleRangeTokenType:
9924
+ for (let i = 0; i < node.l.length; i++) {
9925
+ const element = node.l[i];
9926
+ source.push(element);
9927
+ element[PARENT] = node;
9928
+ }
9929
+ for (let i = 0; i < node.op.length; i++) {
9930
+ const element = node.op[i];
9931
+ source.push(element);
9932
+ element[PARENT] = node;
9933
+ }
9934
+ for (let i = 0; i < node.r.length; i++) {
9935
+ const element = node.r[i];
9936
+ source.push(element);
9937
+ element[PARENT] = node;
9938
+ }
9939
+ break;
9940
+ case exports.EnumToken.MediaRangeQueryTokenType:
9941
+ for (let i = 0; i < node.l.length; i++) {
9942
+ const element = node.l[i];
9943
+ source.push(element);
9944
+ element[PARENT] = node;
9945
+ }
9946
+ source.push(node.op1);
9947
+ node.op1[PARENT] = node;
9948
+ for (let i = 0; i < node.val.length; i++) {
9949
+ const element = node.val[i];
9950
+ source.push(element);
9951
+ element[PARENT] = node;
9952
+ }
9953
+ source.push(node.op2);
9954
+ node.op2[PARENT] = node;
9955
+ for (let i = 0; i < node.r.length; i++) {
9956
+ const element = node.r[i];
9957
+ source.push(element);
9958
+ element[PARENT] = node;
9959
+ }
9960
+ break;
9961
+ }
9962
+ if (source.length > 0) {
9963
+ if (reverse) {
9964
+ for (let i = 0; i < source.length; i++) {
9965
+ parents.push(source[i]);
9966
+ source[i][PARENT] = node;
9967
+ }
9968
+ }
9969
+ else {
9970
+ for (let i = source.length - 1; i >= 0; i--) {
9971
+ parents.push(source[i]);
9972
+ source[i][PARENT] = node;
9973
+ }
9834
9974
  }
9835
9975
  }
9836
- // @ts-expect-error
9837
- parents.splice(i, 0, ...(reverse ? node.val.toReversed() : node.val));
9838
9976
  }
9839
9977
  }
9840
9978
  if (children &&
9841
9979
  // @ts-expect-error
9842
9980
  node["chi"] != null &&
9843
9981
  (!isNumeric || (option & exports.WalkerOptionEnum.IgnoreChildren) === 0)) {
9844
- // @ts-expect-error
9845
- parents.splice(i, 0, ...(reverse ? node.chi.toReversed() : node.chi));
9846
- for (const child of node.chi) {
9847
- if (child[PARENT] != node) {
9848
- child[PARENT] = node;
9982
+ if (reverse) {
9983
+ // @ts-expect-error
9984
+ for (let i = 0; i < node.chi.length; i++) {
9985
+ // @ts-expect-error
9986
+ parents.push(node.chi[i]);
9987
+ // @ts-expect-error
9988
+ node.chi[i][PARENT] = node;
9989
+ }
9990
+ }
9991
+ else {
9992
+ // @ts-expect-error
9993
+ for (let i = node.chi.length - 1; i >= 0; i--) {
9994
+ // @ts-expect-error
9995
+ parents.push(node.chi[i]);
9996
+ // @ts-expect-error
9997
+ node.chi[i][PARENT] = node;
9849
9998
  }
9850
9999
  }
9851
10000
  }
@@ -9898,9 +10047,19 @@
9898
10047
  * // [ "Iden", "from" ]
9899
10048
  * ```
9900
10049
  */
9901
- function* walkValues(values, root = null, filter, reverse) {
9902
- const stack = values.slice();
10050
+ function* walkValues(tokens, root = null, filter, reverse) {
10051
+ const nodes = [];
9903
10052
  let previous = null;
10053
+ if (reverse) {
10054
+ for (let i = 0; i < tokens.length; i++) {
10055
+ nodes.push(tokens[i]);
10056
+ }
10057
+ }
10058
+ else {
10059
+ for (let i = tokens.length - 1; i >= 0; i--) {
10060
+ nodes.push(tokens[i]);
10061
+ }
10062
+ }
9904
10063
  if (filter != null && typeof filter == "function") {
9905
10064
  filter = {
9906
10065
  event: exports.WalkerEvent.Enter,
@@ -9916,7 +10075,7 @@
9916
10075
  let value;
9917
10076
  let option;
9918
10077
  let node;
9919
- let i = -1;
10078
+ const values = [];
9920
10079
  const eventType = filter.event ?? exports.WalkerEvent.Enter;
9921
10080
  // @ts-ignore
9922
10081
  const result = {
@@ -9935,13 +10094,9 @@
9935
10094
  }
9936
10095
  },
9937
10096
  };
9938
- while (++i < stack.length) {
9939
- value = stack[i];
10097
+ while (nodes.length > 0) {
10098
+ value = nodes.pop();
9940
10099
  option = null;
9941
- if (i > maxQueueLength) {
9942
- stack.splice(0, maxQueueLength);
9943
- i -= maxQueueLength;
9944
- }
9945
10100
  if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
9946
10101
  const isValid = filter.type == null ||
9947
10102
  value.typ == filter.type ||
@@ -9969,10 +10124,16 @@
9969
10124
  //
9970
10125
  if (option != null && typeof option == "object" && ("typ" in option || Array.isArray(option))) {
9971
10126
  const op = Array.isArray(option) ? option : [option];
9972
- stack.splice(i, 0, ...(reverse ? op.toReversed() : op));
9973
- for (const o of op) {
9974
- if (o[PARENT] != value) {
9975
- o[PARENT] = value;
10127
+ if (reverse) {
10128
+ for (let i = 0; i < op.length; i++) {
10129
+ nodes.push(op[i]);
10130
+ op[i][PARENT] = value;
10131
+ }
10132
+ }
10133
+ else {
10134
+ for (let i = op.length - 1; i >= 0; i--) {
10135
+ nodes.push(op[i]);
10136
+ op[i][PARENT] = value;
9976
10137
  }
9977
10138
  }
9978
10139
  }
@@ -9981,70 +10142,140 @@
9981
10142
  result.value = value;
9982
10143
  result.parent = value[PARENT] ?? root;
9983
10144
  result.previousValue = previous;
9984
- result.nextValue = stack[0] ?? null;
10145
+ result.nextValue = nodes[nodes.length - 1] ?? null;
9985
10146
  yield result;
9986
10147
  if (!isNumeric || (option & exports.WalkerOptionEnum.IgnoreChildren) === 0) {
9987
- if ("chi" in value) {
9988
- const sliced = value.chi.slice();
9989
- for (const child of sliced) {
9990
- if (child[PARENT] != value) {
9991
- child[PARENT] = value;
9992
- }
9993
- if (reverse) {
9994
- stack.unshift(child);
10148
+ //
10149
+ if (value.chi != null) {
10150
+ const source = value.chi;
10151
+ if (reverse) {
10152
+ for (let i = 0; i < source.length; i++) {
10153
+ nodes.push(source[i]);
10154
+ source[i][PARENT] = value;
9995
10155
  }
9996
- else {
9997
- stack.push(child);
10156
+ }
10157
+ else {
10158
+ for (let i = source.length - 1; i >= 0; i--) {
10159
+ nodes.push(source[i]);
10160
+ source[i][PARENT] = value;
9998
10161
  }
9999
10162
  }
10000
10163
  }
10001
10164
  else {
10002
- const values = [];
10003
- if ("l" in value && value.l != null) {
10004
- // @ts-expect-error
10005
- values.push(value.l);
10006
- // @ts-expect-error
10007
- if (value.l[PARENT] != value) {
10008
- // @ts-expect-error
10165
+ values.length = 0;
10166
+ switch (value.typ) {
10167
+ case exports.EnumToken.BinaryExpressionTokenType:
10168
+ case exports.EnumToken.IfElseConditionTokenType:
10169
+ values.push(value.l);
10009
10170
  value.l[PARENT] = value;
10010
- }
10011
- }
10012
- if ("op" in value && typeof value.op == "object") {
10013
- // @ts-expect-error
10014
- values.push(value.op);
10015
- // @ts-expect-error
10016
- if (value.op[PARENT] != value) {
10017
- // @ts-expect-error
10171
+ values.push(value.r);
10172
+ value.r[PARENT] = value;
10173
+ break;
10174
+ case exports.EnumToken.MatchExpressionTokenType:
10175
+ values.push(value.l);
10176
+ value.l[PARENT] = value;
10177
+ values.push(value.op);
10018
10178
  value.op[PARENT] = value;
10019
- }
10020
- }
10021
- if ("r" in value && value.r != null) {
10022
- if (Array.isArray(value.r)) {
10023
- for (const r of value.r) {
10024
- //
10025
- values.push(r);
10026
- if (r[PARENT] != value) {
10027
- //
10028
- r[PARENT] = value;
10029
- }
10030
- }
10031
- }
10032
- else {
10033
- //
10034
10179
  values.push(value.r);
10035
- if (value.r[PARENT] != value) {
10036
- //
10180
+ value.r[PARENT] = value;
10181
+ break;
10182
+ case exports.EnumToken.SupportsQueryConditionTokenType:
10183
+ case exports.EnumToken.MediaQueryConditionTokenType:
10184
+ for (let i = 0; i < value.l.length; i++) {
10185
+ const element = value.l[i];
10186
+ values.push(element);
10187
+ element[PARENT] = value;
10188
+ }
10189
+ values.push(value.op);
10190
+ value.op[PARENT] = value;
10191
+ for (let i = 0; i < value.r.length; i++) {
10192
+ const element = value.r[i];
10193
+ values.push(element);
10194
+ element[PARENT] = value;
10195
+ }
10196
+ break;
10197
+ case exports.EnumToken.ComposesSelectorNodeType:
10198
+ for (let i = 0; i < value.l.length; i++) {
10199
+ const element = value.l[i];
10200
+ values.push(element);
10201
+ element[PARENT] = value;
10202
+ }
10203
+ if (value.r != null) {
10204
+ values.push(value.r);
10037
10205
  value.r[PARENT] = value;
10038
10206
  }
10039
- }
10207
+ break;
10208
+ case exports.EnumToken.WhenElseQueryConditionTokenType:
10209
+ values.push(value.l);
10210
+ value.l[PARENT] = value;
10211
+ for (let i = 0; i < value.r.length; i++) {
10212
+ const element = value.r[i];
10213
+ values.push(element);
10214
+ element[PARENT] = value;
10215
+ }
10216
+ break;
10217
+ case exports.EnumToken.IfConditionTokenType:
10218
+ for (let i = 0; i < value.l.length; i++) {
10219
+ const element = value.l[i];
10220
+ values.push(element);
10221
+ element[PARENT] = value;
10222
+ }
10223
+ for (let i = 0; i < value.r.length; i++) {
10224
+ const element = value.r[i];
10225
+ values.push(element);
10226
+ element[PARENT] = value;
10227
+ }
10228
+ break;
10229
+ case exports.EnumToken.ContainerStyleRangeTokenType:
10230
+ for (let i = 0; i < value.l.length; i++) {
10231
+ const element = value.l[i];
10232
+ values.push(element);
10233
+ element[PARENT] = value;
10234
+ }
10235
+ for (let i = 0; i < value.op.length; i++) {
10236
+ const element = value.op[i];
10237
+ values.push(element);
10238
+ element[PARENT] = value;
10239
+ }
10240
+ for (let i = 0; i < value.r.length; i++) {
10241
+ const element = value.r[i];
10242
+ values.push(element);
10243
+ element[PARENT] = value;
10244
+ }
10245
+ break;
10246
+ case exports.EnumToken.MediaRangeQueryTokenType:
10247
+ for (let i = 0; i < value.l.length; i++) {
10248
+ const element = value.l[i];
10249
+ values.push(element);
10250
+ element[PARENT] = value;
10251
+ }
10252
+ values.push(value.op1);
10253
+ value.op1[PARENT] = value;
10254
+ for (let i = 0; i < value.val.length; i++) {
10255
+ const element = value.val[i];
10256
+ values.push(element);
10257
+ element[PARENT] = value;
10258
+ }
10259
+ values.push(value.op2);
10260
+ value.op2[PARENT] = value;
10261
+ for (let i = 0; i < value.r.length; i++) {
10262
+ const element = value.r[i];
10263
+ values.push(element);
10264
+ element[PARENT] = value;
10265
+ }
10266
+ break;
10040
10267
  }
10041
10268
  if (values.length > 0) {
10042
- for (const v of values) {
10043
- if (reverse) {
10044
- stack.unshift(v);
10269
+ if (reverse) {
10270
+ for (let i = 0; i < values.length; i++) {
10271
+ nodes.push(values[i]);
10272
+ values[i][PARENT] = value;
10045
10273
  }
10046
- else {
10047
- stack.push(v);
10274
+ }
10275
+ else {
10276
+ for (let i = values.length - 1; i >= 0; i--) {
10277
+ nodes.push(values[i]);
10278
+ values[i][PARENT] = value;
10048
10279
  }
10049
10280
  }
10050
10281
  }
@@ -10061,10 +10292,16 @@
10061
10292
  // @ts-ignore
10062
10293
  if (option != null && ("typ" in option || Array.isArray(option))) {
10063
10294
  const op = Array.isArray(option) ? option : [option];
10064
- stack.splice(i, 0, ...(reverse ? op.toReversed() : op));
10065
- for (const o of op) {
10066
- if (o[PARENT] != value) {
10067
- o[PARENT] = value;
10295
+ if (reverse) {
10296
+ for (let i = 0; i < op.length; i++) {
10297
+ nodes.push(op[i]);
10298
+ op[i][PARENT] = value;
10299
+ }
10300
+ }
10301
+ else {
10302
+ for (let i = op.length - 1; i >= 0; i--) {
10303
+ nodes.push(op[i]);
10304
+ op[i][PARENT] = value;
10068
10305
  }
10069
10306
  }
10070
10307
  }
@@ -10310,6 +10547,9 @@
10310
10547
  }
10311
10548
  }
10312
10549
  if (acc.length > 0 && curr[0] != exports.EnumToken.ListToken) {
10550
+ if ("val" in token && +token.val == 0) {
10551
+ return acc;
10552
+ }
10313
10553
  acc.push({
10314
10554
  typ: exports.EnumToken.Add,
10315
10555
  [LOCSRCID]: token[LOCSRCID],
@@ -11770,6 +12010,11 @@
11770
12010
  [LOC]: { ...position },
11771
12011
  };
11772
12012
  }
12013
+ /**
12014
+ * parse mdn data syntax
12015
+ * @param syntax
12016
+ * @returns
12017
+ */
11773
12018
  function parseSyntax(syntax) {
11774
12019
  const stack = [];
11775
12020
  let tokens = [];
@@ -12313,8 +12558,8 @@
12313
12558
  }
12314
12559
  }
12315
12560
  }
12316
- const block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
12317
- const prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
12561
+ let block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
12562
+ let prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
12318
12563
  let propertyDescriptors = null;
12319
12564
  // @ts-expect-error
12320
12565
  if (node.descriptors != null) {
@@ -12325,7 +12570,24 @@
12325
12570
  propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
12326
12571
  }
12327
12572
  }
12573
+ let optionalBody = false;
12574
+ if (block == null || block.length === 0) {
12575
+ let k = prelude.length - 1;
12576
+ if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
12577
+ k--;
12578
+ }
12579
+ if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
12580
+ if (prelude[k].chi[0].typ ===
12581
+ ValidationTokenEnum.OpenCurlyBrace &&
12582
+ prelude[k].chi.at(-1).typ ===
12583
+ ValidationTokenEnum.CloseCurlyBrace) {
12584
+ block = prelude[k].chi.slice(1, -1);
12585
+ optionalBody = prelude[k].isOptional ?? false;
12586
+ }
12587
+ }
12588
+ }
12328
12589
  return {
12590
+ optionalBody,
12329
12591
  acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
12330
12592
  acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
12331
12593
  node.syntax.includes("<stylesheet>"),
@@ -12413,15 +12675,6 @@
12413
12675
  }
12414
12676
  return tokens;
12415
12677
  }
12416
- /**
12417
- * is a media feature
12418
- * @param featureName
12419
- * @returns
12420
- */
12421
- // export function isMFName(featureName: string): boolean {
12422
- // // @ts-expect-error
12423
- // return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
12424
- // }
12425
12678
  /**
12426
12679
  *
12427
12680
  * @param featureName
@@ -12942,9 +13195,6 @@
12942
13195
  case exports.EnumToken.NumberTokenType:
12943
13196
  case exports.EnumToken.LiteralTokenType:
12944
13197
  case exports.EnumToken.DimensionTokenType:
12945
- // if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
12946
- // stack.pop();
12947
- // }
12948
13198
  if (stack.at(-1)?.typ === exports.EnumToken.PseudoClassFunctionTokenDefType) {
12949
13199
  break;
12950
13200
  }
@@ -13213,43 +13463,9 @@
13213
13463
  continue;
13214
13464
  }
13215
13465
  }
13216
- // custom function token
13217
- if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) {
13218
- if (syntaxes[i].typ != ValidationTokenEnum.PropertyType ||
13219
- syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
13220
- syntaxes[i + 2]?.typ == null) {
13221
- if (!isOptional) {
13222
- return {
13223
- success: false,
13224
- errors: [
13225
- {
13226
- action: "drop",
13227
- message: "could not match syntax",
13228
- node: token,
13229
- syntax: syntaxes[i],
13230
- },
13231
- ],
13232
- syntaxToken: syntaxes[i],
13233
- valid: true,
13234
- context,
13235
- token: null,
13236
- };
13237
- }
13238
- break;
13239
- }
13240
- const range = trimArray(context.peekRange());
13241
- context.next();
13242
- i++;
13243
- result = matchSyntax([syntaxes[i + 1]], createValidationContext(range.slice(1, -1)), options);
13244
- if (result.success) {
13245
- context.update(range.at(-1));
13246
- i += 2;
13247
- }
13248
- return result;
13249
- }
13250
- if (tokensfuncDefMap.has(token.typ) &&
13251
- // @ts-ignore
13252
- token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
13466
+ if (
13467
+ // @ts-ignore
13468
+ token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
13253
13469
  const range = trimArray(context.peekRange());
13254
13470
  result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(range.slice(1, -1)), options);
13255
13471
  if (result.success) {
@@ -13274,6 +13490,9 @@
13274
13490
  context.update(result.context.current());
13275
13491
  continue;
13276
13492
  }
13493
+ if (isOptional) {
13494
+ continue;
13495
+ }
13277
13496
  return result;
13278
13497
  }
13279
13498
  if (syntaxes[i].isList) {
@@ -13294,6 +13513,9 @@
13294
13513
  context.update(result.context.current());
13295
13514
  continue;
13296
13515
  }
13516
+ if (isOptional) {
13517
+ continue;
13518
+ }
13297
13519
  return {
13298
13520
  success: false,
13299
13521
  valid: true,
@@ -13318,6 +13540,9 @@
13318
13540
  context.update(result.context.current());
13319
13541
  continue;
13320
13542
  }
13543
+ if (isOptional) {
13544
+ continue;
13545
+ }
13321
13546
  return {
13322
13547
  success: false,
13323
13548
  valid: true,
@@ -13722,6 +13947,20 @@
13722
13947
  syntaxToken: syntaxes[i],
13723
13948
  errors: [],
13724
13949
  };
13950
+ case ValidationTokenEnum.OpenCurlyBrace:
13951
+ if (token.typ === exports.EnumToken.BlockStartTokenType) {
13952
+ options.visited.get(token).delete(syntaxes[i]);
13953
+ context.next();
13954
+ break;
13955
+ }
13956
+ return {
13957
+ success: false,
13958
+ valid: true,
13959
+ token,
13960
+ context,
13961
+ syntaxToken: syntaxes[i],
13962
+ errors: [],
13963
+ };
13725
13964
  case ValidationTokenEnum.CloseParenthesis:
13726
13965
  if (token.typ === exports.EnumToken.EndParensTokenType) {
13727
13966
  options.visited.get(token).delete(syntaxes[i]);
@@ -13923,6 +14162,7 @@
13923
14162
  };
13924
14163
  }
13925
14164
  switch (property.val) {
14165
+ case "function-parameter":
13926
14166
  case "declaration-value":
13927
14167
  {
13928
14168
  // consume a declaration value
@@ -13932,18 +14172,43 @@
13932
14172
  // if semicolon or end curly brace is encountered, stop
13933
14173
  let expectToken = true;
13934
14174
  let token;
14175
+ const stack = [];
13935
14176
  token = context.peek();
13936
- while ((token = context.peek()) != null) {
13937
- if (token.typ == exports.EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) ;
13938
- if (expectToken) {
13939
- expectToken = false;
13940
- }
13941
- if (token.typ == exports.EnumToken.CommaTokenType) {
13942
- expectToken = true;
14177
+ if (token != null) {
14178
+ success = false;
14179
+ while ((token = context.peek()) != null) {
14180
+ if (token.typ == exports.EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
14181
+ stack.push(token);
14182
+ }
14183
+ if (expectToken) {
14184
+ expectToken = false;
14185
+ }
14186
+ if (token.typ == exports.EnumToken.CommaTokenType) {
14187
+ expectToken = true;
14188
+ }
14189
+ if (token.typ == exports.EnumToken.EndParensTokenType) {
14190
+ if (stack.length > 0) {
14191
+ stack.pop();
14192
+ }
14193
+ else {
14194
+ expectToken = false;
14195
+ break;
14196
+ }
14197
+ }
14198
+ context.next();
13943
14199
  }
13944
- context.next();
13945
14200
  }
13946
14201
  success = !expectToken;
14202
+ if (success) {
14203
+ return {
14204
+ success,
14205
+ valid: true,
14206
+ token: null,
14207
+ context,
14208
+ syntaxToken: property,
14209
+ errors: [],
14210
+ };
14211
+ }
13947
14212
  }
13948
14213
  break;
13949
14214
  case "calc-sum": {
@@ -13976,9 +14241,6 @@
13976
14241
  }
13977
14242
  break;
13978
14243
  }
13979
- // case "at-keyword-token":
13980
- // success = context.peek()?.typ === EnumToken.AtRuleTokenType;
13981
- // break;
13982
14244
  case "an+b":
13983
14245
  {
13984
14246
  let token = context.peek();
@@ -14043,9 +14305,6 @@
14043
14305
  Object.assign(token, { typ: exports.EnumToken.Add });
14044
14306
  }
14045
14307
  token = context.peek(2);
14046
- // if (token == null) {
14047
- // break;
14048
- // }
14049
14308
  if (token?.typ === exports.EnumToken.NumberTokenType &&
14050
14309
  Number.isInteger(token.val) &&
14051
14310
  !token.toString().includes(".") &&
@@ -14153,9 +14412,6 @@
14153
14412
  break;
14154
14413
  case "dimension": {
14155
14414
  const token = context.peek();
14156
- // if (token == null) {
14157
- // break;
14158
- // }
14159
14415
  success =
14160
14416
  token?.typ == exports.EnumToken.DimensionTokenType ||
14161
14417
  token?.typ == exports.EnumToken.AngleTokenType ||
@@ -14164,25 +14420,20 @@
14164
14420
  token?.typ == exports.EnumToken.ResolutionTokenType ||
14165
14421
  token?.typ == exports.EnumToken.TimeTokenType ||
14166
14422
  token?.typ == exports.EnumToken.FrequencyTokenType ||
14423
+ token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
14167
14424
  token?.typ == exports.EnumToken.FlexTokenType;
14168
14425
  break;
14169
14426
  }
14170
14427
  case "angle":
14171
14428
  {
14172
14429
  const token = context.peek();
14173
- // if (token == null) {
14174
- // break;
14175
- // }
14176
- success = token?.typ === exports.EnumToken.AngleTokenType;
14430
+ success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.UserDefinedDimensionTokenType;
14177
14431
  }
14178
14432
  break;
14179
14433
  case "angle-percentage":
14180
14434
  {
14181
14435
  const token = context.peek();
14182
- // if (token == null) {
14183
- // break;
14184
- // }
14185
- success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.PercentageTokenType;
14436
+ success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.UserDefinedDimensionTokenType || token?.typ === exports.EnumToken.PercentageTokenType;
14186
14437
  }
14187
14438
  break;
14188
14439
  case "percentage":
@@ -14197,25 +14448,21 @@
14197
14448
  case "length-percentage":
14198
14449
  {
14199
14450
  const token = context.peek();
14200
- // if (token == null) {
14201
- // break;
14202
- // }
14203
14451
  success =
14204
14452
  token?.typ == exports.EnumToken.PercentageTokenType ||
14205
14453
  token?.typ == exports.EnumToken.LengthTokenType ||
14454
+ token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
14206
14455
  (token?.typ == exports.EnumToken.NumberTokenType && token?.val === 0);
14207
14456
  }
14208
14457
  break;
14209
14458
  case "flex":
14210
- success = context.peek()?.typ == exports.EnumToken.FlexTokenType;
14459
+ success = context.peek()?.typ == exports.EnumToken.FlexTokenType || context.peek()?.typ == exports.EnumToken.UserDefinedDimensionTokenType;
14211
14460
  break;
14212
14461
  case "length": {
14213
14462
  const token = context.peek();
14214
- // if (token == null) {
14215
- // break;
14216
- // }
14217
14463
  success =
14218
14464
  token?.typ == exports.EnumToken.LengthTokenType ||
14465
+ token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
14219
14466
  (token?.typ == exports.EnumToken.NumberTokenType && token?.val === 0);
14220
14467
  break;
14221
14468
  }
@@ -14225,15 +14472,9 @@
14225
14472
  if (token == null) {
14226
14473
  break;
14227
14474
  }
14228
- success = token.typ == exports.EnumToken.TimeTokenType;
14475
+ success = token.typ == exports.EnumToken.TimeTokenType || token.typ == exports.EnumToken.UserDefinedDimensionTokenType;
14229
14476
  }
14230
14477
  break;
14231
- // case "hex-color": {
14232
- // const token = context.peek();
14233
- // success =
14234
- // token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
14235
- // break;
14236
- // }
14237
14478
  case "color":
14238
14479
  case "color-function":
14239
14480
  {
@@ -14241,13 +14482,6 @@
14241
14482
  const errors = [];
14242
14483
  if (tokensfuncDefMap.has(token?.typ)) {
14243
14484
  const range = context.peekRange();
14244
- // if (
14245
- // range.some(
14246
- // (token) =>
14247
- // token.typ == EnumToken.IdenTokenType &&
14248
- // "hslrgbchwmyk".split("").some((t) => equalsIgnoreCase(t, (token as IdentToken).val)),
14249
- // )
14250
- // ) {
14251
14485
  const newRange = range.map((t) => cloneNode(t, true));
14252
14486
  // @ts-ignore
14253
14487
  parseTokens(newRange, { parseColor: true }, errors);
@@ -14272,27 +14506,6 @@
14272
14506
  syntaxToken: null,
14273
14507
  errors,
14274
14508
  };
14275
- // }
14276
- // const result = matchSyntax(
14277
- // getParsedSyntax(
14278
- // ValidationSyntaxGroupEnum.Syntaxes,
14279
- // (token as FunctionToken).val + "()",
14280
- // ) as ValidationFunctionToken[],
14281
- // createValidationContext(range),
14282
- // options,
14283
- // );
14284
- // if (result.success) {
14285
- // context.update(range.at(-1) as Token);
14286
- // return {
14287
- // success: true,
14288
- // valid: true,
14289
- // token: context.peek(),
14290
- // context,
14291
- // syntaxToken: null,
14292
- // errors: [],
14293
- // };
14294
- // }
14295
- // return result;
14296
14509
  }
14297
14510
  // @ts-expect-error
14298
14511
  else if ("chi" in token) {
@@ -14311,10 +14524,6 @@
14311
14524
  }
14312
14525
  }
14313
14526
  break;
14314
- // case "url-token":
14315
- // success =
14316
- // context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
14317
- // break;
14318
14527
  case "type-selector":
14319
14528
  case "compound-selector":
14320
14529
  case "complex-selector":
@@ -14339,15 +14548,6 @@
14339
14548
  };
14340
14549
  }
14341
14550
  case "function-token":
14342
- // if (
14343
- // context.peek()?.typ == EnumToken.IdenTokenType &&
14344
- // context.peek(1, false)?.typ == EnumToken.StartParensTokenType
14345
- // ) {
14346
- // context.next();
14347
- // context.next();
14348
- // success = true;
14349
- // break;
14350
- // }
14351
14551
  if (tokensfuncDefMap.has(context.peek()?.typ)) {
14352
14552
  success = true;
14353
14553
  context.next();
@@ -14369,17 +14569,6 @@
14369
14569
  config$3.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
14370
14570
  break;
14371
14571
  }
14372
- // case "named-color": {
14373
- // const token = context.peek();
14374
- // success =
14375
- // token != null &&
14376
- // token.typ == EnumToken.ColorTokenType &&
14377
- // ((token as ColorToken).kin == ColorType.LIT ||
14378
- // (token as ColorToken).kin == ColorType.SYS ||
14379
- // (token as ColorToken).kin == ColorType.DPSYS ||
14380
- // (token as ColorToken).kin == ColorType.NON_STD);
14381
- // break;
14382
- // }
14383
14572
  case "size-feature": {
14384
14573
  const range = context.peekRange();
14385
14574
  const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
@@ -14410,20 +14599,6 @@
14410
14599
  errors: [],
14411
14600
  };
14412
14601
  }
14413
- // if (filteredRange.length === 3) {
14414
- // success = isValue(filteredRange[2]);
14415
- // if (success) {
14416
- // context.update(filteredRange[2]);
14417
- // return {
14418
- // success,
14419
- // valid: true,
14420
- // token: filteredRange[2],
14421
- // context,
14422
- // syntaxToken: property,
14423
- // errors: [],
14424
- // };
14425
- // }
14426
- // }
14427
14602
  break;
14428
14603
  }
14429
14604
  case "style-feature": {
@@ -14433,16 +14608,6 @@
14433
14608
  // match <style-range>
14434
14609
  const range = context.peekRange();
14435
14610
  const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
14436
- // if (filteredRange.length === 0) {
14437
- // return {
14438
- // success: false,
14439
- // valid: true,
14440
- // token: context.peek(),
14441
- // context,
14442
- // syntaxToken: property,
14443
- // errors: [],
14444
- // };
14445
- // }
14446
14611
  if (filteredRange.length === 1) {
14447
14612
  success =
14448
14613
  filteredRange[0].typ === exports.EnumToken.IdenTokenType ||
@@ -14457,31 +14622,6 @@
14457
14622
  errors: [],
14458
14623
  };
14459
14624
  }
14460
- // if (
14461
- // filteredRange[1]?.typ === EnumToken.ColonTokenType ||
14462
- // filteredRange[1]?.typ === EnumToken.DelimTokenType
14463
- // ) {
14464
- // const result = isDeclarationValue(filteredRange.slice(2));
14465
- // if (result.success) {
14466
- // context.update(filteredRange.at(-1)!);
14467
- // return {
14468
- // success: true,
14469
- // valid: true,
14470
- // token: filteredRange.at(-1)!,
14471
- // context,
14472
- // syntaxToken: property,
14473
- // errors: [],
14474
- // };
14475
- // }
14476
- // return {
14477
- // success: false,
14478
- // valid: false,
14479
- // token: context.peek(),
14480
- // context,
14481
- // syntaxToken: property,
14482
- // errors: result.errors,
14483
- // };
14484
- // }
14485
14625
  return {
14486
14626
  success: false,
14487
14627
  valid: false,
@@ -14493,10 +14633,6 @@
14493
14633
  }
14494
14634
  case "url": {
14495
14635
  const token = context.peek();
14496
- // if (token == null) {
14497
- // success = false;
14498
- // break;
14499
- // }
14500
14636
  let l;
14501
14637
  if (token?.typ == exports.EnumToken.UrlFunctionTokenDefType) {
14502
14638
  l = 0;
@@ -14510,11 +14646,6 @@
14510
14646
  (token.typ == exports.EnumToken.StringTokenType ||
14511
14647
  token.typ == exports.EnumToken.IdenTokenType ||
14512
14648
  token.typ == exports.EnumToken.UrlTokenTokenType)) {
14513
- // if (token.typ === EnumToken.IdenTokenType) {
14514
- // while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
14515
- // l++;
14516
- // }
14517
- // }
14518
14649
  while ((token = context.peek(++l))) {
14519
14650
  if (token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType) {
14520
14651
  break;
@@ -14578,10 +14709,46 @@
14578
14709
  }
14579
14710
  break;
14580
14711
  }
14712
+ case "dashed-function": {
14713
+ const token = context.peek();
14714
+ success = token?.typ == exports.EnumToken.CustomFunctionTokenDefType;
14715
+ if (success) {
14716
+ context.next();
14717
+ return {
14718
+ success: true,
14719
+ valid: true,
14720
+ token,
14721
+ context,
14722
+ syntaxToken: null,
14723
+ errors: [],
14724
+ };
14725
+ }
14726
+ break;
14727
+ }
14728
+ case "block-contents":
14729
+ success = context.peek()?.typ == exports.EnumToken.StartParensTokenType;
14730
+ if (success) {
14731
+ context.next();
14732
+ return {
14733
+ success: true,
14734
+ valid: true,
14735
+ token: null,
14736
+ context,
14737
+ syntaxToken: null,
14738
+ errors: [],
14739
+ };
14740
+ }
14741
+ return {
14742
+ success: false,
14743
+ valid: true,
14744
+ token,
14745
+ context,
14746
+ syntaxToken: property,
14747
+ errors: [],
14748
+ };
14581
14749
  default:
14582
14750
  if (!(property.val in config$3.syntaxes)) {
14583
14751
  console.debug("Unknown syntax", context.peek(), property);
14584
- console.debug(context.getRemainingTokens());
14585
14752
  throw new Error(`Unexpected validation property ${property.val}`);
14586
14753
  }
14587
14754
  return matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
@@ -17617,7 +17784,7 @@
17617
17784
  }
17618
17785
  }
17619
17786
  for (const { value, parent: parentValue } of walkValues(node.val)) {
17620
- if (value.typ == exports.EnumToken.MathFunctionTokenDefType ||
17787
+ if (value.typ == exports.EnumToken.MathFunctionTokenType ||
17621
17788
  (value.typ == exports.EnumToken.WildCardFunctionTokenType && value.val == "var")) {
17622
17789
  if (value.chi.length == 1 &&
17623
17790
  value.chi[0].typ == exports.EnumToken.DashedIdenTokenType) {
@@ -17625,9 +17792,10 @@
17625
17792
  if (info?.replaceable) {
17626
17793
  if (parentValue != null) {
17627
17794
  let i = 0;
17628
- for (; i < parentValue.chi.length; i++) {
17629
- if (parentValue.chi[i] == value) {
17630
- parentValue.chi.splice(i, 1, ...info.node.val);
17795
+ const source = parentValue.typ == exports.EnumToken.DeclarationNodeType ? parentValue.val : parentValue.chi;
17796
+ for (; i < source.length; i++) {
17797
+ if (source[i] == value) {
17798
+ source.splice(i, 1, ...info.node.val);
17631
17799
  break;
17632
17800
  }
17633
17801
  }
@@ -20085,7 +20253,7 @@
20085
20253
  if (value instanceof PropertyMap) {
20086
20254
  for (const [k, v] of value.declarations) {
20087
20255
  if (k == value.config.shorthand) {
20088
- for (const [key, val] of Object.entries(value.config.properties)) {
20256
+ for (const [key] of Object.entries(value.config.properties)) {
20089
20257
  mapped[key] = cloneNode(v);
20090
20258
  for (let i = 0; i < v.val.length; i++) {
20091
20259
  // @ts-ignore
@@ -20861,18 +21029,43 @@
20861
21029
  * Represents a list of property declarations, compute shorthand and remove duplicate declarations.
20862
21030
  */
20863
21031
  class PropertyList {
21032
+ /**
21033
+ * options
21034
+ */
20864
21035
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
21036
+ /**
21037
+ * declarations
21038
+ */
20865
21039
  declarations;
21040
+ /**
21041
+ *
21042
+ * @param options
21043
+ */
20866
21044
  constructor(options = {}) {
20867
21045
  this.options = options;
20868
21046
  this.declarations = new Map();
20869
21047
  }
21048
+ /**
21049
+ * add declarations
21050
+ * @param declarations
21051
+ * @returns
21052
+ */
20870
21053
  add(declarations) {
20871
21054
  let name;
20872
21055
  let syntaxRules = null;
20873
21056
  let result;
20874
21057
  for (const declaration of declarations) {
20875
21058
  name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
21059
+ // do not compute shorthand for invalid declarations
21060
+ if (name == null) {
21061
+ this.declarations.set(objectHash(declaration), declaration);
21062
+ continue;
21063
+ }
21064
+ // @functiom / result
21065
+ if (declaration[STATE] & exports.EnumAstNodeStatus.Unknown && equalsIgnoreCase("result", name)) {
21066
+ this.declarations.set(declaration.nam, declaration);
21067
+ continue;
21068
+ }
20876
21069
  if (declaration[STATE] &
20877
21070
  (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
20878
21071
  declaration.typ != exports.EnumToken.DeclarationNodeType ||
@@ -20996,6 +21189,11 @@
20996
21189
  }
20997
21190
  return this;
20998
21191
  }
21192
+ /**
21193
+ *
21194
+ * @param declaration
21195
+ * @param mapping
21196
+ */
20999
21197
  mapValues(declaration, mapping) {
21000
21198
  let name;
21001
21199
  let values = declaration.val;
@@ -21055,6 +21253,10 @@
21055
21253
  }
21056
21254
  }
21057
21255
  }
21256
+ /**
21257
+ *
21258
+ * @returns
21259
+ */
21058
21260
  [Symbol.iterator]() {
21059
21261
  let iterator = this.declarations.values();
21060
21262
  const iterators = [];
@@ -21110,32 +21312,49 @@
21110
21312
  let l;
21111
21313
  const rules = [];
21112
21314
  const declarations = [];
21113
- // @ts-ignore
21114
- for (; k < j; k++) {
21115
- l = k;
21116
- // capture comments with the next token
21117
- while (l + 1 < j) {
21118
- // @ts-ignore
21119
- const node = ast.chi[l];
21120
- if (node.typ == exports.EnumToken.CommentNodeType) {
21121
- l++;
21122
- continue;
21123
- }
21124
- break;
21315
+ let doNotSort = false;
21316
+ if (ast.typ == exports.EnumToken.AtRuleNodeType) {
21317
+ switch (ast.nam) {
21318
+ case "function":
21319
+ case "mixin":
21320
+ doNotSort = true;
21321
+ break;
21322
+ }
21323
+ }
21324
+ // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
21325
+ if (doNotSort) {
21326
+ for (const node of ast.chi) {
21327
+ declarations.push(node);
21125
21328
  }
21329
+ }
21330
+ else {
21126
21331
  // @ts-ignore
21127
- const node = ast.chi[l];
21128
- if (node.typ == exports.EnumToken.DeclarationNodeType) {
21129
- for (let m = k; m <= l; m++) {
21130
- declarations.push(ast.chi[m]);
21332
+ for (; k < j; k++) {
21333
+ l = k;
21334
+ // capture comments with the next token
21335
+ while (l + 1 < j) {
21336
+ // @ts-ignore
21337
+ const node = ast.chi[l];
21338
+ if (node.typ == exports.EnumToken.CommentNodeType) {
21339
+ l++;
21340
+ continue;
21341
+ }
21342
+ break;
21131
21343
  }
21132
- }
21133
- else {
21134
- for (let m = k; m <= l; m++) {
21135
- rules.push(ast.chi[m]);
21344
+ // @ts-ignore
21345
+ const node = ast.chi[l];
21346
+ if (node.typ == exports.EnumToken.DeclarationNodeType) {
21347
+ for (let m = k; m <= l; m++) {
21348
+ declarations.push(ast.chi[m]);
21349
+ }
21136
21350
  }
21351
+ else {
21352
+ for (let m = k; m <= l; m++) {
21353
+ rules.push(ast.chi[m]);
21354
+ }
21355
+ }
21356
+ k = l;
21137
21357
  }
21138
- k = l;
21139
21358
  }
21140
21359
  if (declarations.length > 0) {
21141
21360
  ast.chi.length = 0;
@@ -21155,6 +21374,7 @@
21155
21374
  exports.EnumToken.LteTokenType,
21156
21375
  exports.EnumToken.ChildCombinatorTokenType,
21157
21376
  exports.EnumToken.PipeTokenType,
21377
+ exports.EnumToken.ColonTokenType,
21158
21378
  ]);
21159
21379
  const trimSpaceAfter = new Set([
21160
21380
  ...tokensfuncSet.values(),
@@ -21176,9 +21396,16 @@
21176
21396
  if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
21177
21397
  throw new TypeError(`replacement is null`);
21178
21398
  }
21179
- for (const newNode of Array.isArray(replacement) ? replacement : [replacement]) {
21180
- if (newNode[PARENT] != node[PARENT]) {
21181
- newNode[PARENT] = node[PARENT];
21399
+ if (!Array.isArray(replacement)) {
21400
+ if (replacement[PARENT] != parent) {
21401
+ replacement[PARENT] = parent;
21402
+ }
21403
+ }
21404
+ else {
21405
+ for (const newNode of replacement) {
21406
+ if (newNode[PARENT] != parent) {
21407
+ newNode[PARENT] = parent;
21408
+ }
21182
21409
  }
21183
21410
  }
21184
21411
  if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
@@ -22661,9 +22888,9 @@
22661
22888
  * @returns
22662
22889
  */
22663
22890
  function find(ast, matcher) {
22664
- for (const { node, parent } of walk(ast)) {
22665
- if (matcher(node, parent)) {
22666
- return node;
22891
+ for (const r of walk(ast)) {
22892
+ if (matcher(r.node, r.parent)) {
22893
+ return r.node;
22667
22894
  }
22668
22895
  }
22669
22896
  return null;
@@ -22702,21 +22929,25 @@
22702
22929
  */
22703
22930
  function findByValue(ast, matcher) {
22704
22931
  let source;
22705
- for (const { node } of walk(ast)) {
22932
+ for (const r1 of walk(ast)) {
22706
22933
  source = null;
22707
- if (node.typ === exports.EnumToken.DeclarationNodeType) {
22708
- source = node.val;
22934
+ if (r1.node.typ === exports.EnumToken.DeclarationNodeType) {
22935
+ source = r1.node.val;
22709
22936
  }
22710
- else if (Array.isArray(node[TOKENS])) {
22711
- source = node[TOKENS];
22937
+ else if (Array.isArray(r1.node[TOKENS])) {
22938
+ source = r1.node[TOKENS];
22712
22939
  }
22713
22940
  if (source == null) {
22714
22941
  continue;
22715
22942
  }
22716
- for (const { value, parent, root: rootNode, parents } of walkValues(source, node)) {
22717
- if (matcher(value, node)) {
22718
- // @ts-ignore
22719
- return { node, value: { node: value, parent, root: rootNode, parents } };
22943
+ for (const r2 of walkValues(source, r1.node)) {
22944
+ if (matcher(r2.value, r1.node)) {
22945
+ return {
22946
+ // @ts-ignore
22947
+ node: r1.node,
22948
+ // @ts-ignore
22949
+ value: { node: r2.value, parent: r2.parent, root: r2.root, parents: r2.parents },
22950
+ };
22720
22951
  }
22721
22952
  }
22722
22953
  }
@@ -22758,9 +22989,9 @@
22758
22989
  */
22759
22990
  function findAll(ast, matcher) {
22760
22991
  const result = [];
22761
- for (const { node, parent } of walk(ast)) {
22762
- if (matcher(node, parent)) {
22763
- result.push(node);
22992
+ for (const r of walk(ast)) {
22993
+ if (matcher(r.node, r.node[PARENT])) {
22994
+ result.push(r.node);
22764
22995
  }
22765
22996
  }
22766
22997
  return result;
@@ -22796,11 +23027,12 @@
22796
23027
  * @returns
22797
23028
  */
22798
23029
  function findLast(ast, matcher) {
22799
- for (const { node, parent } of walk(ast, null, true)) {
22800
- if (matcher(node, parent)) {
22801
- return node;
23030
+ for (const result of walk(ast, null, true))
23031
+ // for (const { node, parent } of walk(ast as AstNode, null, true)) {
23032
+ if (matcher(result.node, result.parent)) {
23033
+ return result.node;
22802
23034
  }
22803
- }
23035
+ // }
22804
23036
  return null;
22805
23037
  }
22806
23038
 
@@ -23343,8 +23575,35 @@
23343
23575
  previous = ast.chi[--nodeIndex];
23344
23576
  }
23345
23577
  node = ast.chi[i];
23346
- if (node.typ === exports.EnumToken.AtRuleNodeType && node.nam === "font-face") {
23347
- continue;
23578
+ if (node.typ === exports.EnumToken.AtRuleNodeType) {
23579
+ if (node.nam === "font-face") {
23580
+ continue;
23581
+ }
23582
+ // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
23583
+ if (equalsIgnoreCase(node.nam, "function")) {
23584
+ const chi = node.chi;
23585
+ let k = chi?.length;
23586
+ let slice = false;
23587
+ while (k--) {
23588
+ if (chi[k].typ === exports.EnumToken.CommentNodeType ||
23589
+ chi[k].typ === exports.EnumToken.WhitespaceTokenType) {
23590
+ continue;
23591
+ }
23592
+ if (chi[k].typ === exports.EnumToken.DeclarationNodeType &&
23593
+ equalsIgnoreCase(chi[k].nam, "result")) {
23594
+ slice = true;
23595
+ break;
23596
+ }
23597
+ }
23598
+ if (k > 0 && slice) {
23599
+ while (k--) {
23600
+ if (chi[k].typ === exports.EnumToken.AtRuleNodeType) {
23601
+ chi.splice(k, 1);
23602
+ continue;
23603
+ }
23604
+ }
23605
+ }
23606
+ }
23348
23607
  }
23349
23608
  if (node.typ === exports.EnumToken.KeyframesAtRuleNodeType) {
23350
23609
  if (previous?.typ === exports.EnumToken.KeyframesAtRuleNodeType &&
@@ -25879,7 +26138,7 @@
25879
26138
  case exports.EnumToken.KeyframesRuleNodeType:
25880
26139
  case exports.EnumToken.KeyframesAtRuleNodeType:
25881
26140
  if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframesAtRuleNodeType].includes(data.typ) && !("chi" in data)) {
25882
- return `${indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
26141
+ return `${(indent.length > 0 ? options.newLine : "") + indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
25883
26142
  }
25884
26143
  const lineMapLength = linesMap ? linesMap.getLineStarts().length : 0;
25885
26144
  const prelude = (indent.length > 0 ? options.newLine : "") +
@@ -26704,6 +26963,7 @@
26704
26963
  case exports.EnumToken.DimensionTokenType:
26705
26964
  case exports.EnumToken.FrequencyTokenType:
26706
26965
  case exports.EnumToken.ResolutionTokenType:
26966
+ case exports.EnumToken.UserDefinedDimensionTokenType:
26707
26967
  let val = token.val.typ == exports.EnumToken.FractionTokenType
26708
26968
  ? renderValue(token.val, options, cache)
26709
26969
  : minifyNumber(token.val);
@@ -26903,8 +27163,10 @@
26903
27163
  case exports.EnumToken.BadUrlTokenType:
26904
27164
  case exports.EnumToken.EOFTokenType:
26905
27165
  return "";
27166
+ case exports.EnumToken.ComposesSelectorNodeType:
27167
+ return `${token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "")}${token.r == null ? "" : " from " + renderValue(token.r, options, cache, reducer)}`;
26906
27168
  default:
26907
- console.debug({ token });
27169
+ console.error({ token });
26908
27170
  throw new Error(`Unsupported token type for ${exports.EnumToken[token.typ]}`);
26909
27171
  }
26910
27172
  // errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
@@ -26967,7 +27229,6 @@
26967
27229
  SymbolsMapTokensLower[key.toLowerCase()] = tokenType;
26968
27230
  }
26969
27231
  }
26970
- SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType;
26971
27232
  SymbolsMapTokens["+"] = exports.EnumToken.Plus;
26972
27233
  SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType;
26973
27234
  SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType;
@@ -27416,6 +27677,11 @@
27416
27677
  hasLetter = true;
27417
27678
  break;
27418
27679
  }
27680
+ // dashed ident as unit
27681
+ if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
27682
+ hasLetter = true;
27683
+ break;
27684
+ }
27419
27685
  return 0;
27420
27686
  }
27421
27687
  if (!hasLetter && !hasPercent) {
@@ -27444,6 +27710,10 @@
27444
27710
  else if (isLetter(codepoint)) {
27445
27711
  hasLetter = true;
27446
27712
  }
27713
+ // custom ident as unit
27714
+ else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
27715
+ hasLetter = true;
27716
+ }
27447
27717
  else {
27448
27718
  return 0;
27449
27719
  }
@@ -27481,6 +27751,10 @@
27481
27751
  hasLetter = true;
27482
27752
  break;
27483
27753
  }
27754
+ else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
27755
+ hasLetter = true;
27756
+ break;
27757
+ }
27484
27758
  if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
27485
27759
  hasPercent = true;
27486
27760
  break;
@@ -27544,6 +27818,11 @@
27544
27818
  hasLetter = true;
27545
27819
  break;
27546
27820
  }
27821
+ // custom ident as unit
27822
+ else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
27823
+ hasLetter = true;
27824
+ break;
27825
+ }
27547
27826
  else if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
27548
27827
  hasPercent = true;
27549
27828
  break;
@@ -27585,7 +27864,7 @@
27585
27864
  const slice = codepoint == 0x45 || codepoint == 0x65 ? position - 1 : position;
27586
27865
  while (position + 1 <= parseInfo.stream.length) {
27587
27866
  codepoint = parseInfo.stream.charCodeAt(++position);
27588
- if (!isLetter(codepoint)) {
27867
+ if (!isLetter(codepoint) && codepoint != 0x2d) {
27589
27868
  break;
27590
27869
  }
27591
27870
  }
@@ -27870,6 +28149,9 @@
27870
28149
  this.val = parseFloat(parseInfo.stream.slice(parseInfo.position - parseInfo.offset, options?.slice));
27871
28150
  if (hint != exports.EnumToken.PercentageTokenType) {
27872
28151
  this.unit = val;
28152
+ if (val.startsWith("--")) {
28153
+ this.typ = exports.EnumToken.UserDefinedDimensionTokenType;
28154
+ }
27873
28155
  }
27874
28156
  }
27875
28157
  else if (hint == exports.EnumToken.NumberTokenType) {
@@ -29625,7 +29907,7 @@
29625
29907
  Object.assign(stream[i], {
29626
29908
  typ: val === "and" ? exports.EnumToken.AndTokenType : exports.EnumToken.OrTokenType,
29627
29909
  });
29628
- if (val === "or" && scopes.length <= 1) {
29910
+ if (val === "or" && (scopes.length == 1 && scopes[0].size > 0 && !scopes[0].has(exports.EnumToken.OrTokenType))) {
29629
29911
  success = false;
29630
29912
  errors.push({
29631
29913
  action: "drop",
@@ -30141,7 +30423,7 @@
30141
30423
  break;
30142
30424
  }
30143
30425
  if ("and" === val || "or" === val) {
30144
- if ("or" === val && scopes.length === 1) {
30426
+ if ("or" === val && scopes.length === 1 && scopes[0].size > 0) {
30145
30427
  const fileName = options.source.getFileName() ?? "";
30146
30428
  const [line, column] = options.source.getOffsets(stream[i]?.[LOCSTA]);
30147
30429
  return {
@@ -31224,19 +31506,10 @@
31224
31506
  key = visitors[i][0];
31225
31507
  value = visitors[i][1];
31226
31508
  if (Number.isInteger(+key)) {
31227
- // if (Array.isArray(value)) {
31228
- // visitors.splice(i + 1, 0, ...Object.entries(value));
31229
- // continue;
31230
- // }
31231
31509
  if (typeof value == "function") {
31232
31510
  key = value.name;
31233
31511
  }
31234
31512
  }
31235
- // if (Array.isArray(value)) {
31236
- // // @ts-ignore
31237
- // visitors.splice(i + 1, 0, ...value.map((item) => [key, item]));
31238
- // continue;
31239
- // }
31240
31513
  if (key in exports.EnumToken) {
31241
31514
  if (typeof value == "function") {
31242
31515
  if (!valuesHandlers.has(exports.EnumToken[key])) {
@@ -31596,7 +31869,7 @@
31596
31869
  if (tokens.length > 0) {
31597
31870
  node = parseNode(tokens, context, options, errors, stats, invalidNodes);
31598
31871
  if (node != null) {
31599
- if ("chi" in node /* && node.typ != EnumToken.InvalidRuleNodeType */) {
31872
+ if ("chi" in node) {
31600
31873
  stack.push(node);
31601
31874
  context = node;
31602
31875
  }
@@ -31610,54 +31883,208 @@
31610
31883
  if (options.visitor != null) {
31611
31884
  const handlers = [];
31612
31885
  const visitors = parseVisitors(options.visitor, errors);
31613
- const subNodes = [];
31614
31886
  let parens;
31615
31887
  let genericKey;
31616
- let nodes = new Array(stats.tokensCount);
31617
- let i;
31618
- let k;
31619
- let j;
31620
- let freeBlock = 1;
31621
- nodes[0] = ast;
31622
- for (i = 0; i < nodes.length; i++) {
31623
- if (nodes[i] == null) {
31624
- break;
31625
- }
31626
- subNodes.length = 0;
31888
+ let nodes = [ast];
31889
+ let node;
31890
+ while (nodes.length > 0) {
31891
+ node = nodes.pop();
31627
31892
  if (visitors.includeTokens) {
31628
- switch (nodes[i].typ) {
31893
+ switch (node.typ) {
31629
31894
  case exports.EnumToken.RuleNodeType:
31630
31895
  case exports.EnumToken.AtRuleNodeType:
31631
31896
  case exports.EnumToken.KeyframesRuleNodeType:
31632
31897
  case exports.EnumToken.KeyframesAtRuleNodeType:
31633
- for (const token of nodes[i][TOKENS]) {
31634
- subNodes.push(token);
31898
+ for (let i =
31899
+ // @ts-ignore
31900
+ node[TOKENS].length -
31901
+ 1; i >= 0; i--) {
31902
+ // @ts-ignore
31903
+ node[TOKENS][i][PARENT] =
31904
+ node;
31905
+ nodes.push(
31906
+ // @ts-ignore
31907
+ node[TOKENS][i]);
31635
31908
  }
31636
31909
  break;
31637
31910
  case exports.EnumToken.DeclarationNodeType:
31638
- for (const token of nodes[i].val) {
31639
- subNodes.push(token);
31911
+ for (let i =
31912
+ // @ts-ignore
31913
+ node.val.length - 1; i >= 0; i--) {
31914
+ node.val[i][PARENT] = node;
31915
+ // @ts-ignore
31916
+ nodes.push(node.val[i]);
31640
31917
  }
31641
31918
  break;
31642
31919
  }
31920
+ // @ts-ignore
31921
+ // if (node.l != null) {
31922
+ // // @ts-ignore
31923
+ // if (node.op2 != null) {
31924
+ // // @ts-ignore
31925
+ // nodes.push(node.op2);
31926
+ // // @ts-ignore
31927
+ // node.op2[PARENT] = node;
31928
+ // }
31929
+ // // @ts-ignore
31930
+ // if (node.op1 != null) {
31931
+ // // @ts-ignore
31932
+ // nodes.push(node.op1);
31933
+ // // @ts-ignore
31934
+ // node.op1[PARENT] = node;
31935
+ // }
31936
+ // // @ts-ignore
31937
+ // if (nodes.op != null && node.op.typ != null) {
31938
+ // // @ts-ignore
31939
+ // nodes.push(node.op);
31940
+ // // @ts-ignore
31941
+ // node.op[PARENT] = node;
31942
+ // }
31943
+ // // @ts-ignore
31944
+ // if (node.r != null) {
31945
+ // // @ts-ignore
31946
+ // if (Array.isArray(node.r)) {
31947
+ // // @ts-ignore
31948
+ // for (let i = node.r.length - 1; i >= 0; i--) {
31949
+ // // @ts-ignore
31950
+ // nodes.push(node.r[i]);
31951
+ // // @ts-ignore
31952
+ // node.r[i][PARENT] = node;
31953
+ // }
31954
+ // } else {
31955
+ // // @ts-ignore
31956
+ // nodes.push(node.r);
31957
+ // // @ts-ignore
31958
+ // node.r[PARENT] = node;
31959
+ // }
31960
+ // }
31961
+ // // @ts-ignore
31962
+ // if (Array.isArray(node.l)) {
31963
+ // // @ts-ignore
31964
+ // for (let i = node.l.length - 1; i >= 0; i--) {
31965
+ // // @ts-ignore
31966
+ // nodes.push(node.l[i]);
31967
+ // // @ts-ignore
31968
+ // node.l[i][PARENT] = node;
31969
+ // }
31970
+ // } else {
31971
+ // // @ts-ignore
31972
+ // nodes.push(node.l);
31973
+ // // @ts-ignore
31974
+ // node.l[PARENT] = node;
31975
+ // }
31976
+ // }
31977
+ }
31978
+ switch (node.typ) {
31979
+ case exports.EnumToken.BinaryExpressionTokenType:
31980
+ case exports.EnumToken.IfElseConditionTokenType:
31981
+ nodes.push(node.r);
31982
+ node.r[PARENT] = node;
31983
+ nodes.push(node.l);
31984
+ node.l[PARENT] = node;
31985
+ break;
31986
+ case exports.EnumToken.MatchExpressionTokenType:
31987
+ nodes.push(node.r);
31988
+ node.r[PARENT] = node;
31989
+ nodes.push(node.op);
31990
+ node.op[PARENT] = node;
31991
+ nodes.push(node.l);
31992
+ node.l[PARENT] = node;
31993
+ break;
31994
+ case exports.EnumToken.SupportsQueryConditionTokenType:
31995
+ case exports.EnumToken.MediaQueryConditionTokenType:
31996
+ for (let i = node.r.length - 1; i >= 0; i--) {
31997
+ const element = node.r[i];
31998
+ nodes.push(element);
31999
+ element[PARENT] = node;
32000
+ }
32001
+ nodes.push(node.op);
32002
+ node.op[PARENT] = node;
32003
+ for (let i = node.l.length - 1; i >= 0; i--) {
32004
+ const element = node.l[i];
32005
+ nodes.push(element);
32006
+ element[PARENT] = node;
32007
+ }
32008
+ break;
32009
+ case exports.EnumToken.WhenElseQueryConditionTokenType:
32010
+ for (let i = node.r.length - 1; i >= 0; i--) {
32011
+ const element = node.r[i];
32012
+ nodes.push(element);
32013
+ element[PARENT] = node;
32014
+ }
32015
+ nodes.push(node.l);
32016
+ node.l[PARENT] = node;
32017
+ break;
32018
+ case exports.EnumToken.IfConditionTokenType:
32019
+ for (let i = node.r.length - 1; i >= 0; i--) {
32020
+ const element = node.r[i];
32021
+ nodes.push(element);
32022
+ element[PARENT] = node;
32023
+ }
32024
+ for (let i = node.l.length - 1; i >= 0; i--) {
32025
+ const element = node.l[i];
32026
+ nodes.push(element);
32027
+ element[PARENT] = node;
32028
+ }
32029
+ break;
32030
+ case exports.EnumToken.ComposesSelectorNodeType:
32031
+ if (node.r != null) {
32032
+ nodes.push(node.r);
32033
+ node.r[PARENT] = node;
32034
+ }
32035
+ for (let i = node.l.length - 1; i >= 0; i--) {
32036
+ const element = node.l[i];
32037
+ nodes.push(element);
32038
+ element[PARENT] = node;
32039
+ }
32040
+ break;
32041
+ case exports.EnumToken.ContainerStyleRangeTokenType:
32042
+ for (let i = node.r.length - 1; i >= 0; i--) {
32043
+ const element = node.r[i];
32044
+ nodes.push(element);
32045
+ element[PARENT] = node;
32046
+ }
32047
+ for (let i = node.op.length - 1; i >= 0; i--) {
32048
+ const element = node.op[i];
32049
+ nodes.push(element);
32050
+ element[PARENT] = node;
32051
+ }
32052
+ for (let i = node.l.length - 1; i >= 0; i--) {
32053
+ const element = node.l[i];
32054
+ nodes.push(element);
32055
+ element[PARENT] = node;
32056
+ }
32057
+ break;
32058
+ case exports.EnumToken.MediaRangeQueryTokenType:
32059
+ for (let i = node.r.length - 1; i >= 0; i--) {
32060
+ const element = node.r[i];
32061
+ nodes.push(element);
32062
+ element[PARENT] = node;
32063
+ }
32064
+ nodes.push(node.op2);
32065
+ node.op2[PARENT] = node;
32066
+ for (let i = node.val.length - 1; i >= 0; i--) {
32067
+ const element = node.val[i];
32068
+ nodes.push(element);
32069
+ element[PARENT] = node;
32070
+ }
32071
+ nodes.push(node.op1);
32072
+ node.op1[PARENT] = node;
32073
+ for (let i = node.l.length - 1; i >= 0; i--) {
32074
+ const element = node.l[i];
32075
+ nodes.push(element);
32076
+ element[PARENT] = node;
32077
+ }
32078
+ break;
31643
32079
  }
31644
32080
  // @ts-ignore
31645
- if (nodes[i].chi != null) {
32081
+ if (node.chi != null) {
32082
+ for (
31646
32083
  // @ts-ignore
31647
- for (const child of nodes[i].chi) {
31648
- subNodes.push(child);
31649
- }
31650
- }
31651
- if (subNodes.length > 0) {
31652
- if (freeBlock <= i) {
31653
- freeBlock = i + 1;
31654
- }
31655
- for (k = 0; k < subNodes.length; k++) {
31656
- j = k + freeBlock;
31657
- nodes[j] = subNodes[k];
31658
- nodes[j][PARENT] = nodes[i];
32084
+ let i = node.chi.length - 1; i >= 0; i--) {
32085
+ // @ts-ignore
32086
+ nodes.push(node.chi[i]);
31659
32087
  }
31660
- freeBlock += subNodes.length;
31661
32088
  }
31662
32089
  parens = null;
31663
32090
  handlers.length = 0;
@@ -31665,23 +32092,23 @@
31665
32092
  handlers.push(...visitors.preAllVisitorsHandlers);
31666
32093
  }
31667
32094
  genericKey =
31668
- nodes[i].typ == exports.EnumToken.DeclarationNodeType
32095
+ node.typ == exports.EnumToken.DeclarationNodeType
31669
32096
  ? "Declaration"
31670
- : nodes[i].typ == exports.EnumToken.AtRuleNodeType
32097
+ : node.typ == exports.EnumToken.AtRuleNodeType
31671
32098
  ? "AtRule"
31672
- : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
32099
+ : node.typ == exports.EnumToken.KeyframesAtRuleNodeType
31673
32100
  ? "KeyframesAtRule"
31674
- : nodes[i].typ === exports.EnumToken.KeyframesRuleNodeType
32101
+ : node.typ === exports.EnumToken.KeyframesRuleNodeType
31675
32102
  ? "KeyframesRule"
31676
- : nodes[i].typ == exports.EnumToken.RuleNodeType
32103
+ : node.typ == exports.EnumToken.RuleNodeType
31677
32104
  ? "Rule"
31678
- : nodes[i].typ == exports.EnumToken.KeyframesRuleNodeType
32105
+ : node.typ == exports.EnumToken.KeyframesRuleNodeType
31679
32106
  ? "KeyframesRule"
31680
32107
  : null;
31681
- let keyName = nodes[i].typ == exports.EnumToken.DeclarationNodeType || nodes[i].typ == exports.EnumToken.AtRuleNodeType
31682
- ? camelize(nodes[i].nam)
31683
- : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
31684
- ? camelize(nodes[i].val)
32108
+ let keyName = node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType
32109
+ ? camelize(node.nam)
32110
+ : node.typ == exports.EnumToken.KeyframesAtRuleNodeType
32111
+ ? camelize(node.val)
31685
32112
  : null;
31686
32113
  if (visitors.allVisitorsHandlers?.size > 0) {
31687
32114
  handlers.push(...visitors.allVisitorsHandlers);
@@ -31701,10 +32128,9 @@
31701
32128
  }
31702
32129
  }
31703
32130
  }
31704
- // @ts-ignore
31705
- if (map.has(nodes[i].typ)) {
32131
+ if (map.has(node.typ)) {
31706
32132
  // @ts-ignore
31707
- for (const handler of map.get(nodes[i].typ)) {
32133
+ for (const handler of map.get(node.typ)) {
31708
32134
  if (typeof handler == "function") {
31709
32135
  handlers.push(handler);
31710
32136
  }
@@ -31732,16 +32158,15 @@
31732
32158
  if (handlers.length == 0) {
31733
32159
  continue;
31734
32160
  }
31735
- let node = nodes[i];
31736
32161
  for (const callable of handlers) {
31737
- replacement = callable(node, nodes[i][PARENT], ast,
32162
+ replacement = callable(node, node[PARENT], ast,
31738
32163
  // @ts-expect-error
31739
32164
  function* () {
31740
32165
  if (parens == null) {
31741
- let node = nodes[i][PARENT];
31742
- while (node != null) {
31743
- yield node;
31744
- node = node[PARENT];
32166
+ let parent = node[PARENT];
32167
+ while (parent != null) {
32168
+ yield parent;
32169
+ parent = parent[PARENT];
31745
32170
  }
31746
32171
  }
31747
32172
  });
@@ -31752,37 +32177,33 @@
31752
32177
  continue;
31753
32178
  }
31754
32179
  // @ts-ignore
31755
- node = replacement;
32180
+ // node = replacement as AstNode;
31756
32181
  //
31757
- if (Array.isArray(node)) {
32182
+ if (Array.isArray(replacement)) {
31758
32183
  break;
31759
32184
  }
31760
32185
  }
31761
- if (node != nodes[i]) {
32186
+ // @ts-ignore
32187
+ if (replacement != null && node != replacement) {
31762
32188
  // @ts-ignore
31763
- replaceNodeOrValue(nodes[i][PARENT], nodes[i], node);
32189
+ replaceNodeOrValue(node[PARENT], node, replacement);
31764
32190
  }
31765
32191
  }
31766
32192
  nodes = null;
31767
32193
  }
31768
32194
  if (invalidNodes.length > 0) {
31769
- let count = invalidNodes.length;
31770
- for (const { node, parent } of walk(ast)) {
32195
+ for (const node of invalidNodes) {
31771
32196
  if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
31772
32197
  continue;
31773
32198
  }
31774
- if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
31775
- node[STATE] & exports.EnumAstNodeStatus.Unknown ||
31776
- node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
31777
- node[STATE] & exports.EnumAstNodeStatus.Malformed ||
31778
- node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
32199
+ if (node[STATE] &
32200
+ (exports.EnumAstNodeStatus.Invalid |
32201
+ exports.EnumAstNodeStatus.Unknown |
32202
+ exports.EnumAstNodeStatus.Unparsed |
32203
+ exports.EnumAstNodeStatus.Malformed |
32204
+ exports.EnumAstNodeStatus.Disallowed)) {
31779
32205
  // @ts-ignore
31780
- parent.chi.splice(parent.chi.indexOf(node), 1);
31781
- node[PARENT] = null;
31782
- count--;
31783
- if (count == 0) {
31784
- break;
31785
- }
32206
+ node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
31786
32207
  }
31787
32208
  }
31788
32209
  }
@@ -31803,7 +32224,6 @@
31803
32224
  ...stats,
31804
32225
  parse: `${(endParseTime - startTime).toFixed(2)}ms`,
31805
32226
  minify: `${(endTime - endParseTime).toFixed(2)}ms`,
31806
- // tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
31807
32227
  total: `${(endTime - startTime).toFixed(2)}ms`,
31808
32228
  },
31809
32229
  };
@@ -31881,6 +32301,7 @@
31881
32301
  }
31882
32302
  // @ts-ignore
31883
32303
  if (node.typ == exports.EnumToken.CssVariableDeclarationMapTokenType) {
32304
+ // @ts-ignore
31884
32305
  const from = node.from.find((t) => t.typ == exports.EnumToken.IdenTokenType || isIdentColor(t));
31885
32306
  if (!(from.val in cssVariablesMap)) {
31886
32307
  errors.push({
@@ -31890,6 +32311,7 @@
31890
32311
  });
31891
32312
  }
31892
32313
  else {
32314
+ // @ts-ignore
31893
32315
  for (const token of node.vars) {
31894
32316
  if (token.typ == exports.EnumToken.IdenTokenType || isIdentColor(token)) {
31895
32317
  if (!(token.val in cssVariablesMap[from.val])) {
@@ -31913,6 +32335,7 @@
31913
32335
  if (result.cssModuleVariables == null) {
31914
32336
  result.cssModuleVariables = {};
31915
32337
  }
32338
+ // @ts-ignore
31916
32339
  result.cssModuleVariables[node.nam] = node;
31917
32340
  }
31918
32341
  parent.chi.splice(parent.chi.indexOf(node), 1);
@@ -32078,7 +32501,8 @@
32078
32501
  value.val = mapping[idenToken];
32079
32502
  }
32080
32503
  }
32081
- else if (node.nam == "grid-template-areas" || node.nam == "grid-template") {
32504
+ else if (node.nam == "grid-template-areas" ||
32505
+ node.nam == "grid-template") {
32082
32506
  for (let i = 0; i < node.val.length; i++) {
32083
32507
  if (node.val[i].typ == exports.EnumToken.String) {
32084
32508
  const tokens = parseString(node.val[i].val.slice(1, -1));
@@ -32105,7 +32529,8 @@
32105
32529
  }
32106
32530
  }
32107
32531
  }
32108
- else if (node.nam == "animation" || node.nam == "animation-name") {
32532
+ else if (node.nam == "animation" ||
32533
+ node.nam == "animation-name") {
32109
32534
  for (const { value } of walkValues(node.val, node)) {
32110
32535
  if (value.typ == exports.EnumToken.IdenTokenType &&
32111
32536
  ![
@@ -32148,14 +32573,14 @@
32148
32573
  }
32149
32574
  }
32150
32575
  }
32151
- for (const { value, parent } of walkValues(node.val, node)) {
32152
- if (value.typ == exports.EnumToken.DashedIdenTokenType) {
32153
- value.val = mapping[value.val];
32576
+ for (const r of walkValues(node.val, node)) {
32577
+ if (r.value.typ == exports.EnumToken.DashedIdenTokenType) {
32578
+ r.value.val = mapping[r.value.val];
32154
32579
  }
32155
- else if ((value.typ == exports.EnumToken.IdenTokenType || isIdentColor(value)) &&
32156
- value.val in importedCssVariables) {
32580
+ else if ((r.value.typ == exports.EnumToken.IdenTokenType || isIdentColor(r.value)) &&
32581
+ r.value.val in importedCssVariables) {
32157
32582
  // @ts-ignore
32158
- replaceNodeOrValue(parent, value, importedCssVariables[value.val].val);
32583
+ replaceNodeOrValue(r.parent, r.value, importedCssVariables[value.val].val);
32159
32584
  }
32160
32585
  }
32161
32586
  }
@@ -32368,14 +32793,9 @@
32368
32793
  let parensMatch = 0;
32369
32794
  let curlyBracketMatch = 0;
32370
32795
  let tokenizer = iter instanceof Promise ? await iter : iter;
32371
- // ast[ROOT] = ast;
32372
32796
  ast[LOCSRCID] = options.source.id;
32373
32797
  ast[LOCSTA] = 0;
32374
32798
  ast[LOCEND] = 0;
32375
- // if (Array.isArray(iter)) {
32376
- // // @ts-expect-error
32377
- // iter = iter[Symbol.iterator]() as Iterator<TokenizeResult>;
32378
- // }
32379
32799
  while (!tokenizer.done()) {
32380
32800
  tokenizer.next();
32381
32801
  if (tokenizer.unit != null) {
@@ -32598,53 +33018,208 @@
32598
33018
  let genericKey;
32599
33019
  const handlers = [];
32600
33020
  const visitors = parseVisitors(options.visitor, errors);
32601
- let nodes = new Array(stats.tokensCount);
32602
- const subNodes = [];
32603
- let i;
32604
- let k;
32605
- let j;
32606
- let freeblock = 1;
32607
- nodes[0] = ast;
32608
- for (i = 0; i < nodes.length; i++) {
32609
- if (nodes[i] == null) {
32610
- break;
32611
- }
32612
- subNodes.length = 0;
33021
+ let nodes = [ast];
33022
+ let node;
33023
+ // nodes[0] = ast;
33024
+ while (nodes.length > 0) {
33025
+ node = nodes.pop();
32613
33026
  if (visitors.includeTokens) {
32614
- switch (nodes[i].typ) {
33027
+ switch (node.typ) {
32615
33028
  case exports.EnumToken.RuleNodeType:
32616
33029
  case exports.EnumToken.AtRuleNodeType:
32617
33030
  case exports.EnumToken.KeyframesRuleNodeType:
32618
33031
  case exports.EnumToken.KeyframesAtRuleNodeType:
32619
- for (const token of nodes[i][TOKENS]) {
32620
- subNodes.push(token);
33032
+ for (let i =
33033
+ // @ts-ignore
33034
+ node[TOKENS].length -
33035
+ 1; i >= 0; i--) {
33036
+ // @ts-ignore
33037
+ node[TOKENS][i][PARENT] =
33038
+ node;
33039
+ nodes.push(
33040
+ // @ts-ignore
33041
+ node[TOKENS][i]);
32621
33042
  }
32622
33043
  break;
32623
33044
  case exports.EnumToken.DeclarationNodeType:
32624
- for (const token of nodes[i].val) {
32625
- subNodes.push(token);
33045
+ for (let i =
33046
+ // @ts-ignore
33047
+ node.val.length - 1; i >= 0; i--) {
33048
+ // @ts-ignore
33049
+ node.val[i][PARENT] = node;
33050
+ // @ts-ignore
33051
+ nodes.push(node.val[i]);
32626
33052
  }
32627
33053
  break;
32628
33054
  }
33055
+ // @ts-ignore
33056
+ // if (node.l != null) {
33057
+ // // @ts-ignore
33058
+ // if (node.op2 != null) {
33059
+ // // @ts-ignore
33060
+ // nodes.push(node.op2);
33061
+ // // @ts-ignore
33062
+ // nodes.op2[PARENT] = node;
33063
+ // }
33064
+ // // @ts-ignore
33065
+ // if (node.op1 != null) {
33066
+ // // @ts-ignore
33067
+ // nodes.push(node.op1);
33068
+ // // @ts-ignore
33069
+ // nodes.op1[PARENT] = node;
33070
+ // }
33071
+ // // @ts-ignore
33072
+ // if (nodes.op != null && node.op.typ != null) {
33073
+ // // @ts-ignore
33074
+ // nodes.push(node.op);
33075
+ // // @ts-ignore
33076
+ // nodes.op[PARENT] = node;
33077
+ // }
33078
+ // // @ts-ignore
33079
+ // if (node.r != null) {
33080
+ // // @ts-ignore
33081
+ // if (Array.isArray(node.r)) {
33082
+ // // @ts-ignore
33083
+ // for (let i = node.r.length - 1; i >= 0; i--) {
33084
+ // // @ts-ignore
33085
+ // nodes.push(node.r[i]);
33086
+ // // @ts-ignore
33087
+ // node.r[i][PARENT] = node;
33088
+ // }
33089
+ // } else {
33090
+ // // @ts-ignore
33091
+ // nodes.push(node.r);
33092
+ // // @ts-ignore
33093
+ // node.r[PARENT] = node;
33094
+ // }
33095
+ // }
33096
+ // // @ts-ignore
33097
+ // if (Array.isArray(node.l)) {
33098
+ // // @ts-ignore
33099
+ // for (let i = node.l.length - 1; i >= 0; i--) {
33100
+ // // @ts-ignore
33101
+ // node.l[i][PARENT] = node;
33102
+ // // @ts-ignore
33103
+ // nodes.push(node.l[i]);
33104
+ // }
33105
+ // } else {
33106
+ // // @ts-ignore
33107
+ // nodes.push(node.l);
33108
+ // // @ts-ignore
33109
+ // node.l[PARENT] = node;
33110
+ // }
33111
+ // }
33112
+ }
33113
+ switch (node.typ) {
33114
+ case exports.EnumToken.BinaryExpressionTokenType:
33115
+ case exports.EnumToken.IfElseConditionTokenType:
33116
+ nodes.push(node.r);
33117
+ node.r[PARENT] = node;
33118
+ nodes.push(node.l);
33119
+ node.l[PARENT] = node;
33120
+ break;
33121
+ case exports.EnumToken.MatchExpressionTokenType:
33122
+ nodes.push(node.r);
33123
+ node.r[PARENT] = node;
33124
+ nodes.push(node.op);
33125
+ node.op[PARENT] = node;
33126
+ nodes.push(node.l);
33127
+ node.l[PARENT] = node;
33128
+ break;
33129
+ case exports.EnumToken.SupportsQueryConditionTokenType:
33130
+ case exports.EnumToken.MediaQueryConditionTokenType:
33131
+ for (let i = node.r.length - 1; i >= 0; i--) {
33132
+ const element = node.r[i];
33133
+ nodes.push(element);
33134
+ element[PARENT] = node;
33135
+ }
33136
+ nodes.push(node.op);
33137
+ node.op[PARENT] = node;
33138
+ for (let i = node.l.length - 1; i >= 0; i--) {
33139
+ const element = node.l[i];
33140
+ nodes.push(element);
33141
+ element[PARENT] = node;
33142
+ }
33143
+ break;
33144
+ case exports.EnumToken.WhenElseQueryConditionTokenType:
33145
+ for (let i = node.r.length - 1; i >= 0; i--) {
33146
+ const element = node.r[i];
33147
+ nodes.push(element);
33148
+ element[PARENT] = node;
33149
+ }
33150
+ nodes.push(node.l);
33151
+ node.l[PARENT] = node;
33152
+ break;
33153
+ case exports.EnumToken.IfConditionTokenType:
33154
+ for (let i = node.r.length - 1; i >= 0; i--) {
33155
+ const element = node.r[i];
33156
+ nodes.push(element);
33157
+ element[PARENT] = node;
33158
+ }
33159
+ for (let i = node.l.length - 1; i >= 0; i--) {
33160
+ const element = node.l[i];
33161
+ nodes.push(element);
33162
+ element[PARENT] = node;
33163
+ }
33164
+ break;
33165
+ case exports.EnumToken.ComposesSelectorNodeType:
33166
+ if (node.r != null) {
33167
+ nodes.push(node.r);
33168
+ node.r[PARENT] = node;
33169
+ }
33170
+ for (let i = node.l.length - 1; i >= 0; i--) {
33171
+ const element = node.l[i];
33172
+ nodes.push(element);
33173
+ element[PARENT] = node;
33174
+ }
33175
+ break;
33176
+ case exports.EnumToken.ContainerStyleRangeTokenType:
33177
+ for (let i = node.r.length - 1; i >= 0; i--) {
33178
+ const element = node.r[i];
33179
+ nodes.push(element);
33180
+ element[PARENT] = node;
33181
+ }
33182
+ for (let i = node.op.length - 1; i >= 0; i--) {
33183
+ const element = node.op[i];
33184
+ nodes.push(element);
33185
+ element[PARENT] = node;
33186
+ }
33187
+ for (let i = node.l.length - 1; i >= 0; i--) {
33188
+ const element = node.l[i];
33189
+ nodes.push(element);
33190
+ element[PARENT] = node;
33191
+ }
33192
+ break;
33193
+ case exports.EnumToken.MediaRangeQueryTokenType:
33194
+ for (let i = node.r.length - 1; i >= 0; i--) {
33195
+ const element = node.r[i];
33196
+ nodes.push(element);
33197
+ element[PARENT] = node;
33198
+ }
33199
+ nodes.push(node.op2);
33200
+ node.op2[PARENT] = node;
33201
+ for (let i = node.val.length - 1; i >= 0; i--) {
33202
+ const element = node.val[i];
33203
+ nodes.push(element);
33204
+ element[PARENT] = node;
33205
+ }
33206
+ nodes.push(node.op1);
33207
+ node.op1[PARENT] = node;
33208
+ for (let i = node.l.length - 1; i >= 0; i--) {
33209
+ const element = node.l[i];
33210
+ nodes.push(element);
33211
+ element[PARENT] = node;
33212
+ }
33213
+ break;
32629
33214
  }
32630
33215
  // @ts-ignore
32631
- if (nodes[i].chi != null) {
33216
+ if (node.chi != null) {
33217
+ for (
32632
33218
  // @ts-ignore
32633
- for (k = 0; k < nodes[i].chi.length; k++) {
33219
+ let i = node.chi.length - 1; i >= 0; i--) {
32634
33220
  // @ts-ignore
32635
- subNodes.push(nodes[i].chi[k]);
32636
- }
32637
- }
32638
- if (subNodes.length > 0) {
32639
- if (freeblock <= i) {
32640
- freeblock = i + 1;
32641
- }
32642
- for (k = 0; k < subNodes.length; k++) {
32643
- j = k + freeblock;
32644
- nodes[j] = subNodes[k];
32645
- nodes[j][PARENT] = nodes[i];
33221
+ nodes.push(node.chi[i]);
32646
33222
  }
32647
- freeblock += subNodes.length;
32648
33223
  }
32649
33224
  parens = null;
32650
33225
  handlers.length = 0;
@@ -32652,23 +33227,23 @@
32652
33227
  handlers.push(...visitors.preAllVisitorsHandlers);
32653
33228
  }
32654
33229
  genericKey =
32655
- nodes[i].typ == exports.EnumToken.DeclarationNodeType
33230
+ node.typ == exports.EnumToken.DeclarationNodeType
32656
33231
  ? "Declaration"
32657
- : nodes[i].typ == exports.EnumToken.AtRuleNodeType
33232
+ : node.typ == exports.EnumToken.AtRuleNodeType
32658
33233
  ? "AtRule"
32659
- : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
33234
+ : node.typ == exports.EnumToken.KeyframesAtRuleNodeType
32660
33235
  ? "KeyframesAtRule"
32661
- : nodes[i].typ === exports.EnumToken.KeyframesRuleNodeType
33236
+ : node.typ === exports.EnumToken.KeyframesRuleNodeType
32662
33237
  ? "KeyframesRule"
32663
- : nodes[i].typ == exports.EnumToken.RuleNodeType
33238
+ : node.typ == exports.EnumToken.RuleNodeType
32664
33239
  ? "Rule"
32665
- : nodes[i].typ == exports.EnumToken.KeyframesRuleNodeType
33240
+ : node.typ == exports.EnumToken.KeyframesRuleNodeType
32666
33241
  ? "KeyframesRule"
32667
33242
  : null;
32668
- let keyName = nodes[i].typ == exports.EnumToken.DeclarationNodeType || nodes[i].typ == exports.EnumToken.AtRuleNodeType
32669
- ? camelize(nodes[i].nam)
32670
- : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
32671
- ? camelize(nodes[i].val)
33243
+ let keyName = node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType
33244
+ ? camelize(node.nam)
33245
+ : node.typ == exports.EnumToken.KeyframesAtRuleNodeType
33246
+ ? camelize(node.val)
32672
33247
  : null;
32673
33248
  if (visitors.allVisitorsHandlers?.size > 0) {
32674
33249
  handlers.push(...visitors.allVisitorsHandlers);
@@ -32681,20 +33256,6 @@
32681
33256
  if (typeof handler == "function") {
32682
33257
  handlers.push(handler);
32683
33258
  }
32684
- // else if (Array.isArray(handler)) {
32685
- // for (const h of handler) {
32686
- // if (typeof h == "function") {
32687
- // handlers.push(h);
32688
- // }
32689
- // // @ts-ignore
32690
- // else if (h[keyName] != null) {
32691
- // // @ts-ignore
32692
- // handlers.push(h[keyName]);
32693
- // }
32694
- // }
32695
- // } else if (typeof handler.handler! == "function") {
32696
- // handlers.push(handler.handler);
32697
- // }
32698
33259
  // @ts-ignore
32699
33260
  else if (typeof handler[keyName] == "function") {
32700
33261
  // @ts-ignore
@@ -32702,10 +33263,9 @@
32702
33263
  }
32703
33264
  }
32704
33265
  }
32705
- // @ts-ignore
32706
- if (map.has(nodes[i].typ)) {
33266
+ if (map.has(node.typ)) {
32707
33267
  // @ts-ignore
32708
- for (const handler of map.get(nodes[i].typ)) {
33268
+ for (const handler of map.get(node.typ)) {
32709
33269
  if (typeof handler == "function") {
32710
33270
  handlers.push(handler);
32711
33271
  }
@@ -32733,16 +33293,16 @@
32733
33293
  if (handlers.length == 0) {
32734
33294
  continue;
32735
33295
  }
32736
- let node = nodes[i];
32737
33296
  for (const callable of handlers) {
32738
- replacement = callable(node, nodes[i][PARENT], ast,
33297
+ replacement = callable(node, node[PARENT], ast,
32739
33298
  // @ts-expect-error
32740
33299
  function* () {
32741
33300
  if (parens == null) {
32742
- let node = nodes[i][PARENT];
32743
- while (node != null) {
32744
- yield node;
32745
- node = node[PARENT];
33301
+ let parent = node[PARENT];
33302
+ // let node = node[PARENT] as AstNode;
33303
+ while (parent != null) {
33304
+ yield parent;
33305
+ parent = parent[PARENT];
32746
33306
  }
32747
33307
  }
32748
33308
  });
@@ -32756,37 +33316,37 @@
32756
33316
  continue;
32757
33317
  }
32758
33318
  // @ts-ignore
32759
- node = replacement;
33319
+ // node = replacement as AstNode;
32760
33320
  //
32761
- if (Array.isArray(node)) {
33321
+ if (Array.isArray(replacement)) {
32762
33322
  break;
32763
33323
  }
32764
33324
  }
32765
- if (node != nodes[i]) {
33325
+ // @ts-ignore
33326
+ if (replacement != null && node != replacement) {
33327
+ console.error({
33328
+ node,
33329
+ replacement,
33330
+ });
32766
33331
  // @ts-ignore
32767
- replaceNodeOrValue(nodes[i][PARENT], nodes[i], node);
33332
+ replaceNodeOrValue(node[PARENT], node, replacement);
32768
33333
  }
32769
33334
  }
32770
33335
  nodes = null;
32771
33336
  }
32772
33337
  if (invalidNodes.length > 0) {
32773
- let count = invalidNodes.length;
32774
- for (const { node, parent } of walk(ast)) {
33338
+ for (const node of invalidNodes) {
32775
33339
  if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
32776
33340
  continue;
32777
33341
  }
32778
- if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
32779
- node[STATE] & exports.EnumAstNodeStatus.Unknown ||
32780
- node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
32781
- node[STATE] & exports.EnumAstNodeStatus.Malformed ||
32782
- node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
33342
+ if (node[STATE] &
33343
+ (exports.EnumAstNodeStatus.Invalid |
33344
+ exports.EnumAstNodeStatus.Unknown |
33345
+ exports.EnumAstNodeStatus.Unparsed |
33346
+ exports.EnumAstNodeStatus.Malformed |
33347
+ exports.EnumAstNodeStatus.Disallowed)) {
32783
33348
  // @ts-ignore
32784
- parent.chi.splice(parent.chi.indexOf(node), 1);
32785
- node[PARENT] = null;
32786
- count--;
32787
- if (count == 0) {
32788
- break;
32789
- }
33349
+ node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
32790
33350
  }
32791
33351
  }
32792
33352
  }
@@ -32912,6 +33472,7 @@
32912
33472
  }
32913
33473
  // @ts-ignore
32914
33474
  if (node.typ == exports.EnumToken.CssVariableDeclarationMapTokenType) {
33475
+ // @ts-ignore
32915
33476
  const from = node.from.find((t) => t.typ == exports.EnumToken.IdenTokenType || isIdentColor(t));
32916
33477
  if (!(from.val in cssVariablesMap)) {
32917
33478
  errors.push({
@@ -32921,6 +33482,7 @@
32921
33482
  });
32922
33483
  }
32923
33484
  else {
33485
+ // @ts-ignore
32924
33486
  for (const token of node.vars) {
32925
33487
  if (token.typ == exports.EnumToken.IdenTokenType || isIdentColor(token)) {
32926
33488
  if (!(token.val in cssVariablesMap[from.val])) {
@@ -32944,6 +33506,7 @@
32944
33506
  if (result.cssModuleVariables == null) {
32945
33507
  result.cssModuleVariables = {};
32946
33508
  }
33509
+ // @ts-ignore
32947
33510
  result.cssModuleVariables[node.nam] = node;
32948
33511
  }
32949
33512
  parent.chi.splice(parent.chi.indexOf(node), 1);
@@ -33184,7 +33747,8 @@
33184
33747
  value.val = mapping[idenToken];
33185
33748
  }
33186
33749
  }
33187
- else if (node.nam == "grid-template-areas" || node.nam == "grid-template") {
33750
+ else if (node.nam == "grid-template-areas" ||
33751
+ node.nam == "grid-template") {
33188
33752
  for (let i = 0; i < node.val.length; i++) {
33189
33753
  if (node.val[i].typ == exports.EnumToken.String) {
33190
33754
  const tokens = parseString(node.val[i].val.slice(1, -1));
@@ -33215,7 +33779,8 @@
33215
33779
  }
33216
33780
  }
33217
33781
  }
33218
- else if (node.nam == "animation" || node.nam == "animation-name") {
33782
+ else if (node.nam == "animation" ||
33783
+ node.nam == "animation-name") {
33219
33784
  for (const { value } of walkValues(node.val, node)) {
33220
33785
  if (value.typ == exports.EnumToken.IdenTokenType &&
33221
33786
  ![
@@ -33610,7 +34175,7 @@
33610
34175
  else if (context.typ === exports.EnumToken.AtRuleNodeType &&
33611
34176
  "page" === context.nam &&
33612
34177
  pageMarginBoxType.has(atRuleName.toLowerCase())) {
33613
- if (parseAsBlock === false) {
34178
+ if (parseAsBlock === false && syntaxRules.optionalBody === false) {
33614
34179
  errors.push({
33615
34180
  action: "drop",
33616
34181
  node: atRule,
@@ -33649,7 +34214,7 @@
33649
34214
  if (parseAsBlock === null) {
33650
34215
  parseAsBlock = blockAllowed;
33651
34216
  }
33652
- if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed) {
34217
+ if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed && !syntaxRules.optionalBody) {
33653
34218
  errors.push({
33654
34219
  action: "drop",
33655
34220
  node: atRule,
@@ -34319,6 +34884,50 @@
34319
34884
  atRule[TOKENS] = stream.slice();
34320
34885
  atRule[STATE] = result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.Invalid;
34321
34886
  atRule[ERRORS] = result.errors;
34887
+ switch (atRule.nam) {
34888
+ case "mixin":
34889
+ if (context != null && context.typ != exports.EnumToken.StyleSheetNodeType) {
34890
+ atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
34891
+ atRule[ERRORS].push({
34892
+ message: "mixin rule cannot be a nested group rule or rule style body",
34893
+ location: atRule[LOCSTA],
34894
+ });
34895
+ }
34896
+ break;
34897
+ case "contents":
34898
+ let parent = context;
34899
+ let valid = parent == null;
34900
+ while (parent != null) {
34901
+ if (parent.typ == exports.EnumToken.AtRuleNodeType && "mixin" == parent.nam) {
34902
+ valid = true;
34903
+ break;
34904
+ }
34905
+ parent = parent[PARENT];
34906
+ }
34907
+ if (!valid) {
34908
+ atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
34909
+ atRule[ERRORS].push({
34910
+ message: "contents rule cannot be used outside mixin rule",
34911
+ location: atRule[LOCSTA],
34912
+ });
34913
+ }
34914
+ break;
34915
+ case "layer":
34916
+ if (context != null && context.typ != exports.EnumToken.StyleSheetNodeType) {
34917
+ let parent = context;
34918
+ while (parent != null) {
34919
+ if (parent.typ == exports.EnumToken.AtRuleNodeType && parent.nam == "mixin") {
34920
+ atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
34921
+ atRule[ERRORS].push({
34922
+ message: "at-rule layeris not allowed inside mixin rule",
34923
+ location: atRule[LOCSTA],
34924
+ });
34925
+ break;
34926
+ }
34927
+ parent = parent[PARENT];
34928
+ }
34929
+ }
34930
+ }
34322
34931
  // @ts-expect-error
34323
34932
  return Object.assign(atRule, {
34324
34933
  typ: exports.EnumToken.AtRuleNodeType,
@@ -34778,7 +35387,7 @@
34778
35387
  }
34779
35388
  }
34780
35389
 
34781
- var version = "1.6.9";
35390
+ var version = "1.8.1";
34782
35391
 
34783
35392
  /**
34784
35393
  * Load file or url
@@ -35205,6 +35814,7 @@
35205
35814
  exports.parseFile = parseFile;
35206
35815
  exports.parseString = parseString;
35207
35816
  exports.parseSync = parseSync;
35817
+ exports.parseSyntax = parseSyntax;
35208
35818
  exports.render = render;
35209
35819
  exports.renderToken = renderValue;
35210
35820
  exports.replaceNodeOrValue = replaceNodeOrValue;