@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,8 +1,8 @@
1
1
  import { EnumToken } from '../../ast/types.js';
2
2
  import { evaluate } from '../../ast/math/expression.js';
3
3
  import { gcd } from '../../ast/math/math.js';
4
- import { tokensfuncDefMap, mediaTypes, definedPropertySettings, mFLT, mFGT } from '../../syntax/constants.js';
5
- import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue, isMFName } from '../../validation/match.js';
4
+ import { tokensfuncDefMap, mediaTypes, LOC, mFLT, mFGT } from '../../syntax/constants.js';
5
+ import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue } from '../../validation/match.js';
6
6
  import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
7
7
  import { getParsedSyntax } from '../../validation/config.js';
8
8
 
@@ -51,61 +51,66 @@ function parseMediaqueryList(stream, options) {
51
51
  if (i < stream.length) {
52
52
  if (stream[i].typ === EnumToken.IdenTokenType) {
53
53
  const val = stream[i].val.toLowerCase();
54
- if ("not" === val || "only" === val) {
55
- tokens.push(stream[i]);
56
- stack.push(stream[i]);
57
- i++;
58
- while (i < stream.length &&
59
- (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
60
- stream[i]?.typ === EnumToken.CommentTokenType)) {
61
- tokens.push(stream[i]);
62
- i++;
63
- }
64
- if (stream[i]?.typ !== EnumToken.IdenTokenType ||
65
- !mediaTypes.includes(stream[i].val.toLowerCase())) {
66
- errors.push({
67
- action: "drop",
68
- node: stream[i],
69
- message: `expecting '<media-type>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
70
- });
71
- continue;
72
- }
73
- const index = tokens.indexOf(stack[stack.length - 1]);
74
- tokens[index] = Object.defineProperty(Object.assign(tokens[index], {
75
- typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
76
- val: stream[i],
77
- }), "loc", { ...definedPropertySettings, value: { ...tokens[index].loc, end: stream[i].loc.end } });
78
- tokens.length = index + 1;
79
- i++;
80
- // expect end of stream | and | or | not
81
- while (i < stream.length &&
82
- (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
83
- stream[i]?.typ === EnumToken.CommentTokenType)) {
84
- tokens.push(stream[i]);
85
- i++;
86
- }
87
- if (i < stream.length) {
88
- if (stream[i].typ === EnumToken.AndTokenType) {
89
- tokens.push(Object.assign(stream[i], { typ: EnumToken.AndTokenType }));
90
- stack.push(stream[i]);
91
- i++;
92
- }
93
- else if (stream[i].typ === EnumToken.OrTokenType) {
94
- tokens.push(Object.assign(stream[i], { typ: EnumToken.OrTokenType }));
95
- stack.push(stream[i]);
96
- i++;
97
- }
98
- else {
99
- success = false;
100
- errors.push({
101
- action: "drop",
102
- node: stream[i],
103
- message: `expecting 'and' or 'or' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
104
- });
105
- }
106
- }
107
- }
108
- else if (mediaTypes.includes(val)) {
54
+ // if ("not" === val || "only" === val) {
55
+ // tokens.push(stream[i]);
56
+ // stack.push(stream[i]);
57
+ // i++;
58
+ // while (
59
+ // i < stream.length &&
60
+ // (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
61
+ // stream[i]?.typ === EnumToken.CommentTokenType)
62
+ // ) {
63
+ // tokens.push(stream[i]);
64
+ // i++;
65
+ // }
66
+ // if (
67
+ // stream[i]?.typ !== EnumToken.IdenTokenType ||
68
+ // !mediaTypes.includes((stream[i] as IdentToken).val.toLowerCase())
69
+ // ) {
70
+ // errors.push({
71
+ // action: "drop",
72
+ // node: stream[i],
73
+ // message: `expecting '<media-type>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
74
+ // });
75
+ // continue;
76
+ // }
77
+ // const index: number = tokens.indexOf(stack[stack.length - 1]);
78
+ // tokens[index][LOC] = { ...tokens[index][LOC]!, end: stream[i][LOC]!.end };
79
+ // tokens[index] = Object.assign(tokens[index], {
80
+ // typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
81
+ // val: stream[i],
82
+ // });
83
+ // tokens.length = index + 1;
84
+ // i++;
85
+ // // expect end of stream | and | or | not
86
+ // while (
87
+ // i < stream.length &&
88
+ // (stream[i]?.typ === EnumToken.WhitespaceTokenType ||
89
+ // stream[i]?.typ === EnumToken.CommentTokenType)
90
+ // ) {
91
+ // tokens.push(stream[i]);
92
+ // i++;
93
+ // }
94
+ // if (i < stream.length) {
95
+ // if (stream[i].typ === EnumToken.AndTokenType) {
96
+ // tokens.push(Object.assign(stream[i], { typ: EnumToken.AndTokenType }));
97
+ // stack.push(stream[i]);
98
+ // i++;
99
+ // } else if (stream[i].typ === EnumToken.OrTokenType) {
100
+ // tokens.push(Object.assign(stream[i], { typ: EnumToken.OrTokenType }));
101
+ // stack.push(stream[i]);
102
+ // i++;
103
+ // } else {
104
+ // success = false;
105
+ // errors.push({
106
+ // action: "drop",
107
+ // node: stream[i],
108
+ // message: `expecting 'and' or 'or' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
109
+ // });
110
+ // }
111
+ // }
112
+ // } else
113
+ if (mediaTypes.includes(val)) {
109
114
  tokens.push(stream[i]);
110
115
  i++;
111
116
  }
@@ -113,9 +118,9 @@ function parseMediaqueryList(stream, options) {
113
118
  success = false;
114
119
  errors.push({
115
120
  action: "drop",
116
- message: `expecting '<media-type>' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
121
+ message: `expecting '<media-type>' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
117
122
  node: stream[i],
118
- location: stream[i].loc,
123
+ location: stream[i][LOC],
119
124
  });
120
125
  }
121
126
  }
@@ -123,9 +128,9 @@ function parseMediaqueryList(stream, options) {
123
128
  success = false;
124
129
  errors.push({
125
130
  action: "drop",
126
- message: `expecting '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
131
+ message: `expecting '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
127
132
  node: stream[i],
128
- location: stream[i].loc,
133
+ location: stream[i][LOC],
129
134
  });
130
135
  }
131
136
  }
@@ -135,23 +140,18 @@ function parseMediaqueryList(stream, options) {
135
140
  continue;
136
141
  }
137
142
  if (expectAndOrComma) {
138
- let valid = true;
139
143
  if (stream[i].typ === EnumToken.IdenTokenType) {
140
- const val = stream[i].val.toLowerCase();
141
- valid = val === "and" || val === "or";
142
- }
143
- else {
144
- valid = stream[i].typ !== EnumToken.CommaTokenType;
145
- }
146
- if (!valid) {
147
- success = false;
148
- errors.push({
149
- action: "drop",
150
- node: stream[i],
151
- message: `expecting <and>, <or> or comma at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
152
- });
153
- break;
144
+ stream[i].val.toLowerCase();
154
145
  }
146
+ // if (!valid) {
147
+ // success = false;
148
+ // errors.push({
149
+ // action: "drop",
150
+ // node: stream[i],
151
+ // message: `expecting <and>, <or> or comma at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
152
+ // });
153
+ // break;
154
+ // }
155
155
  expectAndOrComma = false;
156
156
  }
157
157
  if (stream[i].typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stream[i].typ)) {
@@ -160,14 +160,14 @@ function parseMediaqueryList(stream, options) {
160
160
  continue;
161
161
  }
162
162
  switch (stream[i].typ) {
163
- case EnumToken.LiteralTokenType:
164
- if (stream[i].val === "<") {
165
- stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
166
- }
167
- if (stream[i].val === ">") {
168
- stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
169
- }
170
- break;
163
+ // case EnumToken.LiteralTokenType:
164
+ // if ((stream[i] as LiteralToken).val === "<") {
165
+ // stack.push(Object.assign(stream[i], { typ: EnumToken.LtTokenType }));
166
+ // }
167
+ // if ((stream[i] as LiteralToken).val === ">") {
168
+ // stack.push(Object.assign(stream[i], { typ: EnumToken.GtTokenType }));
169
+ // }
170
+ // break;
171
171
  case EnumToken.ColonTokenType:
172
172
  case EnumToken.LtTokenType:
173
173
  case EnumToken.LteTokenType:
@@ -179,13 +179,13 @@ function parseMediaqueryList(stream, options) {
179
179
  case EnumToken.IdenTokenType:
180
180
  {
181
181
  const val = stream[i].val.toLowerCase();
182
- if (val === "not" || val === "only") {
183
- Object.assign(stream[i], {
184
- typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
185
- });
186
- stack.push(stream[i]);
187
- }
188
- else if (val === "and" || val === "or") {
182
+ // if (val === "not" || val === "only") {
183
+ // Object.assign(stream[i], {
184
+ // typ: val === "not" ? EnumToken.NotTokenType : EnumToken.OnlyTokenType,
185
+ // });
186
+ // stack.push(stream[i]);
187
+ // } else
188
+ if (val === "and" || val === "or") {
189
189
  Object.assign(stream[i], {
190
190
  typ: val === "and" ? EnumToken.AndTokenType : EnumToken.OrTokenType,
191
191
  });
@@ -194,7 +194,7 @@ function parseMediaqueryList(stream, options) {
194
194
  errors.push({
195
195
  action: "drop",
196
196
  node: stream[i],
197
- message: `<or> is not allowed outside of parentheses ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
197
+ message: `<or> is not allowed outside of parentheses ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
198
198
  });
199
199
  break;
200
200
  }
@@ -203,7 +203,7 @@ function parseMediaqueryList(stream, options) {
203
203
  errors.push({
204
204
  action: "drop",
205
205
  node: stream[i],
206
- 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}`,
206
+ 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}`,
207
207
  });
208
208
  }
209
209
  currentScope.add(stream[i].typ);
@@ -214,12 +214,10 @@ function parseMediaqueryList(stream, options) {
214
214
  case EnumToken.EndParensTokenType:
215
215
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
216
216
  const index = tokens.indexOf(stack.at(-1));
217
- Object.defineProperty(Object.assign(tokens[index], {
217
+ tokens[index][LOC] = { ...tokens[index][LOC], end: stream[i][LOC].end };
218
+ Object.assign(tokens[index], {
218
219
  typ: tokensfuncDefMap.get(stack.at(-1)?.typ),
219
220
  chi: trimArray(tokens.slice(index + 1, tokens.length - 1)),
220
- }), "loc", {
221
- ...definedPropertySettings,
222
- value: { ...tokens[index].loc, end: stream[i].loc.end },
223
221
  });
224
222
  tokens.length = index + 1;
225
223
  const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, tokens[index].val + "()")?.[0]?.chi, createValidationContext(tokens[index].chi), options);
@@ -238,33 +236,32 @@ function parseMediaqueryList(stream, options) {
238
236
  const index = tokens.indexOf(stack.at(-1));
239
237
  const prevToken = stack[stack.length - 2];
240
238
  if (mFLT.has(prevToken?.typ) || mFGT.has(prevToken?.typ)) {
241
- if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
242
- success = false;
243
- errors.push({
244
- action: "drop",
245
- node: stream[i],
246
- message: `unmatched '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
247
- });
248
- break;
249
- }
250
- if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
251
- success = false;
252
- errors.push({
253
- action: "drop",
254
- node: stack.at(-1),
255
- message: `expected <mf-lt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
256
- });
257
- break;
258
- }
259
- else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
260
- success = false;
261
- errors.push({
262
- action: "drop",
263
- node: stream[i],
264
- message: `expected <mf-gt> at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
265
- });
266
- break;
267
- }
239
+ // if (stack[stack.length - 3]?.typ !== EnumToken.StartParensTokenType) {
240
+ // success = false;
241
+ // errors.push({
242
+ // action: "drop",
243
+ // node: stream[i],
244
+ // message: `unmatched '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
245
+ // });
246
+ // break;
247
+ // }
248
+ // if (!mFLT.has(stack.at(-1)?.typ) && mFLT.has(prevToken?.typ)) {
249
+ // success = false;
250
+ // errors.push({
251
+ // action: "drop",
252
+ // node: stack.at(-1),
253
+ // message: `expected <mf-lt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
254
+ // });
255
+ // break;
256
+ // } else if (!mFGT.has(stack.at(-1)?.typ) && mFGT.has(prevToken?.typ)) {
257
+ // success = false;
258
+ // errors.push({
259
+ // action: "drop",
260
+ // node: stream[i],
261
+ // message: `expected <mf-gt> at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
262
+ // });
263
+ // break;
264
+ // }
268
265
  // const index: number = tokens.indexOf(stack.at(-1)!);
269
266
  // <mf-lt> | <mf-name>
270
267
  const index2 = tokens.indexOf(prevToken);
@@ -274,15 +271,15 @@ function parseMediaqueryList(stream, options) {
274
271
  const right = trimArray(tokens.slice(index + 1, tokens.length - 1));
275
272
  const names = trimArray(tokens.slice(index2 + 1, index));
276
273
  const filteredNames = names.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
277
- if (filteredNames.length !== 1 || filteredNames[0].typ !== EnumToken.IdenTokenType) {
278
- success = false;
279
- errors.push({
280
- action: "drop",
281
- node: stream[i],
282
- message: `expected <mf-name>> at ${filteredNames[0]?.loc?.src}:${filteredNames[0]?.loc?.sta.lin}:${filteredNames[0]?.loc?.sta.col}`,
283
- });
284
- break;
285
- }
274
+ // if (filteredNames.length !== 1 || filteredNames[0].typ !== EnumToken.IdenTokenType) {
275
+ // success = false;
276
+ // errors.push({
277
+ // action: "drop",
278
+ // node: stream[i],
279
+ // message: `expected <mf-name>> at ${filteredNames[0]?.[LOC]?.src}:${filteredNames[0]?.[LOC]?.sta.lin}:${filteredNames[0]?.[LOC]?.sta.col}`,
280
+ // });
281
+ // break;
282
+ // }
286
283
  const name = filteredNames[0].val;
287
284
  const mfInfo = getMFInfo(name);
288
285
  for (const val of [left, right]) {
@@ -295,17 +292,18 @@ function parseMediaqueryList(stream, options) {
295
292
  val[l].val === "calc") {
296
293
  const value = evaluate([val[l]]);
297
294
  if (value.length == 1) {
298
- if (mfInfo?.type === MediaFeatureType.RatioType) {
299
- if (value[0].typ !== EnumToken.NumberTokenType ||
300
- !(value[0].val
301
- ?.typ === EnumToken.FractionTokenType)) {
302
- continue;
303
- }
304
- }
305
- Object.defineProperty(value[0], "loc", {
306
- ...definedPropertySettings,
307
- value: val[l].loc,
308
- });
295
+ // if (mfInfo?.type === MediaFeatureType.RatioType) {
296
+ // if (
297
+ // value[0].typ !== EnumToken.NumberTokenType ||
298
+ // !(
299
+ // ((value[0] as NumberToken).val as FractionToken)
300
+ // ?.typ === EnumToken.FractionTokenType
301
+ // )
302
+ // ) {
303
+ // continue;
304
+ // }
305
+ // }
306
+ value[0][LOC] = val[l][LOC];
309
307
  val[l] = value[0];
310
308
  }
311
309
  }
@@ -313,27 +311,27 @@ function parseMediaqueryList(stream, options) {
313
311
  }
314
312
  }
315
313
  }
316
- let isValidMFValue = isMFValue(name, left, true);
317
- if (isValidMFValue.valid && !isValidMFValue.success) {
318
- success = false;
319
- errors.push({
320
- action: "drop",
321
- node: left[0] ?? prevToken,
322
- message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(left[0] ?? prevToken)?.loc?.src}:${(left[0] ?? prevToken)?.loc?.sta.lin}:${(left[0] ?? prevToken)?.loc?.sta.col}`,
323
- });
324
- break;
325
- }
326
- isValidMFValue = isMFValue(name, right, true);
327
- if (isValidMFValue.valid && !isValidMFValue.success) {
328
- success = false;
329
- errors.push({
330
- action: "drop",
331
- node: right[0] ?? stream[i],
332
- location: (right[0] ?? stream[i])?.loc,
333
- message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(right[0] ?? stream[i])?.loc?.src}:${(right[0] ?? stream[i])?.loc?.sta.lin}:${(left[0] ?? stream[i])?.loc?.sta.col}`,
334
- });
335
- break;
336
- }
314
+ isMFValue(name, left, true);
315
+ // if (isValidMFValue.valid && !isValidMFValue.success) {
316
+ // success = false;
317
+ // errors.push({
318
+ // action: "drop",
319
+ // node: left[0] ?? prevToken,
320
+ // message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(left[0] ?? prevToken)?.[LOC]?.src}:${(left[0] ?? prevToken)?.[LOC]?.sta.lin}:${(left[0] ?? prevToken)?.[LOC]?.sta.col}`,
321
+ // });
322
+ // break;
323
+ // }
324
+ isMFValue(name, right, true);
325
+ // if (isValidMFValue.valid && !isValidMFValue.success) {
326
+ // success = false;
327
+ // errors.push({
328
+ // action: "drop",
329
+ // node: right[0] ?? stream[i],
330
+ // location: (right[0] ?? stream[i])?.[LOC],
331
+ // message: `${isValidMFValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${(right[0] ?? stream[i])?.[LOC]?.src}:${(right[0] ?? stream[i])?.[LOC]?.sta.lin}:${(left[0] ?? stream[i])?.[LOC]?.sta.col}`,
332
+ // });
333
+ // break;
334
+ // }
337
335
  for (const val of [left, right]) {
338
336
  if (mfInfo?.type === MediaFeatureType.RatioType) {
339
337
  const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType &&
@@ -352,126 +350,131 @@ function parseMediaqueryList(stream, options) {
352
350
  }
353
351
  }
354
352
  }
355
- tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
353
+ tokens.splice(index3 + 1, tokens.length - index3 - 2, {
356
354
  typ: EnumToken.MediaRangeQueryTokenType,
357
355
  l: left,
358
356
  val: filteredNames,
359
357
  op1: prevToken,
360
358
  op2: stack.at(-1),
361
359
  r: right,
362
- }, "loc", {
363
- ...definedPropertySettings,
364
- value: { ...left[0].loc, end: right.at(-1).loc.end },
365
- }));
360
+ [LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
361
+ });
366
362
  stack.pop();
367
363
  stack.pop();
368
364
  }
369
- else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
370
- success = false;
371
- errors.push({
372
- action: "drop",
373
- node: stream[i],
374
- location: stream[i]?.loc,
375
- message: `expected '(' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
376
- });
377
- break;
378
- }
365
+ // else if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
366
+ // success = false;
367
+ // errors.push({
368
+ // action: "drop",
369
+ // node: stream[i],
370
+ // location: stream[i]?.[LOC],
371
+ // message: `expected '(' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
372
+ // });
373
+ // break;
374
+ // }
379
375
  }
380
376
  if (mFGT.has(stack.at(-1)?.typ) ||
381
377
  mFLT.has(stack.at(-1)?.typ) ||
382
378
  stack.at(-1)?.typ === EnumToken.DelimTokenType ||
383
379
  stack.at(-1)?.typ === EnumToken.ColonTokenType) {
384
- if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
385
- success = false;
386
- errors.push({
387
- action: "drop",
388
- node: stream[i],
389
- location: stream[i]?.loc,
390
- message: `expected '(' at ${(stack[stack.length - 2] ?? tokens[0])?.loc?.src}:${(stack[stack.length - 2] ?? tokens[0])?.loc?.sta.lin}:${(stack[stack.length - 2] ?? tokens[0])?.loc?.sta.col}`,
391
- });
392
- break;
393
- }
380
+ // if (stack[stack.length - 2]?.typ !== EnumToken.StartParensTokenType) {
381
+ // success = false;
382
+ // errors.push({
383
+ // action: "drop",
384
+ // node: stream[i],
385
+ // location: stream[i]?.[LOC],
386
+ // message: `expected '(' at ${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.src}:${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.sta.lin}:${(stack[stack.length - 2] ?? tokens[0])?.[LOC]?.sta.col}`,
387
+ // });
388
+ // break;
389
+ // }
394
390
  const index2 = tokens.indexOf(stack.at(-1));
395
391
  const index3 = tokens.indexOf(stack.at(-2));
396
392
  let names = trimArray(tokens.slice(index3 + 1, index2));
397
393
  let values = trimArray(tokens.slice(index2 + 1, tokens.length - 1));
398
- let swapped = false;
399
- if (stack.at(-1)?.typ !== EnumToken.ColonTokenType) {
400
- const filteredNames = names.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
401
- if (filteredNames.length !== 1 ||
402
- (filteredNames[0].typ !== EnumToken.IdenTokenType &&
403
- filteredNames[0].typ !== EnumToken.DashedIdenTokenType)) {
404
- swapped = true;
405
- }
406
- }
407
- const filteredNames = (swapped ? values : names).filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
408
- if (filteredNames.length !== 1 ||
409
- (filteredNames[0].typ !== EnumToken.IdenTokenType &&
410
- filteredNames[0].typ !== EnumToken.DashedIdenTokenType)) {
411
- success = false;
412
- errors.push({
413
- action: "drop",
414
- node: names[0] ?? stack.at(-1),
415
- location: names[0]?.loc,
416
- message: `expected <mf-name> at ${(names[0] ?? stack.at(-1))?.loc?.src}:${(names[0] ?? stack.at(-1))?.loc?.sta.lin}:${(names[0] ?? stack.at(-1))?.loc?.sta.col}`,
417
- });
418
- break;
419
- }
394
+ // if (stack.at(-1)?.typ !== EnumToken.ColonTokenType) {
395
+ // const filteredNames = names.filter(
396
+ // (n) =>
397
+ // n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType,
398
+ // );
399
+ // if (
400
+ // filteredNames.length !== 1 ||
401
+ // (filteredNames[0].typ !== EnumToken.IdenTokenType &&
402
+ // filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
403
+ // ) {
404
+ // swapped = true;
405
+ // }
406
+ // }
407
+ const filteredNames = (names).filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
408
+ // if (
409
+ // filteredNames.length !== 1 ||
410
+ // (filteredNames[0].typ !== EnumToken.IdenTokenType &&
411
+ // filteredNames[0].typ !== EnumToken.DashedIdenTokenType)
412
+ // ) {
413
+ // success = false;
414
+ // errors.push({
415
+ // action: "drop",
416
+ // node: names[0] ?? stack.at(-1),
417
+ // location: names[0]?.[LOC],
418
+ // message: `expected <mf-name> at ${(names[0] ?? stack.at(-1))?.[LOC]?.src}:${(names[0] ?? stack.at(-1))?.[LOC]?.sta.lin}:${(names[0] ?? stack.at(-1))?.[LOC]?.sta.col}`,
419
+ // });
420
+ // break;
421
+ // }
420
422
  const name = filteredNames[0].val;
421
- if (!isMFName(name)) {
422
- success = false;
423
- errors.push({
424
- action: "drop",
425
- node: names[0] ?? stack.at(-1),
426
- location: names[0]?.loc ?? stack.at(-1)?.loc,
427
- message: `expected <mf-name> at ${names[0]?.loc?.src}:${names[0]?.loc?.sta.lin}:${names[0]?.loc?.sta.col}`,
428
- });
429
- break;
430
- }
423
+ // if (!isMFName(name)) {
424
+ // success = false;
425
+ // errors.push({
426
+ // action: "drop",
427
+ // node: names[0] ?? stack.at(-1),
428
+ // location: names[0]?.[LOC] ?? stack.at(-1)?.[LOC],
429
+ // message: `expected <mf-name> at ${names[0]?.[LOC]?.src}:${names[0]?.[LOC]?.sta.lin}:${names[0]?.[LOC]?.sta.col}`,
430
+ // });
431
+ // break;
432
+ // }
431
433
  const mfInfo = getMFInfo(name);
432
434
  if (options.computeCalcExpression) {
433
435
  if (mfInfo == null ||
434
436
  (mfInfo.type != MediaFeatureType.KeywordType &&
435
437
  mfInfo.type != MediaFeatureType.StringType)) {
436
- const val = swapped ? names : values;
438
+ const val = values;
437
439
  for (let l = 0; l < val.length; l++) {
438
440
  if (val[l].typ === EnumToken.MathFunctionTokenType &&
439
441
  val[l].val === "calc") {
440
442
  const value = evaluate([val[l]]);
441
443
  if (value.length == 1) {
442
- if (mfInfo?.type === MediaFeatureType.RatioType) {
443
- if (value[0].typ !== EnumToken.NumberTokenType ||
444
- !(value[0].val?.typ ===
445
- EnumToken.FractionTokenType)) {
446
- continue;
447
- }
448
- }
449
- Object.defineProperty(value[0], "loc", {
450
- ...definedPropertySettings,
451
- value: val[l].loc,
452
- });
444
+ // if (mfInfo?.type === MediaFeatureType.RatioType) {
445
+ // if (
446
+ // value[0].typ !== EnumToken.NumberTokenType ||
447
+ // !(
448
+ // ((value[0] as NumberToken).val as FractionToken)?.typ ===
449
+ // EnumToken.FractionTokenType
450
+ // )
451
+ // ) {
452
+ // continue;
453
+ // }
454
+ // }
455
+ value[0][LOC] = val[l][LOC];
453
456
  val[l] = value[0];
454
457
  }
455
458
  }
456
459
  }
457
460
  }
458
461
  }
459
- const mfValue = isMFValue(name, swapped ? names : values, mFGT.has(stack.at(-1)?.typ) ||
462
+ const mfValue = isMFValue(name, values, mFGT.has(stack.at(-1)?.typ) ||
460
463
  mFLT.has(stack.at(-1)?.typ) ||
461
464
  stack.at(-1)?.typ === EnumToken.DelimTokenType);
462
465
  if (!mfValue.success) {
463
466
  success = false;
464
- const arr = swapped ? names : values;
467
+ const arr = values;
465
468
  errors.push({
466
469
  action: "drop",
467
470
  node: arr[0],
468
- location: arr[0]?.loc,
469
- message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${arr[0]?.loc?.src}:${arr[0]?.loc?.sta.lin}:${arr[0]?.loc?.sta.col}`,
471
+ location: arr[0]?.[LOC],
472
+ message: `${mfValue.isValueAllowed === false ? "invalid <mf-name>" : "expected <mf-value>"} at ${arr[0]?.[LOC]?.src}:${arr[0]?.[LOC]?.sta.lin}:${arr[0]?.[LOC]?.sta.col}`,
470
473
  });
471
474
  break;
472
475
  }
473
476
  if (mfInfo?.type === MediaFeatureType.RatioType) {
474
- const val = swapped ? names : values;
477
+ const val = values;
475
478
  const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType && n.typ !== EnumToken.CommentTokenType);
476
479
  if (filteredValues.length === 3) {
477
480
  if (options.computeCalcExpression) {
@@ -486,53 +489,52 @@ function parseMediaqueryList(stream, options) {
486
489
  val.splice(0, val.length, ...filteredValues);
487
490
  }
488
491
  }
489
- tokens.splice(index3 + 1, tokens.length - index3 - 2, Object.defineProperty({
492
+ tokens.splice(index3 + 1, tokens.length - index3 - 2, {
490
493
  typ: EnumToken.MediaQueryConditionTokenType,
491
494
  l: names,
492
495
  op: stack.pop(),
493
496
  r: values,
494
- }, "loc", {
495
- ...definedPropertySettings,
496
- value: { ...names[0].loc, end: values.at(-1).loc.end },
497
- }));
498
- }
499
- if (stack.length === 0) {
500
- success = false;
501
- errors.push({
502
- action: "drop",
503
- node: stream[i],
504
- location: stream[i]?.loc,
505
- message: `unmatched ')' at ${stream[i]?.loc?.src}:${stream[i]?.loc?.sta.lin}:${stream[i]?.loc?.sta.col}`,
497
+ // @ts-expect-error
498
+ [LOC]: { ...names[0][LOC], end: values.at(-1)[LOC].end },
506
499
  });
507
- break;
508
500
  }
501
+ // if (stack.length === 0) {
502
+ // success = false;
503
+ // errors.push({
504
+ // action: "drop",
505
+ // node: stream[i],
506
+ // location: stream[i]?.[LOC],
507
+ // message: `unmatched ')' at ${stream[i]?.[LOC]?.src}:${stream[i]?.[LOC]?.sta.lin}:${stream[i]?.[LOC]?.sta.col}`,
508
+ // });
509
+ // break;
510
+ // }
509
511
  {
510
512
  const index = tokens.indexOf(stack.at(-1));
511
- tokens[index] = Object.defineProperty({
513
+ tokens[index] = {
512
514
  typ: EnumToken.ParensTokenType,
513
515
  chi: tokens.slice(index + 1, tokens.length - 1),
514
- }, "loc", {
515
- ...definedPropertySettings,
516
- value: { ...tokens[index].loc, end: stream[i].loc.end },
517
- });
516
+ // @ts-expect-error
517
+ [LOC]: { ...tokens[index][LOC], end: stream[i][LOC].end },
518
+ };
518
519
  tokens.length = index + 1;
519
520
  scopes.pop();
520
521
  currentScope = scopes.at(-1);
521
522
  stack.pop();
522
- if (stack.at(-1)?.typ === EnumToken.NotTokenType ||
523
- stack.at(-1)?.typ === EnumToken.OnlyTokenType) {
524
- const index = tokens.indexOf(stack.at(-1));
525
- const slice = trimArray(tokens.slice(index + 1));
526
- tokens[index] = Object.defineProperty({
527
- typ: EnumToken.MediaQueryUnaryFeatureTokenType,
528
- l: stack.pop(),
529
- r: slice,
530
- }, "loc", {
531
- ...definedPropertySettings,
532
- value: { ...tokens[index].loc, end: slice.at(-1).loc.end },
533
- });
534
- tokens.length = index + 1;
535
- }
523
+ // if (
524
+ // stack.at(-1)?.typ === EnumToken.NotTokenType ||
525
+ // stack.at(-1)?.typ === EnumToken.OnlyTokenType
526
+ // ) {
527
+ // const index = tokens.indexOf(stack.at(-1)!);
528
+ // const slice = trimArray(tokens.slice(index + 1));
529
+ // tokens[index] = {
530
+ // typ: EnumToken.MediaQueryUnaryFeatureTokenType,
531
+ // l: stack.pop()!,
532
+ // r: slice,
533
+ // // @ts-expect-error
534
+ // [LOC]: { ...tokens[index][LOC]!, end: slice.at(-1)![LOC]!.end } as Location,
535
+ // };
536
+ // tokens.length = index + 1;
537
+ // }
536
538
  if (stack.at(-1)?.typ === EnumToken.AndTokenType ||
537
539
  stack.at(-1)?.typ === EnumToken.OrTokenType) {
538
540
  const index = tokens.indexOf(stack.at(-1));
@@ -544,15 +546,13 @@ function parseMediaqueryList(stream, options) {
544
546
  }
545
547
  const left = trimArray(tokens.slice(l, index));
546
548
  const right = trimArray(tokens.slice(index + 1));
547
- tokens[l] = Object.defineProperty({
549
+ tokens[l] = {
548
550
  typ: EnumToken.MediaQueryConditionTokenType,
549
551
  op: stack.pop(),
550
552
  l: left,
551
553
  r: right,
552
- }, "loc", {
553
- ...definedPropertySettings,
554
- value: { ...left[0].loc, end: right.at(-1).loc.end },
555
- });
554
+ [LOC]: { ...left[0][LOC], end: right.at(-1)[LOC].end },
555
+ };
556
556
  tokens.length = l + 1;
557
557
  expectAndOrComma = true;
558
558
  }
@@ -563,15 +563,15 @@ function parseMediaqueryList(stream, options) {
563
563
  break;
564
564
  }
565
565
  }
566
- if (success && stack.length > 0) {
567
- success = false;
568
- errors.push({
569
- action: "drop",
570
- node: stack.at(-1),
571
- location: stack.at(-1)?.loc,
572
- 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}`,
573
- });
574
- }
566
+ // if (success && stack.length > 0) {
567
+ // success = false;
568
+ // errors.push({
569
+ // action: "drop",
570
+ // node: stack.at(-1),
571
+ // location: stack.at(-1)?.[LOC],
572
+ // 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}`,
573
+ // });
574
+ // }
575
575
  if (!success) {
576
576
  hasErrors = true;
577
577
  parts.splice(parts.indexOf(stream), 1);