@tbela99/css-parser 1.4.6 → 1.4.8

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 (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +6578 -6969
  4. package/dist/index.cjs +7808 -8197
  5. package/dist/index.d.ts +923 -51
  6. package/dist/lib/ast/clone.js +16 -23
  7. package/dist/lib/ast/expand.js +2 -2
  8. package/dist/lib/ast/features/if.js +88 -87
  9. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  10. package/dist/lib/ast/features/prefix.js +26 -22
  11. package/dist/lib/ast/features/transform.js +3 -3
  12. package/dist/lib/ast/find.js +17 -14
  13. package/dist/lib/ast/minify.js +97 -94
  14. package/dist/lib/ast/types.js +10 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +47 -45
  17. package/dist/lib/parser/arena.js +206 -0
  18. package/dist/lib/parser/declaration/list.js +9 -10
  19. package/dist/lib/parser/declaration/map.js +13 -18
  20. package/dist/lib/parser/linemap.js +62 -0
  21. package/dist/lib/parser/parse.js +331 -504
  22. package/dist/lib/parser/source.js +72 -0
  23. package/dist/lib/parser/tokenize.js +39 -33
  24. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  25. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  26. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  27. package/dist/lib/parser/utils/at-rule-media.js +284 -283
  28. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  29. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  30. package/dist/lib/parser/utils/at-rule.js +19 -16
  31. package/dist/lib/parser/utils/cache.js +33 -5
  32. package/dist/lib/parser/utils/declaration.js +260 -298
  33. package/dist/lib/parser/utils/hash.js +15 -15
  34. package/dist/lib/parser/utils/selector.js +182 -222
  35. package/dist/lib/parser/utils/token.js +4 -7
  36. package/dist/lib/renderer/render.js +152 -121
  37. package/dist/lib/syntax/color/alpha.js +1 -4
  38. package/dist/lib/syntax/color/color-mix.js +8 -1
  39. package/dist/lib/syntax/color/color.js +17 -9
  40. package/dist/lib/syntax/color/hex.js +1 -1
  41. package/dist/lib/syntax/color/p3.js +9 -1
  42. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  43. package/dist/lib/syntax/color/utils/components.js +21 -22
  44. package/dist/lib/syntax/color/utils/distance.js +6 -1
  45. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  46. package/dist/lib/syntax/constants.js +25 -3
  47. package/dist/lib/syntax/syntax.js +240 -311
  48. package/dist/lib/validation/config.js +16 -17
  49. package/dist/lib/validation/match.js +1118 -1131
  50. package/dist/lib/validation/parser/parse.js +130 -286
  51. package/dist/node.js +18 -14
  52. package/dist/web.js +12 -10
  53. package/package.json +4 -4
  54. package/dist/lib/validation/utils/whitespace.js +0 -17
  55. /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
@@ -1,12 +1,9 @@
1
- import { EnumToken, ValidationLevel } from '../../ast/types.js';
2
- import { renderValue } from '../../renderer/render.js';
3
- import { tokensfuncDefMap, trimTokenSpace, tokensfuncSet, definedPropertySettings } from '../../syntax/constants.js';
1
+ import { EnumToken } from '../../ast/types.js';
2
+ import { pseudoElements, LOC, tokensfuncDefMap } from '../../syntax/constants.js';
4
3
  import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
5
- import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
4
+ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
6
5
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
7
6
  import { parseDeclaration } from './declaration.js';
8
- import { equalsIgnoreCase } from './text.js';
9
- import { pseudoElements } from '../../syntax/syntax.js';
10
7
 
11
8
  function parseAtRuleSupportSyntax(stream, context, options = {}) {
12
9
  const tokens = [];
@@ -26,34 +23,41 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
26
23
  EnumToken.ColumnCombinatorTokenType,
27
24
  EnumToken.UniversalSelectorTokenType,
28
25
  ]);
29
- while (i < stream.length &&
30
- (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
31
- tokens.push(stream[i]);
32
- i++;
33
- }
34
- if (!tokensfuncDefMap.has(stream[i]?.typ) &&
35
- stream[i]?.typ !== EnumToken.StartParensTokenType &&
36
- !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === stream[i]?.val.toLowerCase())) {
37
- return {
38
- success: false,
39
- errors: [
40
- {
41
- action: "drop",
42
- node: stream[i],
43
- message: `expecting '<supports-condition>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
44
- },
45
- ],
46
- };
47
- }
26
+ // while (
27
+ // i < stream.length &&
28
+ // (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)
29
+ // ) {
30
+ // tokens.push(stream[i]);
31
+ // i++;
32
+ // }
33
+ // if (
34
+ // !tokensfuncDefMap.has(stream[i]?.typ) &&
35
+ // stream[i]?.typ !== EnumToken.StartParensTokenType &&
36
+ // !(stream[i]?.typ === EnumToken.IdenTokenType && "not" === (stream[i] as IdentToken)?.val.toLowerCase())
37
+ // ) {
38
+ // return {
39
+ // success: false,
40
+ // errors: [
41
+ // {
42
+ // action: "drop",
43
+ // node: stream[i],
44
+ // message: `expecting '<supports-condition>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
45
+ // },
46
+ // ],
47
+ // };
48
+ // }
48
49
  for (; i < stream.length; i++) {
49
50
  tokens.push(stream[i]);
50
51
  if (stream[i].typ == EnumToken.ColonTokenType) {
51
52
  if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
53
+ const val = stream[i + 1].val;
52
54
  Object.assign(stream[i], {
53
- typ: EnumToken.PseudoElementTokenType,
54
- val: ":" + stream[i + 1].val,
55
+ typ: pseudoElements.includes(val)
56
+ ? EnumToken.PseudoElementTokenType
57
+ : EnumToken.PseudoClassTokenType,
58
+ val: ":" + val,
55
59
  });
56
- stream[i].loc.end = stream[i + 1].loc.end;
60
+ stream[i][LOC].end = stream[i + 1][LOC].end;
57
61
  stream.splice(i + 1, 1);
58
62
  continue;
59
63
  }
@@ -66,36 +70,37 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
66
70
  val,
67
71
  });
68
72
  stack.push(stream[i]);
69
- stream[i].loc.end = stream[i + 1].loc.end;
70
- stream.splice(i + 1, 1);
71
- continue;
72
- }
73
- }
74
- if (stream[i].typ == EnumToken.DoubleColonTokenType) {
75
- val = ":" + stream[i + 1].val;
76
- if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
77
- Object.assign(stream[i], {
78
- typ: EnumToken.PseudoClassTokenType,
79
- val: (pseudoElements.includes(val) ? "" : ":") + val,
80
- });
81
- stream[i].loc.end = stream[i + 1].loc.end;
82
- stream.splice(i + 1, 1);
83
- continue;
84
- }
85
- if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
86
- val = "::" + stream[i + 1].val;
87
- Object.assign(stream[i], {
88
- typ: val + "()" in getSyntaxConfig().selectors
89
- ? EnumToken.PseudoClassFunctionTokenDefType
90
- : EnumToken.FunctionTokenDefType,
91
- val,
92
- });
93
- stack.push(stream[i]);
94
- stream[i].loc.end = stream[i + 1].loc.end;
73
+ stream[i][LOC].end = stream[i + 1][LOC].end;
95
74
  stream.splice(i + 1, 1);
96
75
  continue;
97
76
  }
98
77
  }
78
+ // if (stream[i].typ == EnumToken.DoubleColonTokenType) {
79
+ // val = ":" + (stream[i + 1] as IdentToken).val;
80
+ // if (stream[i + 1]?.typ == EnumToken.IdenTokenType) {
81
+ // Object.assign(stream[i], {
82
+ // typ: EnumToken.PseudoClassTokenType,
83
+ // val: (pseudoElements.includes(val) ? "" : ":") + val,
84
+ // });
85
+ // stream[i][LOC]!.end = stream[i + 1]![LOC]!.end;
86
+ // stream.splice(i + 1, 1);
87
+ // continue;
88
+ // }
89
+ // if (stream[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
90
+ // val = "::" + (stream[i + 1] as IdentToken).val;
91
+ // Object.assign(stream[i], {
92
+ // typ:
93
+ // val + "()" in getSyntaxConfig().selectors
94
+ // ? EnumToken.PseudoClassFunctionTokenDefType
95
+ // : EnumToken.FunctionTokenDefType,
96
+ // val,
97
+ // });
98
+ // stack.push(stream[i]);
99
+ // stream[i][LOC]!.end = stream[i + 1]![LOC]!.end;
100
+ // stream.splice(i + 1, 1);
101
+ // continue;
102
+ // }
103
+ // }
99
104
  if (trimWhiteSpace.has(stream[i].typ)) {
100
105
  if (tokens.at(-2)?.typ === EnumToken.WhitespaceTokenType) {
101
106
  tokens.splice(tokens.length - 2, 1);
@@ -112,23 +117,27 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
112
117
  tokens.push(stream[k]);
113
118
  k++;
114
119
  }
115
- if (k < stream.length) {
116
- if (stream[k].typ !== EnumToken.EndParensTokenType &&
117
- !(stream[k].typ === EnumToken.IdenTokenType &&
118
- ("and" === stream[k]?.val.toLowerCase() ||
119
- "or" === stream[k]?.val.toLowerCase()))) {
120
- return {
121
- success: false,
122
- errors: [
123
- {
124
- action: "drop",
125
- node: stream[k],
126
- message: `expecting 'and' or 'or' at ${stream[k]?.loc?.src}:${stream[k]?.loc?.sta.lin}:${stream[k]?.loc?.sta.col}`,
127
- },
128
- ],
129
- };
130
- }
131
- }
120
+ // if (k < stream.length) {
121
+ // if (
122
+ // stream[k].typ !== EnumToken.EndParensTokenType &&
123
+ // !(
124
+ // stream[k].typ === EnumToken.IdenTokenType &&
125
+ // ("and" === (stream[k] as IdentToken)?.val.toLowerCase() ||
126
+ // "or" === (stream[k] as IdentToken)?.val.toLowerCase())
127
+ // )
128
+ // ) {
129
+ // return {
130
+ // success: false,
131
+ // errors: [
132
+ // {
133
+ // action: "drop",
134
+ // node: stream[k],
135
+ // message: `expecting 'and' or 'or' at ${stream[k]?.[LOC]?.src}:${stream[k]?.[LOC]?.sta.lin}:${stream[k]?.[LOC]?.sta.col}`,
136
+ // },
137
+ // ],
138
+ // };
139
+ // }
140
+ // }
132
141
  expectAndOr = false;
133
142
  }
134
143
  if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
@@ -139,77 +148,91 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
139
148
  switch (stream[i].typ) {
140
149
  case EnumToken.EndParensTokenType:
141
150
  {
142
- if (stack.length === 0) {
143
- return {
144
- success: false,
145
- errors: [
146
- {
147
- action: "drop",
148
- node: stream[i],
149
- message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
150
- },
151
- ],
152
- };
153
- }
151
+ // if (stack.length === 0) {
152
+ // return {
153
+ // success: false,
154
+ // errors: [
155
+ // {
156
+ // action: "drop",
157
+ // node: stream[i],
158
+ // message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
159
+ // },
160
+ // ],
161
+ // };
162
+ // }
154
163
  if (stack[stack.length - 1].typ === EnumToken.ColonTokenType) {
155
- if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
156
- const index = tokens.indexOf(stack[stack.length - 1]);
157
- // expecting ident or dashed ident
158
- if (tokens[index + 1]?.typ == EnumToken.IdenTokenType ||
159
- tokens[index + 1]?.typ == EnumToken.DashedIdenTokenType) {
160
- Object.assign(tokens[index], {
161
- typ: EnumToken.PseudoElementTokenType,
162
- val: ":" + tokens[index + 1].val,
163
- });
164
- tokens[index].loc.end = tokens[index + 1].loc.end;
165
- tokens.splice(index + 1, 1);
166
- stack.pop();
167
- const index2 = tokens.indexOf(stack[stack.length - 1]);
168
- const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index2].val + "()")[0]?.chi, createValidationContext(tokens.slice(index2 + 1, -1)), options);
169
- if (!result.success) {
170
- return {
171
- success: false,
172
- errors: result.errors,
173
- };
174
- }
175
- tokens.pop();
176
- Object.assign(tokens[index2], {
177
- typ: tokensfuncDefMap.get(tokens[index2].typ),
178
- chi: tokens.splice(index2 + 1, tokens.length - index2 - 1),
179
- });
180
- tokens[index2].loc.end = stream[i].loc.end;
181
- stack.pop();
182
- break;
183
- }
184
- }
185
- if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
186
- return {
187
- success: false,
188
- errors: [
189
- {
190
- action: "drop",
191
- node: stream[i],
192
- message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
193
- },
194
- ],
195
- };
196
- }
164
+ // if (tokensfuncDefMap.has(stack[stack.length - 2]?.typ)) {
165
+ // const index: number = tokens.indexOf(stack[stack.length - 1]);
166
+ // // expecting ident or dashed ident
167
+ // if (
168
+ // tokens[index + 1]?.typ == EnumToken.IdenTokenType ||
169
+ // tokens[index + 1]?.typ == EnumToken.DashedIdenTokenType
170
+ // ) {
171
+ // const val: string = (tokens[index + 1] as IdentToken | DashedIdentToken).val;
172
+ // Object.assign(tokens[index], {
173
+ // typ: pseudoElements.includes(val)
174
+ // ? EnumToken.PseudoElementTokenType
175
+ // : EnumToken.PseudoClassTokenType,
176
+ // val: ":" + val,
177
+ // });
178
+ // tokens[index][LOC]!.end = tokens[index + 1][LOC]!.end;
179
+ // tokens.splice(index + 1, 1);
180
+ // stack.pop();
181
+ // const index2: number = tokens.indexOf(stack[stack.length - 1]);
182
+ // const result = matchAllSyntaxes(
183
+ // (
184
+ // getParsedSyntax(
185
+ // ValidationSyntaxGroupEnum.Syntaxes,
186
+ // (tokens[index2] as FunctionToken).val + "()",
187
+ // ) as ValidationFunctionToken[]
188
+ // )[0]?.chi as ValidationToken[],
189
+ // createValidationContext(tokens.slice(index2 + 1, -1)),
190
+ // options,
191
+ // );
192
+ // if (!result.success) {
193
+ // return {
194
+ // success: false,
195
+ // errors: result.errors,
196
+ // };
197
+ // }
198
+ // tokens.pop();
199
+ // Object.assign(tokens[index2], {
200
+ // typ: tokensfuncDefMap.get(tokens[index2].typ)!,
201
+ // chi: tokens.splice(index2 + 1, tokens.length - index2 - 1),
202
+ // });
203
+ // tokens[index2][LOC]!.end = stream[i][LOC]!.end;
204
+ // stack.pop();
205
+ // break;
206
+ // }
207
+ // }
208
+ // if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
209
+ // return {
210
+ // success: false,
211
+ // errors: [
212
+ // {
213
+ // action: "drop",
214
+ // node: stream[i],
215
+ // message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
216
+ // },
217
+ // ],
218
+ // };
219
+ // }
197
220
  // match declaration
198
221
  const index = tokens.indexOf(stack[stack.length - 2]);
199
222
  const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
200
- const declaration = parseDeclaration(slice, context, { ...options, validation: ValidationLevel.None }, errors);
201
- if (declaration.typ !== EnumToken.DeclarationNodeType) {
202
- return {
203
- success: false,
204
- errors: [
205
- {
206
- action: "drop",
207
- node: declaration,
208
- message: `invalid declaration at ${declaration?.loc?.src}:${declaration?.loc?.sta.lin}:${declaration?.loc?.sta.col}`,
209
- },
210
- ],
211
- };
212
- }
223
+ const declaration = parseDeclaration(slice, context, { ...options, validation: false }, errors);
224
+ // if (declaration.typ !== EnumToken.DeclarationNodeType) {
225
+ // return {
226
+ // success: false,
227
+ // errors: [
228
+ // {
229
+ // action: "drop",
230
+ // node: declaration,
231
+ // message: `invalid declaration at ${declaration?.[LOC]?.src}:${declaration?.[LOC]?.sta.lin}:${declaration?.[LOC]?.sta.col}`,
232
+ // },
233
+ // ],
234
+ // };
235
+ // }
213
236
  tokens.splice(index + 1, 0, declaration);
214
237
  stack.pop();
215
238
  }
@@ -218,32 +241,34 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
218
241
  if (stack.at(-1)?.typ === EnumToken.StartParensTokenType) {
219
242
  const index = tokens.indexOf(stack.at(-1));
220
243
  const slice = trimArray(tokens.splice(index + 1, tokens.length - index - 2));
221
- const filtered = slice.filter((token) => {
244
+ slice.filter((token) => {
222
245
  return (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
223
246
  });
224
- if (filtered.length !== 1 ||
225
- !(trimTokenSpace.has(filtered[0].typ) ||
226
- tokensfuncDefMap.has(filtered[0].typ) ||
227
- tokensfuncSet.has(filtered[0].typ))) {
228
- const token = filtered[0] ?? slice[0] ?? stream[i];
229
- return {
230
- success: false,
231
- errors: [
232
- {
233
- action: "drop",
234
- node: token,
235
- message: `expecting '<${filtered[0]?.typ === EnumToken.IdenTokenType ? "supports-condition-name" : "supports-condition"}>' at ${token?.loc?.src}:${token?.loc?.sta.lin}:${token?.loc?.sta.col}`,
236
- },
237
- ],
238
- };
239
- }
240
- tokens[index] = Object.defineProperty({
247
+ // if (
248
+ // filtered.length !== 1 ||
249
+ // !(
250
+ // trimTokenSpace.has(filtered[0].typ) ||
251
+ // tokensfuncDefMap.has(filtered[0].typ) ||
252
+ // tokensfuncSet.has(filtered[0].typ)
253
+ // )
254
+ // ) {
255
+ // const token = filtered[0] ?? slice[0] ?? stream[i];
256
+ // return {
257
+ // success: false,
258
+ // errors: [
259
+ // {
260
+ // action: "drop",
261
+ // node: token,
262
+ // message: `expecting '<${filtered[0]?.typ === EnumToken.IdenTokenType ? "supports-condition-name" : "supports-condition"}>' at ${token?.[LOC]?.src}:${token?.[LOC]?.sta.lin}:${token?.[LOC]?.sta.col}`,
263
+ // },
264
+ // ],
265
+ // };
266
+ // }
267
+ tokens[index] = {
241
268
  typ: EnumToken.ParensTokenType,
242
269
  chi: slice,
243
- }, "loc", {
244
- ...definedPropertySettings,
245
- value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
246
- });
270
+ [LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
271
+ };
247
272
  stack.pop();
248
273
  tokens.pop();
249
274
  scopes.pop();
@@ -252,14 +277,12 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
252
277
  }
253
278
  else if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
254
279
  const index = tokens.indexOf(stack.at(-1));
255
- tokens[index] = Object.defineProperty({
280
+ tokens[index] = {
256
281
  typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
257
282
  val: stack.at(-1).val,
258
283
  chi: trimArray(tokens.splice(index + 1, tokens.length - index - 2)),
259
- }, "loc", {
260
- ...definedPropertySettings,
261
- value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
262
- });
284
+ [LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
285
+ };
263
286
  if (tokens[index].typ === EnumToken.PseudoClassFuncTokenType) {
264
287
  // not a declaration
265
288
  const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
@@ -278,33 +301,42 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
278
301
  while (tokensfuncDefMap.has(stack[k]?.typ)) {
279
302
  k--;
280
303
  }
281
- if (stack[k]?.typ !== EnumToken.ColonTokenType) {
282
- if (tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
283
- !equalsIgnoreCase("env", tokens[index].val)) {
284
- errors.push({
285
- action: "ignore",
286
- node: tokens[index],
287
- 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}`,
288
- });
289
- }
290
- else {
291
- // not a declaration
292
- const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
293
- if (!result.valid) {
294
- errors.push(...result.errors, {
295
- action: "ignore",
296
- node: tokens[index],
297
- message: `missing syntax for function '${tokens[index].val}()' at ${tokens[index]?.loc?.src}:${tokens[index]?.loc?.sta.lin}:${tokens[index]?.loc?.sta.col}`,
298
- });
299
- }
300
- else if (!result.success) {
301
- return {
302
- success: false,
303
- errors: result.errors,
304
- };
305
- }
306
- }
307
- }
304
+ // if (stack[k]?.typ !== EnumToken.ColonTokenType) {
305
+ // if (
306
+ // tokens[index].typ !== EnumToken.SupportsFunctionTokenType &&
307
+ // !equalsIgnoreCase("env", (tokens[index] as FunctionToken).val)
308
+ // ) {
309
+ // errors.push({
310
+ // action: "ignore",
311
+ // node: tokens[index],
312
+ // 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}`,
313
+ // });
314
+ // } else {
315
+ // // not a declaration
316
+ // const result = matchAllSyntaxes(
317
+ // (
318
+ // getParsedSyntax(
319
+ // ValidationSyntaxGroupEnum.Syntaxes,
320
+ // (tokens[index] as FunctionToken).val + "()",
321
+ // ) as ValidationFunctionToken[]
322
+ // )?.[0]?.chi as ValidationToken[],
323
+ // createValidationContext((tokens[index] as FunctionToken).chi as Token[]),
324
+ // options,
325
+ // );
326
+ // if (!result.valid) {
327
+ // errors.push(...result.errors, {
328
+ // action: "ignore",
329
+ // node: tokens[index],
330
+ // message: `missing syntax for function '${(tokens[index] as FunctionToken).val}()' at ${tokens[index]?.[LOC]?.src}:${tokens[index]?.[LOC]?.sta.lin}:${tokens[index]?.[LOC]?.sta.col}`,
331
+ // });
332
+ // } else if (!result.success) {
333
+ // return {
334
+ // success: false,
335
+ // errors: result.errors,
336
+ // };
337
+ // }
338
+ // }
339
+ // }
308
340
  stack.pop();
309
341
  tokens.pop();
310
342
  scopes.pop();
@@ -312,55 +344,51 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
312
344
  }
313
345
  if (stack.at(-1)?.typ === EnumToken.NotTokenType) {
314
346
  const index = tokens.indexOf(stack.at(-1));
315
- tokens[index] = Object.defineProperty({
347
+ tokens[index] = {
316
348
  typ: EnumToken.SupportsQueryUnaryConditionTokenType,
317
349
  l: stack.at(-1),
318
350
  r: trimArray(tokens.splice(index + 1, i - index - 1)),
319
- }, "loc", {
320
- ...definedPropertySettings,
321
- value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
322
- });
351
+ [LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
352
+ };
323
353
  stack.pop();
324
354
  }
325
355
  if (stack.at(-1)?.typ === EnumToken.AndTokenType || stack.at(-1)?.typ === EnumToken.OrTokenType) {
326
- if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
327
- return {
328
- success: false,
329
- errors: [
330
- {
331
- action: "drop",
332
- node: stack.at(-2),
333
- message: `expecting '(' at ${stack.at(-2)?.loc?.src}:${stack.at(-2)?.loc?.sta.lin}:${stack.at(-2)?.loc?.sta.col}`,
334
- },
335
- ],
336
- };
337
- }
356
+ // if (stack.length > 1 && stack.at(-2)?.typ !== EnumToken.StartParensTokenType) {
357
+ // return {
358
+ // success: false,
359
+ // errors: [
360
+ // {
361
+ // action: "drop",
362
+ // node: stack.at(-2),
363
+ // message: `expecting '(' at ${stack.at(-2)?.[LOC]?.src}:${stack.at(-2)?.[LOC]?.sta.lin}:${stack.at(-2)?.[LOC]?.sta.col}`,
364
+ // },
365
+ // ],
366
+ // };
367
+ // }
338
368
  const index = tokens.indexOf(stack.at(-1));
339
369
  const index2 = stack.length > 1 ? tokens.indexOf(stack.at(-2)) + 1 : 0;
340
370
  const left = trimArray(tokens.slice(index2, index));
341
- const notToken = left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
371
+ left.find((t) => t.typ === EnumToken.SupportsQueryUnaryConditionTokenType &&
342
372
  t.l.typ === EnumToken.NotTokenType);
343
- if (notToken != null) {
344
- return {
345
- success: false,
346
- errors: [
347
- {
348
- action: "drop",
349
- node: stack.at(-1),
350
- message: `unexpected token after 'not' expression at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
351
- },
352
- ],
353
- };
354
- }
355
- tokens[index2] = Object.defineProperty({
373
+ // if (notToken != null) {
374
+ // return {
375
+ // success: false,
376
+ // errors: [
377
+ // {
378
+ // action: "drop",
379
+ // node: stack.at(-1),
380
+ // message: `unexpected token after 'not' expression at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
381
+ // },
382
+ // ],
383
+ // };
384
+ // }
385
+ tokens[index2] = {
356
386
  typ: EnumToken.SupportsQueryConditionTokenType,
357
387
  op: stack.at(-1),
358
388
  l: left,
359
389
  r: trimArray(tokens.slice(index + 1)),
360
- }, "loc", {
361
- ...definedPropertySettings,
362
- value: { ...stack.at(-1).loc, end: { ...stream[i]?.loc?.end } },
363
- });
390
+ [LOC]: { ...stack.at(-1)[LOC], end: { ...stream[i]?.[LOC]?.end } },
391
+ };
364
392
  tokens.length = index2 + 1;
365
393
  stack.pop();
366
394
  }
@@ -378,24 +406,24 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
378
406
  break;
379
407
  }
380
408
  if ("and" === val || "or" === val) {
381
- if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
382
- return {
383
- success: false,
384
- errors: [
385
- {
386
- action: "drop",
387
- 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}`,
388
- },
389
- ],
390
- };
391
- }
409
+ // if (scope.has("or" === val ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
410
+ // return {
411
+ // success: false,
412
+ // errors: [
413
+ // {
414
+ // action: "drop",
415
+ // 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}`,
416
+ // },
417
+ // ],
418
+ // };
419
+ // }
392
420
  if ("or" === val && scopes.length === 1) {
393
421
  return {
394
422
  success: false,
395
423
  errors: [
396
424
  {
397
425
  action: "drop",
398
- message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
426
+ message: `<or> is not allowed outside of a parenthesis at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
399
427
  },
400
428
  ],
401
429
  };
@@ -411,18 +439,18 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
411
439
  break;
412
440
  }
413
441
  }
414
- if (stack.length > 0) {
415
- return {
416
- success: false,
417
- errors: [
418
- {
419
- action: "drop",
420
- node: stack.at(-1),
421
- message: `unmatched token '${renderValue(stack.at(-1))}' at ${stack.at(-1).loc.src}:${stack.at(-1).loc.sta.lin}:${stack.at(-1).loc.sta.col}`,
422
- },
423
- ],
424
- };
425
- }
442
+ // if (stack.length > 0) {
443
+ // return {
444
+ // success: false,
445
+ // errors: [
446
+ // {
447
+ // action: "drop",
448
+ // node: stack.at(-1),
449
+ // message: `unmatched token '${renderValue(stack.at(-1) as Token)}' at ${stack.at(-1)![LOC]!.src}:${stack.at(-1)![LOC]!.sta.lin}:${stack.at(-1)![LOC]!.sta.col}`,
450
+ // },
451
+ // ],
452
+ // };
453
+ // }
426
454
  stream.length = 0;
427
455
  stream.push(...trimArray(tokens));
428
456
  return { success, errors };