@tbela99/css-parser 1.4.1 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +168 -4
  7. package/README.md +82 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24393 -18479
  12. package/dist/index.cjs +27430 -21519
  13. package/dist/index.d.ts +1403 -933
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +543 -215
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +53 -47
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +50 -41
  182. package/package.json +18 -13
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -0,0 +1,366 @@
1
+ import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
+ import { renderToken } from '../../renderer/render.js';
3
+ import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
4
+ import { getParsedSyntax } from '../../validation/config.js';
5
+ import { matchAllSyntax, createValidationContext, trimArray } from '../../validation/match.js';
6
+ import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
7
+ import { parseDeclaration } from './declaration.js';
8
+ import { equalsIgnoreCase } from './text.js';
9
+
10
+ function parseAtRuleSupportSyntax(stream, context, options = {}) {
11
+ const tokens = [];
12
+ const stack = [];
13
+ let i = 0;
14
+ let success = true;
15
+ let expectAndOr = false;
16
+ let scope = new Set();
17
+ const errors = [];
18
+ const scopes = [scope];
19
+ const trimWhiteSpace = new Set([
20
+ EnumToken.GtTokenType,
21
+ EnumToken.ChildCombinatorTokenType,
22
+ EnumToken.NextSiblingCombinatorTokenType,
23
+ EnumToken.SubsequentSiblingCombinatorTokenType,
24
+ EnumToken.ColumnCombinatorTokenType,
25
+ EnumToken.UniversalSelectorTokenType,
26
+ ]);
27
+ while (i < stream.length &&
28
+ (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
29
+ tokens.push(stream[i]);
30
+ i++;
31
+ }
32
+ if (!tokensfuncDefMap.has(stream[i]?.typ) &&
33
+ stream[i]?.typ !== EnumToken.StartParensTokenType &&
34
+ !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === stream[i]?.val.toLowerCase())) {
35
+ return {
36
+ success,
37
+ errors: [
38
+ {
39
+ action: "drop",
40
+ node: stream[i],
41
+ message: `expecting '<supports-condition>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ for (; i < stream.length; i++) {
47
+ tokens.push(stream[i]);
48
+ if (trimWhiteSpace.has(stream[i].typ)) {
49
+ if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
50
+ tokens.splice(tokens.length - 2, 1);
51
+ }
52
+ if (stream[i + 1]?.typ === EnumToken.WhitespaceTokenType) {
53
+ i++;
54
+ continue;
55
+ }
56
+ }
57
+ if (expectAndOr) {
58
+ let k = i;
59
+ while (k < stream.length &&
60
+ (stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)) {
61
+ tokens.push(stream[k]);
62
+ k++;
63
+ }
64
+ if (k < stream.length) {
65
+ if (stream[k].typ !== EnumToken.EndParensTokenType &&
66
+ !(stream[k].typ === EnumToken.IdenTokenType &&
67
+ ("and" === stream[k]?.val.toLowerCase() ||
68
+ "or" === stream[k]?.val.toLowerCase()))) {
69
+ return {
70
+ success: false,
71
+ errors: [
72
+ {
73
+ action: "drop",
74
+ node: stream[k],
75
+ message: `expecting 'and' or 'or' at ${stream[k]?.loc?.src}:${stream[k]?.loc?.sta.lin}:${stream[k]?.loc?.sta.col}`,
76
+ },
77
+ ],
78
+ };
79
+ }
80
+ }
81
+ expectAndOr = false;
82
+ }
83
+ if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
84
+ scopes.push((scope = new Set()));
85
+ stack.push(stream[i]);
86
+ continue;
87
+ }
88
+ switch (stream[i].typ) {
89
+ case EnumToken.EndParensTokenType:
90
+ {
91
+ if (stack.length === 0) {
92
+ return {
93
+ success: false,
94
+ errors: [
95
+ {
96
+ action: "drop",
97
+ node: stream[i],
98
+ message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
99
+ },
100
+ ],
101
+ };
102
+ }
103
+ if (stack[stack.length - 1].typ === EnumToken.ColonTokenType) {
104
+ if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
105
+ const index = tokens.indexOf(stack[stack.length - 1]);
106
+ // expecting ident or dashed ident
107
+ if (tokens[index + 1]?.typ == EnumToken.IdenTokenType ||
108
+ tokens[index + 1]?.typ == EnumToken.DashedIdenTokenType) {
109
+ Object.assign(tokens[index], {
110
+ typ: EnumToken.PseudoElementTokenType,
111
+ val: ":" + tokens[index + 1].val,
112
+ });
113
+ tokens[index].loc.end = tokens[index + 1].loc.end;
114
+ tokens.splice(index + 1, 1);
115
+ stack.pop();
116
+ const index2 = tokens.indexOf(stack[stack.length - 1]);
117
+ const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
118
+ if (!result.success) {
119
+ return {
120
+ success: false,
121
+ errors: result.errors,
122
+ };
123
+ }
124
+ tokens.pop();
125
+ Object.assign(tokens[index2], {
126
+ typ: tokensfuncDefMap.get(tokens[index2].typ),
127
+ chi: tokens.splice(index2 + 1, tokens.length - index2 - 1),
128
+ });
129
+ tokens[index2].loc.end = stream[i].loc.end;
130
+ stack.pop();
131
+ break;
132
+ }
133
+ }
134
+ if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
135
+ return {
136
+ success: false,
137
+ errors: [
138
+ {
139
+ action: "drop",
140
+ node: stream[i],
141
+ message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
142
+ },
143
+ ],
144
+ };
145
+ }
146
+ // match declaration
147
+ const index = tokens.indexOf(stack[stack.length - 2]);
148
+ const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
149
+ const declaration = parseDeclaration(slice, context, { ...options, validation: ValidationLevel.None }, errors);
150
+ if (declaration.typ !== EnumToken.DeclarationNodeType) {
151
+ return {
152
+ success: false,
153
+ errors: [
154
+ {
155
+ action: "drop",
156
+ node: declaration,
157
+ message: `invalid declaration at ${declaration?.loc?.src}:${declaration?.loc?.sta.lin}:${declaration?.loc?.sta.col}`,
158
+ },
159
+ ],
160
+ };
161
+ }
162
+ tokens.splice(index + 1, 0, declaration);
163
+ stack.pop();
164
+ }
165
+ // match <support-condition-name>
166
+ // @supports (--condition-name) {}
167
+ if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
168
+ const index = tokens.indexOf(stack.at(-1));
169
+ const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
170
+ const filtered = slice.filter((token) => {
171
+ return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
172
+ });
173
+ if (filtered.length !== 1 ||
174
+ !(trimTokenSpace.has(filtered[0].typ) ||
175
+ tokensfuncDefMap.has(filtered[0].typ) ||
176
+ tokensfuncSet.has(filtered[0].typ))) {
177
+ const token = filtered[0] ?? slice[0] ?? stream[i];
178
+ return {
179
+ success: false,
180
+ errors: [
181
+ {
182
+ action: "drop",
183
+ node: token,
184
+ message: `expecting '<${filtered[0]?.typ === EnumToken.IdenTokenType ? "supports-condition-name" : "supports-condition"}>' at ${token?.loc?.src}:${token?.loc?.sta.lin}:${token?.loc?.sta.col}`,
185
+ },
186
+ ],
187
+ };
188
+ }
189
+ tokens[index] = Object.defineProperty({
190
+ typ: EnumToken.ParensTokenType,
191
+ chi: slice,
192
+ }, "loc", {
193
+ ...definedPropertySettings,
194
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
195
+ });
196
+ stack.pop();
197
+ tokens.pop();
198
+ scopes.pop();
199
+ scope = scopes[scopes.length - 1];
200
+ expectAndOr = true;
201
+ }
202
+ else if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
203
+ const index = tokens.indexOf(stack.at(-1));
204
+ tokens[index] = Object.defineProperty({
205
+ typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
206
+ val: stack.at(-1).val,
207
+ chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
208
+ }, "loc", {
209
+ ...definedPropertySettings,
210
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
211
+ });
212
+ //
213
+ let k = stack.length - 1;
214
+ while (tokensfuncDefMap.has(stack[k]?.typ)) {
215
+ k--;
216
+ }
217
+ if (stack[k]?.typ !== EnumToken.ColonTokenType) {
218
+ if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType && !equalsIgnoreCase('env', tokens[index].val)) {
219
+ errors.push({
220
+ action: "ignore",
221
+ node: tokens[index],
222
+ message: `expecting <supports-selector-fn>, <supports-env-fn>, <font-tech()>, <font-format()>, <at-rule()> or <named-feature()> at ${tokens[index]?.loc?.src}:${tokens[index]?.loc?.sta.lin}:${tokens[index]?.loc?.sta.col}`,
223
+ });
224
+ }
225
+ else {
226
+ // not a declaration
227
+ const result = matchAllSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
228
+ if (!result.valid) {
229
+ errors.push(...result.errors, {
230
+ action: "ignore",
231
+ node: tokens[index],
232
+ message: `missing syntax for function '${tokens[index].val}()' at ${tokens[index]?.loc?.src}:${tokens[index]?.loc?.sta.lin}:${tokens[index]?.loc?.sta.col}`,
233
+ });
234
+ }
235
+ else if (!result.success) {
236
+ return {
237
+ success: false,
238
+ errors: result.errors,
239
+ };
240
+ }
241
+ }
242
+ }
243
+ stack.pop();
244
+ tokens.pop();
245
+ scopes.pop();
246
+ scope = scopes[scopes.length - 1];
247
+ }
248
+ if (stack.at(-1)?.typ === EnumToken.NotTokenType) {
249
+ const index = tokens.indexOf(stack.at(-1));
250
+ tokens[index] = Object.defineProperty({
251
+ typ: EnumToken.SupportsQueryUnaryConditionTokenType,
252
+ l: stack.at(-1),
253
+ r: trimArray(tokens.splice(index + 1, i - index - 1)),
254
+ }, "loc", {
255
+ ...definedPropertySettings,
256
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
257
+ });
258
+ stack.pop();
259
+ }
260
+ if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
261
+ if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
262
+ return {
263
+ success: false,
264
+ errors: [
265
+ {
266
+ action: "drop",
267
+ node: stack.at(-2),
268
+ message: `expecting '(' at ${stack.at(-2)?.loc?.src}:${stack.at(-2)?.loc?.sta.lin}:${stack.at(-2)?.loc?.sta.col}`,
269
+ },
270
+ ],
271
+ };
272
+ }
273
+ const index = tokens.indexOf(stack.at(-1));
274
+ const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
275
+ const left = trimArray(tokens.slice(index2, index));
276
+ const notToken = left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
277
+ t.l.typ === EnumToken.NotTokenType);
278
+ if (notToken != null) {
279
+ return {
280
+ success: false,
281
+ errors: [
282
+ {
283
+ action: "drop",
284
+ node: stack.at(-1),
285
+ message: `unexpected token after 'not' expression at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
286
+ },
287
+ ],
288
+ };
289
+ }
290
+ tokens[index2] = Object.defineProperty({
291
+ typ: EnumToken.SupportsQueryConditionTokenType,
292
+ op: stack.at(-1),
293
+ l: left,
294
+ r: trimArray(tokens.slice(index + 1)),
295
+ }, "loc", {
296
+ ...definedPropertySettings,
297
+ value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
298
+ });
299
+ tokens.length = index2 + 1;
300
+ stack.pop();
301
+ }
302
+ }
303
+ break;
304
+ case EnumToken.ColonTokenType:
305
+ stack.push(stream[i]);
306
+ break;
307
+ case EnumToken.IdenTokenType:
308
+ {
309
+ const val = stream[i].val.toLowerCase();
310
+ if ("not" === val) {
311
+ stack.push(stream[i]);
312
+ Object.assign(stream[i], { typ: EnumToken.NotTokenType });
313
+ break;
314
+ }
315
+ if ("and" === val || "or" === val) {
316
+ if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
317
+ return {
318
+ success: false,
319
+ errors: [
320
+ {
321
+ action: "drop",
322
+ message: `mixing <and> and <or> at the same level is not allowed at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
323
+ },
324
+ ],
325
+ };
326
+ }
327
+ if ("or" === val && scopes.length === 1) {
328
+ return {
329
+ success: false,
330
+ errors: [
331
+ {
332
+ action: "drop",
333
+ message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
334
+ },
335
+ ],
336
+ };
337
+ }
338
+ Object.assign(stream[i], {
339
+ typ: "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType,
340
+ });
341
+ scope.add(stream[i].typ);
342
+ stack.push(stream[i]);
343
+ break;
344
+ }
345
+ }
346
+ break;
347
+ }
348
+ }
349
+ if (stack.length > 0) {
350
+ return {
351
+ success: false,
352
+ errors: [
353
+ {
354
+ action: "drop",
355
+ node: stack.at(-1),
356
+ message: `unmatched token '${renderToken(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
357
+ },
358
+ ],
359
+ };
360
+ }
361
+ stream.length = 0;
362
+ stream.push(...trimArray(tokens));
363
+ return { success, errors };
364
+ }
365
+
366
+ export { parseAtRuleSupportSyntax };
@@ -0,0 +1 @@
1
+ export declare function parseAtRuleToken(): void;
@@ -0,0 +1,5 @@
1
+ import type { AstAtRule, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
2
+ export declare function matchAtRuleWhenElseSyntax(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
3
+ success: boolean;
4
+ errors: ErrorDescription[];
5
+ };