@tbela99/css-parser 1.4.6 → 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 +17 -0
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +6548 -6964
  4. package/dist/index.cjs +7784 -8198
  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 -504
  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 -298
  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,9 +1,8 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
- import { tokensfuncDefMap, mFLT, mFGT, definedPropertySettings } from '../../syntax/constants.js';
3
- import { matchAllSyntaxes, createValidationContext, trimArray, isStyleRangeValue } from '../../validation/match.js';
2
+ import { tokensfuncDefMap, LOC, mFGT, mFLT } from '../../syntax/constants.js';
3
+ import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
5
  import { getSyntaxRule } from '../../validation/config.js';
6
- import { parseColor } from '../../syntax/syntax.js';
7
6
 
8
7
  function parseAtRuleContainerQueryList(stream, context, options = {}) {
9
8
  let matchCount = 0;
@@ -49,19 +48,19 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
49
48
  (stream[i]?.typ === EnumToken.WhitespaceTokenType || stream[i]?.typ === EnumToken.CommentTokenType)) {
50
49
  tokens.push(stream[i++]);
51
50
  }
52
- if (i >= stream.length) {
53
- return {
54
- success: false,
55
- errors: [
56
- {
57
- action: "drop",
58
- node: context,
59
- location: context.loc,
60
- message: `expecting <container-condition> at ${context.loc?.src}:${context?.loc?.sta.lin}:${context.loc?.sta.col}`,
61
- },
62
- ],
63
- };
64
- }
51
+ // if (i >= stream.length) {
52
+ // return {
53
+ // success: false,
54
+ // errors: [
55
+ // {
56
+ // action: "drop",
57
+ // node: context,
58
+ // location: context[LOC],
59
+ // message: `expecting <container-condition> at ${context[LOC]?.src}:${context?.[LOC]?.sta.lin}:${context[LOC]?.sta.col}`,
60
+ // },
61
+ // ],
62
+ // };
63
+ // }
65
64
  if (stream[i].typ === EnumToken.IdenTokenType) {
66
65
  tokens.push(stream[i++]);
67
66
  }
@@ -77,36 +76,34 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
77
76
  {
78
77
  action: "drop",
79
78
  node: stream[i],
80
- location: stream[i]?.loc ?? context.loc,
81
- message: `expecting <container-condition> at ${(stream[i] ?? context)?.loc?.src}:${(stream[i] ?? context)?.loc?.sta.lin}:${(stream[i] ?? context)?.loc?.sta.col}`,
79
+ location: stream[i]?.[LOC], // ?? context[LOC],
80
+ message: `expecting <container-condition> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
82
81
  },
83
82
  ],
84
83
  };
85
84
  }
86
- if (stream[i]?.typ === EnumToken.IdenTokenType) {
87
- const val = stream[i].val.toLowerCase();
88
- if ("not" === val) {
89
- tokens.push(stream[i]);
90
- stack.push(Object.assign(stream[i], { typ: EnumToken.NotTokenType }));
91
- i++;
92
- }
93
- else if ("and" === val || "or" === val) {
94
- return {
95
- success: false,
96
- errors: [
97
- {
98
- action: "drop",
99
- node: stream[i],
100
- location: stream[i]?.loc,
101
- message: `unexpected token at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
102
- },
103
- ],
104
- };
105
- }
106
- else {
107
- tokens.push(stream[i++]);
108
- }
109
- }
85
+ // if (stream[i]?.typ === EnumToken.IdenTokenType) {
86
+ // const val: string = (stream[i] as IdentToken).val.toLowerCase();
87
+ // if ("not" === val) {
88
+ // tokens.push(stream[i]);
89
+ // stack.push(Object.assign(stream[i], { typ: EnumToken.NotTokenType }));
90
+ // i++;
91
+ // } else if ("and" === val || "or" === val) {
92
+ // return {
93
+ // success: false,
94
+ // errors: [
95
+ // {
96
+ // action: "drop",
97
+ // node: stream[i],
98
+ // location: stream[i]?.[LOC],
99
+ // message: `unexpected token at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
100
+ // },
101
+ // ],
102
+ // };
103
+ // } else {
104
+ // tokens.push(stream[i++]);
105
+ // }
106
+ // }
110
107
  for (; i < stream.length; i++) {
111
108
  tokens.push(stream[i]);
112
109
  if (stream[i].typ === EnumToken.WhitespaceTokenType || stream[i].typ === EnumToken.CommentTokenType) {
@@ -114,23 +111,22 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
114
111
  }
115
112
  if (expectAndOr) {
116
113
  let valid = true;
117
- if (stream[i].typ === EnumToken.IdenTokenType) {
118
- const val = stream[i].val.toLowerCase();
119
- valid = val === "and" || val === "or";
120
- }
121
- else {
122
- valid = stream[i].typ !== EnumToken.CommaTokenType;
123
- }
114
+ // if (stream[i].typ === EnumToken.IdenTokenType) {
115
+ // const val: string = (stream[i] as IdentToken).val.toLowerCase();
116
+ // valid = val === "and" || val === "or";
117
+ // } else {
118
+ valid = stream[i].typ !== EnumToken.CommaTokenType;
119
+ // }
124
120
  if (!valid) {
125
121
  success = false;
126
122
  errors.push({
127
123
  action: "drop",
128
124
  node: stream[i],
129
- message: `expecting <and>, <or> or comma at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
125
+ message: `expecting <and>, <or> or comma at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
130
126
  });
131
127
  break;
132
128
  }
133
- expectAndOr = false;
129
+ // expectAndOr = false;
134
130
  }
135
131
  if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
136
132
  scopes.push((currentScope = new Set()));
@@ -138,14 +134,14 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
138
134
  continue;
139
135
  }
140
136
  switch (stream[i].typ) {
141
- case EnumToken.LiteralTokenType:
142
- if (stream[i].val === "<") {
143
- stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
144
- }
145
- if (stream[i].val === ">") {
146
- stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
147
- }
148
- break;
137
+ // case EnumToken.LiteralTokenType:
138
+ // if ((stream[i] as LiteralToken).val === "<") {
139
+ // stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
140
+ // }
141
+ // if ((stream[i] as LiteralToken).val === ">") {
142
+ // stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
143
+ // }
144
+ // break;
149
145
  case EnumToken.ColonTokenType:
150
146
  case EnumToken.LtTokenType:
151
147
  case EnumToken.LteTokenType:
@@ -172,210 +168,215 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
172
168
  errors.push({
173
169
  action: "drop",
174
170
  node: stream[i],
175
- message: `<or> is not allowed outside of parentheses ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
176
- });
177
- break;
178
- }
179
- if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
180
- success = false;
181
- errors.push({
182
- action: "drop",
183
- node: stream[i],
184
- message: `cannot mix <and> and <or> at the same level at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
171
+ message: `<or> is not allowed outside of parentheses ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
185
172
  });
186
173
  break;
187
174
  }
175
+ // if (currentScope.has(val === "or" ? EnumToken.AndTokenType : EnumToken.OrTokenType)) {
176
+ // success = false;
177
+ // errors.push({
178
+ // action: "drop",
179
+ // node: stream[i],
180
+ // message: `cannot mix <and> and <or> at the same level at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
181
+ // });
182
+ // break;
183
+ // }
188
184
  currentScope.add(stream[i].typ);
189
185
  stack.push(stream[i]);
190
186
  }
191
- else if (scopes.length === 0) {
192
- success = false;
193
- errors.push({
194
- action: "drop",
195
- node: stream[i],
196
- location: stream[i]?.loc,
197
- message: `unexpected <ident> at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
198
- });
199
- return {
200
- success,
201
- errors,
202
- };
203
- }
187
+ // else if (scopes.length === 0) {
188
+ // success = false;
189
+ // errors.push({
190
+ // action: "drop",
191
+ // node: stream[i],
192
+ // location: stream[i]?.[LOC],
193
+ // message: `unexpected <ident> at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
194
+ // });
195
+ // return {
196
+ // success,
197
+ // errors,
198
+ // };
199
+ // }
204
200
  }
205
201
  break;
206
202
  case EnumToken.EndParensTokenType:
207
203
  // feature
208
- if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
209
- // <mf-lt> | <mf-gt>
210
- const index = tokens.indexOf(stack.at(-1));
211
- const prevToken = stack[stack.length - 2];
212
- if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
213
- if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
214
- success = false;
215
- errors.push({
216
- action: "drop",
217
- node: stream[i],
218
- message: `unmatched '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
219
- });
220
- break;
221
- }
222
- if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
223
- success = false;
224
- errors.push({
225
- action: "drop",
226
- node: stack.at(-1),
227
- message: `expected <mf-lt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
228
- });
229
- break;
230
- }
231
- else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
232
- success = false;
233
- errors.push({
234
- action: "drop",
235
- node: stream[i],
236
- message: `expected <mf-gt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
237
- });
238
- break;
239
- }
240
- // <style-range>
241
- // const index: number = tokens.indexOf(stack.at(-1)!);
242
- // <mf-lt> | <mf-gt>
243
- const index2 = tokens.indexOf(prevToken);
244
- // '('
245
- const index3 = tokens.indexOf(stack.at(-3));
246
- const left = trimArray(tokens.slice(index3 + 1, index2));
247
- const right = trimArray(tokens.slice(index + 1, tokens.length - 1));
248
- const names = trimArray(tokens.slice(index2 + 1, index));
249
- if (!isStyleRangeValue(left)) {
250
- success = false;
251
- errors.push({
252
- action: "drop",
253
- node: left[0],
254
- message: `expected <style-feature-value> at ${left[0]?.loc?.src}:${left[0]?.loc?.sta.lin}:${left[0]?.loc?.sta.col}`,
255
- });
256
- break;
257
- }
258
- if (!isStyleRangeValue(right)) {
259
- success = false;
260
- errors.push({
261
- action: "drop",
262
- node: right[0],
263
- message: `expected <style-feature-value> at ${right[0]?.loc?.src}:${right[0]?.loc?.sta.lin}:${right[0]?.loc?.sta.col}`,
264
- });
265
- break;
266
- }
267
- if (!isStyleRangeValue(names)) {
268
- success = false;
269
- errors.push({
270
- action: "drop",
271
- node: names[0],
272
- message: `expected <style-feature-value> at ${names[0]?.loc?.src}:${names[0]?.loc?.sta.lin}:${names[0]?.loc?.sta.col}`,
273
- });
274
- break;
275
- }
276
- tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
277
- typ: EnumToken.ContainerStyleRangeTokenType,
278
- l: left,
279
- op: names,
280
- r: right,
281
- }, "loc", {
282
- ...definedPropertySettings,
283
- value: { ...left[0].loc, end: right.at(-1).loc.end },
284
- }));
285
- // check <style()> or <scroll-state()>
286
- stack.pop();
287
- stack.pop();
288
- }
289
- else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
290
- success = false;
291
- errors.push({
292
- action: "drop",
293
- node: stream[i],
294
- location: stream[i]?.loc,
295
- message: `expected '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
296
- });
297
- break;
298
- }
299
- }
204
+ // if (mFLT.has(stack.at(-1)?.typ) || mFGT.has(stack.at(-1)?.typ)) {
205
+ // // <mf-lt> | <mf-gt>
206
+ // const index: number = tokens.indexOf(stack.at(-1)!);
207
+ // const prevToken: Token = stack[stack.length - 2];
208
+ // if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
209
+ // if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
210
+ // success = false;
211
+ // errors.push({
212
+ // action: "drop",
213
+ // node: stream[i],
214
+ // message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
215
+ // });
216
+ // break;
217
+ // }
218
+ // if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
219
+ // success = false;
220
+ // errors.push({
221
+ // action: "drop",
222
+ // node: stack.at(-1),
223
+ // message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
224
+ // });
225
+ // break;
226
+ // } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
227
+ // success = false;
228
+ // errors.push({
229
+ // action: "drop",
230
+ // node: stream[i],
231
+ // message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
232
+ // });
233
+ // break;
234
+ // }
235
+ // // <style-range>
236
+ // // const index: number = tokens.indexOf(stack.at(-1)!);
237
+ // // <mf-lt> | <mf-gt>
238
+ // const index2: number = tokens.indexOf(prevToken);
239
+ // // '('
240
+ // const index3: number = tokens.indexOf(stack.at(-3)!);
241
+ // const left: Token[] = trimArray(tokens.slice(index3 + 1, index2));
242
+ // const right: Token[] = trimArray(tokens.slice(index + 1, tokens.length - 1));
243
+ // const names: Token[] = trimArray(tokens.slice(index2 + 1, index));
244
+ // if (!isStyleFeatureValue(left)) {
245
+ // success = false;
246
+ // errors.push({
247
+ // action: "drop",
248
+ // node: left[0],
249
+ // message: `expected <style-feature-value> at ${left[0]?.[LOC]?.src}:${left[0]?.[LOC]?.sta.lin}:${left[0]?.[LOC]?.sta.col}`,
250
+ // });
251
+ // break;
252
+ // }
253
+ // if (!isStyleFeatureValue(right)) {
254
+ // success = false;
255
+ // errors.push({
256
+ // action: "drop",
257
+ // node: right[0],
258
+ // message: `expected <style-feature-value> at ${right[0]?.[LOC]?.src}:${right[0]?.[LOC]?.sta.lin}:${right[0]?.[LOC]?.sta.col}`,
259
+ // });
260
+ // break;
261
+ // }
262
+ // if (!isStyleFeatureValue(names)) {
263
+ // success = false;
264
+ // errors.push({
265
+ // action: "drop",
266
+ // node: names[0],
267
+ // message: `expected <style-feature-value> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
268
+ // });
269
+ // break;
270
+ // }
271
+ // tokens.splice(index3 + 1, tokens.length - index3 - 2, {
272
+ // typ: EnumToken.ContainerStyleRangeTokenType,
273
+ // l: left,
274
+ // op: names,
275
+ // r: right,
276
+ // [LOC]: { ...left[0][LOC]!, end: right.at(-1)![LOC]!.end },
277
+ // } as ContainerStyleRangeToken);
278
+ // // check <style()> or <scroll-state()>
279
+ // stack.pop();
280
+ // stack.pop();
281
+ // } else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
282
+ // success = false;
283
+ // errors.push({
284
+ // action: "drop",
285
+ // node: stream[i],
286
+ // location: stream[i]?.[LOC],
287
+ // message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
288
+ // });
289
+ // break;
290
+ // }
291
+ // }
300
292
  if (mFGT.has(stack.at(-1)?.typ) ||
301
293
  mFLT.has(stack.at(-1)?.typ) ||
302
294
  stack.at(-1)?.typ === EnumToken.DelimTokenType ||
303
295
  stack.at(-1)?.typ === EnumToken.ColonTokenType) {
304
- const funcName = stack[stack.length - 2].val?.toLowerCase?.();
305
- if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
306
- !(stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
307
- ("style" === funcName || "scroll-state" === funcName))) {
308
- success = false;
309
- errors.push({
310
- action: "drop",
311
- node: stream[i],
312
- location: stream[i]?.loc,
313
- message: `unmatched2 ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
314
- });
315
- break;
316
- }
296
+ stack[stack.length - 2].val?.toLowerCase?.();
297
+ // if (
298
+ // stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType &&
299
+ // !(
300
+ // stack[stack.length - 2]?.typ === EnumToken.ContainerFunctionTokenDefType &&
301
+ // ("style" === funcName || "scroll-state" === funcName)
302
+ // )
303
+ // ) {
304
+ // success = false;
305
+ // errors.push({
306
+ // action: "drop",
307
+ // node: stream[i],
308
+ // location: stream[i]?.[LOC],
309
+ // message: `unmatched2 ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
310
+ // });
311
+ // break;
312
+ // }
317
313
  const index2 = tokens.indexOf(stack.at(-1));
318
314
  const index3 = tokens.indexOf(stack.at(-2));
319
315
  let names = trimArray(tokens.slice(index3 + 1, index2));
320
316
  let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
321
- if (stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
322
- stack.at(-1)?.typ !== EnumToken.DelimTokenType) {
323
- names.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
324
- }
325
- tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
317
+ // if (
318
+ // stack.at(-1)?.typ !== EnumToken.ColonTokenType &&
319
+ // stack.at(-1)?.typ !== EnumToken.DelimTokenType
320
+ // ) {
321
+ // const filteredNames = names.filter(
322
+ // (n) =>
323
+ // n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
324
+ // );
325
+ // if (
326
+ // filteredNames.length !== 1 ||
327
+ // (filteredNames[0].typ !== EnumToken.IdenTokenType &&
328
+ // filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
329
+ // ) {
330
+ // }
331
+ // }
332
+ tokens.splice(index3 + 1, tokens.length - index3 - 2, {
326
333
  typ: EnumToken.MediaQueryConditionTokenType,
327
334
  l: names,
328
335
  op: stack.pop(),
329
336
  r: values,
330
- }, "loc", {
331
- ...definedPropertySettings,
332
- value: { ...names[0].loc, end: values.at(-1).loc.end },
333
- }));
337
+ [LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
338
+ });
334
339
  // check <style()> or <scroll-state()>
335
340
  }
336
341
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
337
342
  const index = tokens.indexOf(stack.at(-1));
338
- Object.defineProperty(Object.assign(tokens[index], {
343
+ Object.assign(tokens[index], {
339
344
  typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
340
345
  chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
341
- }), "loc", {
342
- ...definedPropertySettings,
343
- value: { ...tokens[index].loc, end: stream[i].loc.end },
344
346
  });
347
+ tokens[index][LOC] = { ...tokens[index][LOC], end: stream[i][LOC].end };
345
348
  if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
346
349
  success = false;
347
350
  errors.push({
348
351
  action: "drop",
349
352
  node: stream[i],
350
- location: stream[i]?.loc,
351
- message: `expecting '<${tokens[index].val}-query>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
353
+ location: stream[i]?.[LOC],
354
+ message: `expecting '<${tokens[index].val}-query>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
352
355
  });
353
356
  break;
354
357
  }
355
358
  tokens.length = index + 1;
356
- if (EnumToken.ColorTokenType === tokens[index].typ) {
357
- parseColor(tokens[index]);
358
- }
359
+ // if (EnumToken.ColorTokenType === tokens[index].typ) {
360
+ // parseColor(tokens[index]);
361
+ // }
359
362
  stack.pop();
360
363
  scopes.pop();
361
364
  currentScope = scopes.at(-1);
362
365
  }
363
366
  else {
364
367
  const index = tokens.indexOf(stack.at(-1));
365
- tokens[index] = Object.defineProperty({
368
+ tokens[index] = {
366
369
  typ: EnumToken.ParensTokenType,
367
370
  chi: tokens.slice(index + 1, tokens.length - 1),
368
- }, "loc", {
369
- ...definedPropertySettings,
370
- value: { ...tokens[index].loc, end: stream[i].loc.end },
371
- });
371
+ [LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
372
+ };
372
373
  if (tokens[index].chi.every((t) => t.typ === EnumToken.WhitespaceTokenType || t.typ === EnumToken.CommentTokenType)) {
373
374
  success = false;
374
375
  errors.push({
375
376
  action: "drop",
376
377
  node: stream[i],
377
- location: stream[i]?.loc,
378
- message: `expecting '<query-in-parens>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
378
+ location: stream[i]?.[LOC],
379
+ message: `expecting '<query-in-parens>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
379
380
  });
380
381
  break;
381
382
  }
@@ -396,23 +397,21 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
396
397
  errors.push({
397
398
  action: "drop",
398
399
  node: tokens[k],
399
- location: tokens[k]?.loc,
400
- message: `unexpected token 'not' at ${tokens[k]?.loc?.src}:${tokens[k]?.loc?.sta.lin}:${tokens[k]?.loc?.sta.col}`,
400
+ location: tokens[k]?.[LOC],
401
+ message: `unexpected token 'not' at ${tokens[k]?.[LOC]?.src}:${tokens[k]?.[LOC]?.sta.lin}:${tokens[k]?.[LOC]?.sta.col}`,
401
402
  });
402
403
  break;
403
404
  }
404
405
  }
405
- const index = tokens.indexOf(stack.at(-1));
406
- const slice = trimArray(tokens.slice(index + 1));
407
- tokens[index] = Object.defineProperty({
408
- typ: EnumToken.MediaQueryUnaryFeatureTokenType,
409
- l: stack.pop(),
410
- r: slice,
411
- }, "loc", {
412
- ...definedPropertySettings,
413
- value: { ...tokens[index].loc, end: slice.at(-1).loc.end },
414
- });
415
- tokens.length = index + 1;
406
+ // const index = tokens.indexOf(stack.at(-1)!);
407
+ // const slice = trimArray(tokens.slice(index + 1));
408
+ // tokens[index] = {
409
+ // typ: EnumToken.MediaQueryUnaryFeatureTokenType,
410
+ // l: stack.pop()!,
411
+ // r: slice,
412
+ // [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end },
413
+ // };
414
+ // tokens.length = index + 1;
416
415
  }
417
416
  if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
418
417
  stack.at(-1)?.typ === EnumToken.OrTokenType) {
@@ -425,38 +424,36 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
425
424
  }
426
425
  const left = trimArray(tokens.slice(l, index));
427
426
  const right = trimArray(tokens.slice(index + 1));
428
- tokens[l] = Object.defineProperty({
427
+ tokens[l] = {
429
428
  typ: EnumToken.MediaQueryConditionTokenType,
430
429
  op: stack.pop(),
431
430
  l: left,
432
431
  r: right,
433
- }, "loc", {
434
- ...definedPropertySettings,
435
- value: { ...left[0].loc, end: right.at(-1).loc.end },
436
- });
432
+ [LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
433
+ };
437
434
  tokens.length = l + 1;
438
435
  expectAndOr = true;
439
436
  }
440
437
  break;
441
- default:
442
- if (tokensfuncDefMap.has(stream[i]?.typ)) {
443
- stack.push(stream[i]);
444
- scopes.push((currentScope = new Set()));
445
- }
446
- break;
438
+ // default:
439
+ // if (tokensfuncDefMap.has(stream[i]?.typ)) {
440
+ // stack.push(stream[i]);
441
+ // scopes.push((currentScope = new Set()));
442
+ // }
443
+ // break;
447
444
  }
448
445
  if (!success) {
449
446
  break;
450
447
  }
451
448
  }
452
- if (success && stack.length > 0) {
453
- success = false;
454
- errors.push({
455
- action: "drop",
456
- node: stack.at(-1),
457
- message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
458
- });
459
- }
449
+ // if (success && stack.length > 0) {
450
+ // success = false;
451
+ // errors.push({
452
+ // action: "drop",
453
+ // node: stack.at(-1),
454
+ // message: `unmatched token '${EnumToken[stack.at(-1)?.typ]}' at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
455
+ // });
456
+ // }
460
457
  if (!success) {
461
458
  return {
462
459
  success,
@@ -471,9 +468,9 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
471
468
  stream.push(...parts
472
469
  .filter((p) => p.length > 0 && p[0].typ !== EnumToken.InvalidMediaQueryTokenType)
473
470
  .reduce((acc, b) => {
474
- if (acc.length > 0) {
475
- acc.push({ typ: EnumToken.CommaTokenType });
476
- }
471
+ // if (acc.length > 0) {
472
+ // acc.push({ typ: EnumToken.CommaTokenType });
473
+ // }
477
474
  acc.push(...b);
478
475
  return acc;
479
476
  }, []));