@tbela99/css-parser 1.4.5 → 1.4.7

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 (47) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/README.md +2 -0
  3. package/dist/index-umd-web.js +6546 -6987
  4. package/dist/index.cjs +7784 -8223
  5. package/dist/index.d.ts +919 -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 +6 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +46 -44
  17. package/dist/lib/parser/declaration/list.js +9 -10
  18. package/dist/lib/parser/declaration/map.js +13 -18
  19. package/dist/lib/parser/parse.js +331 -506
  20. package/dist/lib/parser/tokenize.js +39 -33
  21. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  22. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  23. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  24. package/dist/lib/parser/utils/at-rule-media.js +286 -286
  25. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  26. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  27. package/dist/lib/parser/utils/at-rule.js +19 -16
  28. package/dist/lib/parser/utils/cache.js +33 -5
  29. package/dist/lib/parser/utils/declaration.js +260 -322
  30. package/dist/lib/parser/utils/hash.js +15 -15
  31. package/dist/lib/parser/utils/selector.js +182 -222
  32. package/dist/lib/parser/utils/token.js +4 -7
  33. package/dist/lib/renderer/render.js +150 -120
  34. package/dist/lib/syntax/color/alpha.js +1 -4
  35. package/dist/lib/syntax/color/color.js +5 -5
  36. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  37. package/dist/lib/syntax/color/utils/components.js +21 -22
  38. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  39. package/dist/lib/syntax/constants.js +22 -3
  40. package/dist/lib/syntax/syntax.js +252 -311
  41. package/dist/lib/validation/config.js +16 -17
  42. package/dist/lib/validation/match.js +1118 -1131
  43. package/dist/lib/validation/parser/parse.js +130 -286
  44. package/dist/node.js +16 -12
  45. package/dist/web.js +10 -8
  46. package/package.json +4 -4
  47. package/dist/lib/validation/utils/whitespace.js +0 -17
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import { tokensfuncDefMap } from '../../syntax/constants.js';
2
+ import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
3
3
  import { equalsIgnoreCase } from './text.js';
4
4
 
5
5
  function matchGenericSyntax(stream) {
@@ -23,40 +23,40 @@ function matchGenericSyntax(stream) {
23
23
  }
24
24
  if (token.typ === EnumToken.EndParensTokenType) {
25
25
  if (stack.length === 0 ||
26
- (stack.at(-1)?.typ !== EnumToken.ParensTokenType && !tokensfuncDefMap.has(stack.at(-1)?.typ))) {
26
+ (stack.at(-1)?.typ !== EnumToken.StartParensTokenType && !tokensfuncDefMap.has(stack.at(-1)?.typ))) {
27
27
  errors.push({
28
28
  action: "drop",
29
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
29
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
30
30
  node: token,
31
- location: token.loc,
31
+ location: token[LOC],
32
32
  });
33
33
  success = false;
34
34
  break;
35
35
  }
36
36
  stack.pop();
37
37
  scopes.pop();
38
- if (scopes.length === 0) {
39
- return {
40
- success: false,
41
- errors: [
42
- {
43
- action: "drop",
44
- node: token,
45
- message: `Unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
46
- location: token.loc,
47
- },
48
- ],
49
- };
50
- }
38
+ // if (scopes.length === 0) {
39
+ // return {
40
+ // success: false,
41
+ // errors: [
42
+ // {
43
+ // action: "drop",
44
+ // node: token,
45
+ // message: `Unexpected token ${EnumToken[token.typ]} at ${token[LOC]!.src}:${token[LOC]!.sta.lin}:${token[LOC]!.sta.col}`,
46
+ // location: token[LOC]!,
47
+ // },
48
+ // ],
49
+ // };
50
+ // }
51
51
  continue;
52
52
  }
53
53
  if (token.typ === EnumToken.IdenTokenType && equalsIgnoreCase("and", token.val)) {
54
54
  if (!expectAndOr || scopes.at(-1)?.has(EnumToken.OrTokenType)) {
55
55
  errors.push({
56
56
  action: "drop",
57
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
57
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
58
58
  node: token,
59
- location: token.loc,
59
+ location: token[LOC],
60
60
  });
61
61
  success = false;
62
62
  break;
@@ -70,9 +70,9 @@ function matchGenericSyntax(stream) {
70
70
  if (!expectAndOr || scopes.at(-1)?.has(EnumToken.AndTokenType)) {
71
71
  errors.push({
72
72
  action: "drop",
73
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
73
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
74
74
  node: token,
75
- location: token.loc,
75
+ location: token[LOC],
76
76
  });
77
77
  success = false;
78
78
  break;
@@ -86,9 +86,9 @@ function matchGenericSyntax(stream) {
86
86
  if (!expectComma) {
87
87
  errors.push({
88
88
  action: "drop",
89
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
89
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
90
90
  node: token,
91
- location: token.loc,
91
+ location: token[LOC],
92
92
  });
93
93
  success = false;
94
94
  break;
@@ -106,9 +106,9 @@ function matchGenericSyntax(stream) {
106
106
  if (stack.length > 0) {
107
107
  errors.push({
108
108
  action: "drop",
109
- message: `unexpected token ${EnumToken[stack.at(-1)?.typ]} at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
109
+ message: `unexpected token ${EnumToken[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
110
110
  node: stack.at(-1),
111
- location: stack.at(-1)?.loc,
111
+ location: stack.at(-1)?.[LOC],
112
112
  });
113
113
  success = false;
114
114
  }
@@ -2,8 +2,7 @@ import { EnumToken } from '../../ast/types.js';
2
2
  import { getSyntaxRule } from '../../validation/config.js';
3
3
  import { trimArray } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
- import { tokensfuncDefMap, definedPropertySettings } from '../../syntax/constants.js';
6
- import { isColor, parseColor } from '../../syntax/syntax.js';
5
+ import { tokensfuncDefMap, LOC } from '../../syntax/constants.js';
7
6
  import { parseMediaqueryList } from './at-rule-media.js';
8
7
  import { parseAtRuleSupportSyntax } from './at-rule-support.js';
9
8
 
@@ -27,8 +26,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
27
26
  // match ending ')'
28
27
  let matchCount = 0;
29
28
  let k = 0;
30
- let stringCount = 0;
31
- let urlTokenCount = 0;
29
+ // let stringCount = 0;
32
30
  for (; k < stream.length; k++) {
33
31
  if (stream[k]?.typ === EnumToken.EndParensTokenType) {
34
32
  matchCount--;
@@ -36,56 +34,54 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
36
34
  else if (stream[k]?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[k]?.typ)) {
37
35
  matchCount++;
38
36
  }
39
- else if (stream[k]?.typ === EnumToken.StringTokenType) {
40
- stringCount++;
41
- }
42
- else if (stream[k]?.typ === EnumToken.UrlFunctionTokenDefType) {
43
- urlTokenCount++;
44
- }
45
- else if (!(stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)) {
46
- return {
47
- success: false,
48
- errors: [
49
- {
50
- action: "drop",
51
- message: "Expected string or <url-token>",
52
- syntax: "@import",
53
- node: stream[k],
54
- location: stream[k]?.loc,
55
- },
56
- ],
57
- };
58
- }
37
+ // else if (stream[k]?.typ === EnumToken.StringTokenType) {
38
+ // stringCount++;
39
+ // }
40
+ // else if (stream[k]?.typ === EnumToken.UrlFunctionTokenDefType) {
41
+ // urlTokenCount++;
42
+ // } else if (
43
+ // !(stream[k]?.typ === EnumToken.WhitespaceTokenType || stream[k]?.typ === EnumToken.CommentTokenType)
44
+ // ) {
45
+ // return {
46
+ // success: false,
47
+ // errors: [
48
+ // {
49
+ // action: "drop",
50
+ // message: "Expected string or <url-token>",
51
+ // syntax: "@import",
52
+ // node: stream[k],
53
+ // location: stream[k]?.[LOC],
54
+ // } as ErrorDescription,
55
+ // ],
56
+ // };
57
+ // }
59
58
  if (matchCount === 0) {
60
59
  break;
61
60
  }
62
61
  }
63
- if (stringCount + urlTokenCount != 1) {
64
- return {
65
- success: false,
66
- errors: [
67
- {
68
- action: "drop",
69
- syntax: "@import",
70
- message: "could not match syntax <url>",
71
- node: stream[0],
72
- location: stream[0].loc,
73
- },
74
- ],
75
- };
76
- }
62
+ // if (stringCount + urlTokenCount != 1) {
63
+ // return {
64
+ // success: false,
65
+ // errors: [
66
+ // {
67
+ // action: "drop",
68
+ // syntax: "@import",
69
+ // message: "could not match syntax <url>",
70
+ // node: stream[0],
71
+ // location: stream[0][LOC],
72
+ // },
73
+ // ],
74
+ // };
75
+ // }
77
76
  const slice = stream.slice(index + 1, k);
78
- tokens.push(Object.defineProperties(Object.assign({}, stream[0], {
77
+ // @ts-expect-error
78
+ stream[0][LOC] = {
79
+ ...stream[0][LOC],
80
+ end: stream[1][LOC].end,
81
+ };
82
+ tokens.push(Object.assign({
79
83
  typ: tokensfuncDefMap.get(stream[0].typ),
80
84
  chi: trimArray(slice),
81
- }), {
82
- loc: {
83
- ...definedPropertySettings,
84
- value: {
85
- ...stream[0].loc,
86
- end: stream[1].loc.end,
87
- },
88
- },
89
85
  }));
90
86
  index = k + 1;
91
87
  }
@@ -98,7 +94,7 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
98
94
  message: "Expected string or url()",
99
95
  syntax: "@import",
100
96
  node: stream[0],
101
- location: stream[0]?.loc,
97
+ location: stream[0]?.[LOC],
102
98
  },
103
99
  ],
104
100
  };
@@ -116,10 +112,12 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
116
112
  "layer".localeCompare(stream[index].val) === 0) {
117
113
  stack.push(stream[index]);
118
114
  tokens.push(stream[index++]);
119
- while (stream[index]?.typ === EnumToken.WhitespaceTokenType ||
120
- stream[index]?.typ === EnumToken.CommentTokenType) {
121
- tokens.push(stream[index++]);
122
- }
115
+ // while (
116
+ // stream[index]?.typ === EnumToken.WhitespaceTokenType ||
117
+ // stream[index]?.typ === EnumToken.CommentTokenType
118
+ // ) {
119
+ // tokens.push(stream[index++] as Token);
120
+ // }
123
121
  // <layer-name">
124
122
  if (stream[index]?.typ === EnumToken.EndParensTokenType) {
125
123
  i = tokens.indexOf(stack.at(-1));
@@ -129,10 +127,10 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
129
127
  errors: [
130
128
  {
131
129
  action: "drop",
132
- message: `Expected <layer-name> at ${stream[index]?.loc?.src}:${stream[index]?.loc?.sta.lin}:${stream[index]?.loc?.sta.col}`,
130
+ message: `Expected <layer-name> at ${stream[index]?.[LOC]?.src}:${stream[index]?.[LOC]?.sta.lin}:${stream[index]?.[LOC]?.sta.col}`,
133
131
  syntax: "@import",
134
132
  node: stream[index],
135
- location: stream[index]?.loc,
133
+ location: stream[index]?.[LOC],
136
134
  },
137
135
  ],
138
136
  };
@@ -142,24 +140,26 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
142
140
  while (stream[index]?.typ == EnumToken.ClassSelectorTokenType) {
143
141
  tokens.push(stream[index++]);
144
142
  }
145
- while (stream[index]?.typ == EnumToken.WhitespaceTokenType ||
146
- stream[index]?.typ == EnumToken.CommentTokenType) {
147
- tokens.push(stream[index++]);
148
- }
149
- if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
150
- return {
151
- success: false,
152
- errors: [
153
- {
154
- action: "drop",
155
- message: "Expected ')'",
156
- syntax: "@import",
157
- node: stream[index],
158
- location: stream[index]?.loc,
159
- },
160
- ],
161
- };
162
- }
143
+ // while (
144
+ // stream[index]?.typ == EnumToken.WhitespaceTokenType ||
145
+ // stream[index]?.typ == EnumToken.CommentTokenType
146
+ // ) {
147
+ // tokens.push(stream[index++] as Token);
148
+ // }
149
+ // if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
150
+ // return {
151
+ // success: false,
152
+ // errors: [
153
+ // {
154
+ // action: "drop",
155
+ // message: "Expected ')'",
156
+ // syntax: "@import",
157
+ // node: stream[index],
158
+ // location: stream[index]?.[LOC],
159
+ // } as ErrorDescription,
160
+ // ],
161
+ // };
162
+ // }
163
163
  i = tokens.indexOf(stack.at(-1));
164
164
  tokens.splice(index, 1);
165
165
  Object.assign(stack.at(-1), {
@@ -174,10 +174,10 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
174
174
  errors: [
175
175
  {
176
176
  action: "drop",
177
- message: `Expected <layer-name> at ${stream[index]?.loc?.src}:${stream[index]?.loc?.sta.lin}:${stream[index]?.loc?.sta.col}`,
177
+ message: `Expected <layer-name> at ${stream[index]?.[LOC]?.src}:${stream[index]?.[LOC]?.sta.lin}:${stream[index]?.[LOC]?.sta.col}`,
178
178
  syntax: "@import",
179
179
  node: stream[index],
180
- location: stream[index]?.loc,
180
+ location: stream[index]?.[LOC],
181
181
  },
182
182
  ],
183
183
  };
@@ -193,176 +193,136 @@ function matchAtRuleImportSyntax(atRule, stream, context, options) {
193
193
  stack.push(stream[index]);
194
194
  tokens.push(stream[index++]);
195
195
  matchCount = 1;
196
- let isDecl = false;
197
- while (stream[index]?.typ === EnumToken.WhitespaceTokenType ||
198
- stream[index]?.typ === EnumToken.CommentTokenType) {
199
- tokens.push(stream[index++]);
200
- }
196
+ // while (
197
+ // stream[index]?.typ === EnumToken.WhitespaceTokenType ||
198
+ // stream[index]?.typ === EnumToken.CommentTokenType
199
+ // ) {
200
+ // tokens.push(stream[index++] as Token);
201
+ // }
201
202
  // <declaration>
202
- if (stream[index]?.typ === EnumToken.IdenTokenType &&
203
- !["and", "or", "not", "only"].includes(stream[index].val.toLowerCase())) {
204
- tokens.push(stream[index++]);
205
- while (stream[index]?.typ === EnumToken.WhitespaceTokenType ||
206
- stream[index]?.typ === EnumToken.CommentTokenType) {
207
- tokens.push(stream[index++]);
208
- }
209
- if (stream[index]?.typ !== EnumToken.ColonTokenType) {
210
- return {
211
- success: false,
212
- errors: [
213
- {
214
- action: "drop",
215
- message: "Expected ':'",
216
- syntax: "@import",
217
- node: stream[index],
218
- location: stream[index]?.loc,
219
- },
220
- ],
221
- };
222
- }
223
- else {
224
- isDecl = true;
225
- tokens.push(stream[index++]);
226
- // match the next ')'
227
- while (index < stream.length && matchCount > 0) {
228
- if (stream[index]?.typ === EnumToken.StartParensTokenType ||
229
- tokensfuncDefMap.has(stream[index]?.typ)) {
230
- matchCount++;
231
- // stack.push(stream[index] as Token);
232
- }
233
- else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
234
- matchCount--;
235
- if (matchCount === 0) {
236
- i = tokens.indexOf(stack.at(-1));
237
- tokens.splice(index, 1);
238
- Object.assign(stack.at(-1), {
239
- typ: tokensfuncDefMap.get(stack.at(-1).typ),
240
- chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
241
- });
242
- stack.pop();
243
- break;
244
- }
245
- }
246
- else if (stream[index]?.typ === EnumToken.ImportantTokenType) {
247
- tokens.push(stream[index++]);
248
- while (stream[index]?.typ === EnumToken.WhitespaceTokenType ||
249
- stream[index]?.typ === EnumToken.CommentTokenType) {
250
- tokens.push(stream[index++]);
251
- }
252
- // next token is ')'
253
- if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
254
- return {
255
- success: false,
256
- errors: [
257
- {
258
- action: "drop",
259
- message: "Expected ')'",
260
- syntax: "@import",
261
- node: stream[index],
262
- location: stream[index]?.loc,
263
- },
264
- ],
265
- };
266
- }
267
- matchCount--;
268
- i = tokens.indexOf(stack.at(-1));
269
- tokens.splice(index, 1);
270
- Object.assign(stack.at(-1), {
271
- typ: tokensfuncDefMap.get(stack.at(-1).typ),
272
- chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
273
- });
274
- stack.pop();
275
- break;
276
- }
277
- tokens.push(stream[index++]);
278
- }
279
- }
280
- }
203
+ // if (
204
+ // stream[index]?.typ === EnumToken.IdenTokenType &&
205
+ // !["and", "or", "not", "only"].includes((stream[index] as IdentToken).val.toLowerCase())
206
+ // ) {
207
+ // tokens.push(stream[index++] as Token);
208
+ // while (
209
+ // stream[index]?.typ === EnumToken.WhitespaceTokenType ||
210
+ // stream[index]?.typ === EnumToken.CommentTokenType
211
+ // ) {
212
+ // tokens.push(stream[index++] as Token);
213
+ // }
214
+ // if (stream[index]?.typ !== EnumToken.ColonTokenType) {
215
+ // return {
216
+ // success: false,
217
+ // errors: [
218
+ // {
219
+ // action: "drop",
220
+ // message: "Expected ':'",
221
+ // syntax: "@import",
222
+ // node: stream[index],
223
+ // location: stream[index]?.[LOC],
224
+ // } as ErrorDescription,
225
+ // ],
226
+ // };
227
+ // } else {
228
+ // isDecl = true;
229
+ // tokens.push(stream[index++] as Token);
230
+ // // match the next ')'
231
+ // while (index < stream.length && matchCount > 0) {
232
+ // if (
233
+ // stream[index]?.typ === EnumToken.StartParensTokenType ||
234
+ // tokensfuncDefMap.has(stream[index]?.typ)
235
+ // ) {
236
+ // matchCount++;
237
+ // // stack.push(stream[index] as Token);
238
+ // } else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
239
+ // matchCount--;
240
+ // if (matchCount === 0) {
241
+ // i = tokens.indexOf(stack.at(-1) as Token);
242
+ // tokens.splice(index, 1);
243
+ // Object.assign(stack.at(-1) as Token, {
244
+ // typ: tokensfuncDefMap.get((stack.at(-1) as Token).typ),
245
+ // chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
246
+ // });
247
+ // stack.pop();
248
+ // break;
249
+ // }
250
+ // } else if (stream[index]?.typ === EnumToken.ImportantTokenType) {
251
+ // tokens.push(stream[index++] as Token);
252
+ // while (
253
+ // stream[index]?.typ === EnumToken.WhitespaceTokenType ||
254
+ // stream[index]?.typ === EnumToken.CommentTokenType
255
+ // ) {
256
+ // tokens.push(stream[index++] as Token);
257
+ // }
258
+ // // next token is ')'
259
+ // if (stream[index]?.typ !== EnumToken.EndParensTokenType) {
260
+ // return {
261
+ // success: false,
262
+ // errors: [
263
+ // {
264
+ // action: "drop",
265
+ // message: "Expected ')'",
266
+ // syntax: "@import",
267
+ // node: stream[index],
268
+ // location: stream[index]?.[LOC],
269
+ // } as ErrorDescription,
270
+ // ],
271
+ // };
272
+ // }
273
+ // matchCount--;
274
+ // i = tokens.indexOf(stack.at(-1) as Token);
275
+ // tokens.splice(index, 1);
276
+ // Object.assign(stack.at(-1) as Token, {
277
+ // typ: tokensfuncDefMap.get((stack.at(-1) as Token).typ),
278
+ // chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
279
+ // });
280
+ // stack.pop();
281
+ // break;
282
+ // }
283
+ // tokens.push(stream[index++] as Token);
284
+ // }
285
+ // }
286
+ // }
281
287
  // <supports-condition>
282
- else {
283
- // match the next ')'
284
- while (index < stream.length && matchCount > 0) {
285
- if (stream[index]?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[index]?.typ)) {
286
- matchCount++;
287
- }
288
- else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
289
- matchCount--;
290
- if (matchCount === 0) {
291
- tokens.splice(index, 1);
292
- i = tokens.indexOf(stack.at(-1));
293
- Object.assign(stack.at(-1), {
294
- typ: tokensfuncDefMap.get(stack.at(-1).typ),
295
- chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
296
- });
297
- stack.pop();
298
- break;
299
- }
300
- }
301
- tokens.push(stream[index++]);
302
- }
303
- }
304
- if (matchCount > 0) {
305
- return {
306
- success: false,
307
- errors: [
308
- {
309
- action: "drop",
310
- message: "unmatched ')'",
311
- syntax: "@import",
312
- node: stack.at(-1),
313
- location: stack.at(-1)?.loc,
314
- },
315
- ],
316
- };
317
- }
318
- // support() is the last item in tokens array
319
- if (isDecl) {
320
- const supports = tokens.at(-1);
321
- for (i = 0; i < supports.chi.length; i++) {
322
- if (supports.chi[i].typ === EnumToken.IdenTokenType) {
323
- break;
324
- }
325
- }
326
- let j = i + 1;
327
- while (j < supports.chi.length && supports.chi[j].typ !== EnumToken.ColonTokenType) {
328
- j++;
288
+ // else {
289
+ // match the next ')'
290
+ while (index < stream.length && matchCount > 0) {
291
+ if (stream[index]?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[index]?.typ)) {
292
+ matchCount++;
329
293
  }
330
- const val = trimArray(supports.chi.slice(j + 1));
331
- supports.chi[i] = Object.defineProperties({
332
- typ: EnumToken.DeclarationNodeType,
333
- nam: supports.chi[i].val,
334
- val,
335
- }, {
336
- loc: {
337
- ...definedPropertySettings,
338
- value: {
339
- ...supports.chi[i].loc,
340
- end: { ...(val.at(-1) ?? supports.chi.at(-1)).loc?.end },
341
- },
342
- },
343
- });
344
- supports.chi.splice(i + 1, j - i + 1 + val.length);
345
- const stack = [];
346
- for (i = 0; i < val.length; i++) {
347
- if (val[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(val[i].typ)) {
348
- stack.push(val[i]);
349
- }
350
- else if (val[i].typ === EnumToken.EndParensTokenType) {
351
- const index = val.indexOf(stack.at(-1));
352
- val.splice(i, 1);
294
+ else if (stream[index]?.typ === EnumToken.EndParensTokenType) {
295
+ matchCount--;
296
+ if (matchCount === 0) {
297
+ tokens.splice(index, 1);
298
+ i = tokens.indexOf(stack.at(-1));
353
299
  Object.assign(stack.at(-1), {
354
300
  typ: tokensfuncDefMap.get(stack.at(-1).typ),
355
- chi: trimArray(val.splice(index + 1, i - index - 1)),
301
+ chi: trimArray(tokens.splice(i + 1, index++ - i - 1)),
356
302
  });
357
- i = index;
358
303
  stack.pop();
359
- }
360
- if (isColor(val[i])) {
361
- val[i] = parseColor(val[i]);
304
+ break;
362
305
  }
363
306
  }
307
+ tokens.push(stream[index++]);
364
308
  }
365
- else {
309
+ // }
310
+ // if (matchCount > 0) {
311
+ // return {
312
+ // success: false,
313
+ // errors: [
314
+ // {
315
+ // action: "drop",
316
+ // message: "unmatched ')'",
317
+ // syntax: "@import",
318
+ // node: stack.at(-1),
319
+ // location: stack.at(-1)?.[LOC],
320
+ // } as ErrorDescription,
321
+ // ],
322
+ // };
323
+ // }
324
+ // support() is the last item in tokens array
325
+ {
366
326
  const result = parseAtRuleSupportSyntax(tokens[tokens.length - 1].chi, context, options);
367
327
  if (!result.success && result.errors.length > 0) {
368
328
  errors.push(...result.errors);