@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
@@ -2,11 +2,11 @@
2
2
  const LOWER = "abcdefghijklmnopqrstuvwxyz";
3
3
  const DIGITS = "0123456789";
4
4
  const FULL_ALPHABET = (LOWER + DIGITS).split(""); // 64 chars
5
- const FIRST_ALPHABET = (LOWER).split(""); // 54 chars (no digits)
5
+ const FIRST_ALPHABET = LOWER.split(""); // 54 chars (no digits)
6
6
  /**
7
7
  * supported hash algorithms
8
8
  */
9
- const hashAlgorithms = ['hex', 'base64', 'base64url', 'sha1', 'sha256', 'sha384', 'sha512'];
9
+ const hashAlgorithms = ["hex", "base64", "base64url", "sha1", "sha256", "sha384", "sha512"];
10
10
  // simple deterministic hash → number
11
11
  function hashCode(str) {
12
12
  let hash = 0;
@@ -39,15 +39,15 @@ function hashId(input, length = 6) {
39
39
  * @param input
40
40
  */
41
41
  function toHex(input) {
42
- let result = '';
42
+ let result = "";
43
43
  if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {
44
44
  for (const byte of Array.from(new Uint8Array(input))) {
45
- result += byte.toString(16).padStart(2, '0');
45
+ result += byte.toString(16).padStart(2, "0");
46
46
  }
47
47
  }
48
48
  else {
49
49
  for (const char of String(input)) {
50
- result += char.charCodeAt(0).toString(16).padStart(2, '0');
50
+ result += char.charCodeAt(0).toString(16).padStart(2, "0");
51
51
  }
52
52
  }
53
53
  return result;
@@ -62,20 +62,20 @@ async function hash(input, length = 6, algo) {
62
62
  let result;
63
63
  if (algo != null) {
64
64
  switch (algo) {
65
- case 'hex':
65
+ case "hex":
66
66
  return toHex(input).slice(0, length);
67
- case 'base64':
68
- case 'base64url':
67
+ case "base64url":
68
+ case "base64":
69
69
  result = btoa(input);
70
- if (algo == 'base64url') {
71
- result = result.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
70
+ if (algo == "base64url") {
71
+ result = result.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
72
72
  }
73
73
  return result.slice(0, length);
74
- case 'sha1':
75
- case 'sha256':
76
- case 'sha384':
77
- case 'sha512':
78
- return toHex(await crypto.subtle.digest(algo.replace('sha', 'SHA-'), new TextEncoder().encode(input))).slice(0, length);
74
+ case "sha256":
75
+ case "sha384":
76
+ case "sha512":
77
+ case "sha1":
78
+ return toHex(await crypto.subtle.digest(algo.replace("sha", "SHA-"), new TextEncoder().encode(input))).slice(0, length);
79
79
  default:
80
80
  throw new Error(`Unsupported hash algorithm: ${algo}`);
81
81
  }
@@ -1,7 +1,7 @@
1
1
  import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
2
2
  import { renderValue } from '../../renderer/render.js';
3
- import { definedPropertySettings, tokensfuncDefMap, combinators } from '../../syntax/constants.js';
4
- import { pseudoElements, isIdent, isHash } from '../../syntax/syntax.js';
3
+ import { LOC, ERRORS, STATE, TOKENS, pseudoElements, tokensfuncDefMap, combinators, PARENT } from '../../syntax/constants.js';
4
+ import { isHash } from '../../syntax/syntax.js';
5
5
  import { getParsedSyntax, getSyntaxRule, getSyntaxConfig } from '../../validation/config.js';
6
6
  import { matchAllSyntaxes, createValidationContext, trimArray, matchSelectorSyntax } from '../../validation/match.js';
7
7
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
@@ -22,23 +22,19 @@ function parseSelector(tokens, context, options, errors) {
22
22
  if (filtered.length === 1) {
23
23
  if (filtered[0].typ === EnumToken.IdenTokenType &&
24
24
  "from" === filtered[0].val.toLowerCase()) {
25
- filtered[0] = Object.defineProperty({
25
+ filtered[0] = {
26
26
  typ: EnumToken.PercentageTokenType,
27
27
  val: 0,
28
- }, "loc", {
29
- ...definedPropertySettings,
30
- value: filtered[0].loc,
31
- });
28
+ [LOC]: filtered[0][LOC],
29
+ };
32
30
  }
33
31
  else if (filtered[0].typ === EnumToken.PercentageTokenType &&
34
32
  100 === filtered[0].val) {
35
- filtered[0] = Object.defineProperty({
33
+ filtered[0] = {
36
34
  typ: EnumToken.IdenTokenType,
37
35
  val: "to",
38
- }, "loc", {
39
- ...definedPropertySettings,
40
- value: filtered[0].loc,
41
- });
36
+ [LOC]: filtered[0][LOC],
37
+ };
42
38
  }
43
39
  part.splice(0, part.length, ...filtered);
44
40
  }
@@ -51,7 +47,7 @@ function parseSelector(tokens, context, options, errors) {
51
47
  acc.push(...curr);
52
48
  return acc;
53
49
  }, []));
54
- return Object.defineProperties({
50
+ return {
55
51
  typ: EnumToken.KeyFramesRuleNodeType,
56
52
  sel: [
57
53
  ...splitTokenList(trimArray(tokens)).reduce((acc, curr) => {
@@ -60,24 +56,14 @@ function parseSelector(tokens, context, options, errors) {
60
56
  }, new Set()),
61
57
  ].join(),
62
58
  chi: [],
63
- }, {
64
- state: {
65
- ...definedPropertySettings,
66
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
67
- },
68
- errors: {
69
- ...definedPropertySettings,
70
- value: result.errors,
59
+ [LOC]: {
60
+ ...tokens[0][LOC],
61
+ end: { ...(tokens[tokens.length - 1]?.[LOC]?.end ?? tokens[0]?.[LOC]?.end) },
71
62
  },
72
- tokens: { ...definedPropertySettings, value: tokens.length === 0 ? null : tokens },
73
- loc: {
74
- ...definedPropertySettings,
75
- value: {
76
- ...tokens[0].loc,
77
- end: { ...(tokens[tokens.length - 1]?.loc?.end ?? tokens[0]?.loc?.end) },
78
- },
79
- },
80
- });
63
+ [TOKENS]: tokens.length === 0 ? null : tokens,
64
+ [STATE]: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
65
+ [ERRORS]: result.errors,
66
+ };
81
67
  }
82
68
  const stack = [];
83
69
  const uniq = new Map();
@@ -110,11 +96,11 @@ function parseSelector(tokens, context, options, errors) {
110
96
  }
111
97
  do {
112
98
  if (parent?.typ === EnumToken.AtRuleNodeType && "media" === parent.nam) {
113
- parent = parent.parent;
99
+ parent = parent[PARENT];
114
100
  continue;
115
101
  }
116
102
  nested = parent?.typ == EnumToken.RuleNodeType;
117
- parent = parent?.parent;
103
+ parent = parent?.[PARENT];
118
104
  } while (!nested && parent != null);
119
105
  for (; i < tokens.length; i++) {
120
106
  if (tokens[i].typ == EnumToken.ColonTokenType) {
@@ -123,7 +109,7 @@ function parseSelector(tokens, context, options, errors) {
123
109
  typ: EnumToken.PseudoElementTokenType,
124
110
  val: ":" + tokens[i + 1].val,
125
111
  });
126
- tokens[i].loc.end = tokens[i + 1].loc.end;
112
+ tokens[i][LOC].end = tokens[i + 1][LOC].end;
127
113
  tokens.splice(i + 1, 1);
128
114
  continue;
129
115
  }
@@ -135,7 +121,7 @@ function parseSelector(tokens, context, options, errors) {
135
121
  : tokens[i + 1].typ,
136
122
  val,
137
123
  });
138
- tokens[i].loc.end = tokens[i + 1].loc.end;
124
+ tokens[i][LOC].end = tokens[i + 1][LOC].end;
139
125
  tokens.splice(i + 1, 1);
140
126
  continue;
141
127
  }
@@ -147,7 +133,7 @@ function parseSelector(tokens, context, options, errors) {
147
133
  typ: EnumToken.PseudoClassTokenType,
148
134
  val: (pseudoElements.includes(val) ? "" : ":") + val,
149
135
  });
150
- tokens[i].loc.end = tokens[i + 1].loc.end;
136
+ tokens[i][LOC].end = tokens[i + 1][LOC].end;
151
137
  tokens.splice(i + 1, 1);
152
138
  continue;
153
139
  }
@@ -159,18 +145,18 @@ function parseSelector(tokens, context, options, errors) {
159
145
  : EnumToken.FunctionTokenDefType,
160
146
  val,
161
147
  });
162
- tokens[i].loc.end = tokens[i + 1].loc.end;
148
+ tokens[i][LOC].end = tokens[i + 1][LOC].end;
163
149
  tokens.splice(i + 1, 1);
164
150
  continue;
165
151
  }
166
152
  }
167
153
  if (tokens[i].typ == EnumToken.ColorTokenType) {
168
- if (isIdent(tokens[i].val)) {
169
- Object.assign(tokens[i], {
170
- typ: EnumToken.IdenTokenType,
171
- });
172
- }
173
- else if (isHash(tokens[i].val)) {
154
+ // if (isIdent((tokens[i] as ColorToken).val)) {
155
+ // Object.assign(tokens[i], {
156
+ // typ: EnumToken.IdenTokenType,
157
+ // });
158
+ // } else
159
+ if (isHash(tokens[i].val)) {
174
160
  Object.assign(tokens[i], {
175
161
  typ: EnumToken.HashTokenType,
176
162
  });
@@ -191,13 +177,10 @@ function parseSelector(tokens, context, options, errors) {
191
177
  index = tokens.indexOf(stack.at(-1));
192
178
  // @ts-expect-error
193
179
  const { val, ...attr } = stack.at(-1);
194
- Object.defineProperty(attr, "loc", {
195
- ...definedPropertySettings,
196
- value: {
197
- ...stack.at(-1).loc,
198
- end: token.loc.end,
199
- },
200
- });
180
+ attr[LOC] = {
181
+ ...stack.at(-1)[LOC],
182
+ end: token[LOC].end,
183
+ };
201
184
  tokens.splice(i, 1);
202
185
  Object.assign(attr, {
203
186
  typ: EnumToken.AttrTokenType,
@@ -215,7 +198,7 @@ function parseSelector(tokens, context, options, errors) {
215
198
  if (stack.at(-1)?.typ == EnumToken.PseudoClassFunctionTokenDefType) {
216
199
  const func = stack.at(-1);
217
200
  index = tokens.indexOf(func);
218
- stack.at(-1).loc.end = token.loc.end;
201
+ stack.at(-1)[LOC].end = token[LOC].end;
219
202
  tokens.splice(i, 1);
220
203
  if (tokensfuncDefMap.has(func.typ)) {
221
204
  // @ts-expect-error
@@ -242,88 +225,84 @@ function parseSelector(tokens, context, options, errors) {
242
225
  }
243
226
  }
244
227
  else {
245
- if (!/\d+$/.test(token.val)) {
246
- let index = func.chi.indexOf(token);
247
- let i = index + 1;
248
- let sign = null;
249
- let num = null;
250
- for (; i < func.chi.length; i++) {
251
- if (func.chi[i].typ == EnumToken.WhitespaceTokenType ||
252
- func.chi[i].typ == EnumToken.CommentTokenType) {
253
- continue;
254
- }
255
- if (func.chi[i].typ == EnumToken.NumberTokenType) {
256
- num = func.chi[i];
257
- break;
258
- }
259
- else {
260
- sign = func.chi[i];
261
- }
262
- }
263
- if (num != null) {
264
- if (num.val === 0) {
265
- func.chi.splice(index + 1, i - index);
266
- if (token.val == "-n") {
267
- token.val = "n";
268
- }
269
- break;
270
- }
271
- if (sign == null) {
272
- func.chi.splice(index + 1, i - index - 1);
273
- if (Math.sign(num.val) === 1) {
274
- func.chi.splice(index + 1, 0, {
275
- typ: EnumToken.LiteralTokenType,
276
- val: "+",
277
- });
278
- }
279
- }
280
- }
281
- else if (token.val == "-n") {
282
- token.val = "n";
283
- }
284
- break;
285
- }
228
+ // if (!/\d+$/.test((token as IdentToken | LiteralToken).val)) {
229
+ // let index = func.chi.indexOf(token);
230
+ // let i: number = index + 1;
231
+ // let sign: Token | null = null;
232
+ // let num: NumberToken | null = null;
233
+ // for (; i < func.chi.length; i++) {
234
+ // if (
235
+ // func.chi[i].typ == EnumToken.WhitespaceTokenType ||
236
+ // func.chi[i].typ == EnumToken.CommentTokenType
237
+ // ) {
238
+ // continue;
239
+ // }
240
+ // if (func.chi[i].typ == EnumToken.NumberTokenType) {
241
+ // num = func.chi[i] as NumberToken;
242
+ // break;
243
+ // } else {
244
+ // sign = func.chi[i] as Token;
245
+ // }
246
+ // }
247
+ // if (num != null) {
248
+ // if (num.val === 0) {
249
+ // func.chi.splice(index + 1, i - index);
250
+ // if ((token as IdentToken | LiteralToken).val == "-n") {
251
+ // (token as IdentToken).val = "n";
252
+ // }
253
+ // break;
254
+ // }
255
+ // if (sign == null) {
256
+ // func.chi.splice(index + 1, i - index - 1);
257
+ // if (Math.sign(num.val as number) === 1) {
258
+ // func.chi.splice(index + 1, 0, {
259
+ // typ: EnumToken.LiteralTokenType,
260
+ // val: "+",
261
+ // });
262
+ // }
263
+ // }
264
+ // } else if ((token as IdentToken | LiteralToken).val == "-n") {
265
+ // (token as IdentToken).val = "n";
266
+ // }
267
+ // break;
268
+ // }
286
269
  const matches = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(token.val);
287
270
  if (matches != null) {
288
271
  const a1 = matches[2] === "" ? 1 : matches[2] === "-" ? -1 : +matches[2];
289
272
  const b1 = +matches[3];
290
- if (a1 === 0) {
291
- if (b1 === 1) {
292
- let hasSelector = false;
293
- let i = func.chi.indexOf(token);
294
- let j = i + 1;
295
- for (; j < func.chi.length; j++) {
296
- if (func.chi[j].typ == EnumToken.IdenTokenType &&
297
- func.chi[j].val == "of") {
298
- hasSelector = true;
299
- break;
300
- }
301
- }
302
- if (hasSelector) {
303
- Object.assign(token, {
304
- typ: EnumToken.NumberTokenType,
305
- val: b1,
306
- });
307
- }
308
- else {
309
- // :first-child
310
- tokens[tokens.indexOf(func)] = Object.defineProperties({
311
- typ: EnumToken.PseudoClassTokenType,
312
- val: ":first-child",
313
- }, {
314
- loc: {
315
- ...definedPropertySettings,
316
- value: func.loc,
317
- },
318
- });
319
- }
320
- break;
321
- }
322
- else {
323
- Object.assign(token, { typ: EnumToken.NumberTokenType, val: b1 });
324
- }
325
- }
326
- else if (b1 === 0) {
273
+ // if (a1 === 0) {
274
+ // if (b1 === 1) {
275
+ // let hasSelector: boolean = false;
276
+ // let i: number = func.chi.indexOf(token);
277
+ // let j: number = i + 1;
278
+ // for (; j < func.chi.length; j++) {
279
+ // if (
280
+ // func.chi[j].typ == EnumToken.IdenTokenType &&
281
+ // (func.chi[j] as IdentToken).val == "of"
282
+ // ) {
283
+ // hasSelector = true;
284
+ // break;
285
+ // }
286
+ // }
287
+ // if (hasSelector) {
288
+ // Object.assign(token, {
289
+ // typ: EnumToken.NumberTokenType,
290
+ // val: b1,
291
+ // });
292
+ // } else {
293
+ // // :first-child
294
+ // tokens[tokens.indexOf(func)] = {
295
+ // typ: EnumToken.PseudoClassTokenType,
296
+ // val: ":first-child",
297
+ // [LOC]: func[LOC],
298
+ // };
299
+ // }
300
+ // break;
301
+ // } else {
302
+ // Object.assign(token, { typ: EnumToken.NumberTokenType, val: b1 });
303
+ // }
304
+ // } else
305
+ if (b1 === 0) {
327
306
  Object.assign(token, Math.abs(a1) === 1
328
307
  ? {
329
308
  typ: EnumToken.IdenTokenType,
@@ -335,24 +314,22 @@ function parseSelector(tokens, context, options, errors) {
335
314
  unit: "n",
336
315
  });
337
316
  }
338
- else if (Math.abs(a1) === 2) {
339
- if (b1 === 0) {
340
- Object.assign(token, {
341
- typ: EnumToken.DimensionTokenType,
342
- val: a1,
343
- unit: "n",
344
- });
345
- }
346
- else if (Math.abs(b1) === 1) {
347
- Object.assign(token, { typ: EnumToken.IdenTokenType, val: "odd" });
348
- }
349
- }
317
+ // else if (Math.abs(a1) === 2) {
318
+ // if (b1 === 0) {
319
+ // Object.assign(token, {
320
+ // typ: EnumToken.DimensionTokenType,
321
+ // val: a1,
322
+ // unit: "n",
323
+ // });
324
+ // } else if (Math.abs(b1) === 1) {
325
+ // Object.assign(token, { typ: EnumToken.IdenTokenType, val: "odd" });
326
+ // }
327
+ // }
350
328
  }
351
329
  }
352
330
  }
353
331
  else if (token?.typ === EnumToken.DimensionTokenType) {
354
332
  const index = func.chi.indexOf(token);
355
- let sign = null;
356
333
  let num = null;
357
334
  let i = index + 1;
358
335
  for (; i < func.chi.length; i++) {
@@ -364,47 +341,39 @@ function parseSelector(tokens, context, options, errors) {
364
341
  num = func.chi[i];
365
342
  break;
366
343
  }
367
- else {
368
- sign = func.chi[i];
369
- }
370
344
  }
371
345
  if (num != null) {
372
- if (token.val === 0) {
373
- if (num.val === 0) {
374
- func.chi.splice(0, i);
375
- }
376
- else if (num.val === 1) {
377
- let hasSelector = false;
378
- let j = i + 1;
379
- for (; j < func.chi.length; j++) {
380
- if (func.chi[j].typ == EnumToken.IdenTokenType &&
381
- func.chi[j].val == "of") {
382
- hasSelector = true;
383
- break;
384
- }
385
- }
386
- if (hasSelector) {
387
- func.chi.splice(0, i);
388
- }
389
- else {
390
- tokens[tokens.indexOf(func)] = Object.defineProperties({
391
- typ: EnumToken.PseudoClassTokenType,
392
- val: ":first-child",
393
- }, {
394
- loc: {
395
- ...definedPropertySettings,
396
- value: func.loc,
397
- },
398
- });
399
- }
400
- break;
401
- }
402
- else {
403
- func.chi.splice(0, i);
404
- }
405
- break;
406
- }
407
- else if (num.val === 0) {
346
+ // if ((token as DimensionToken).val === 0) {
347
+ // if (num.val === 0) {
348
+ // func.chi.splice(0, i);
349
+ // } else if (num.val === 1) {
350
+ // let hasSelector: boolean = false;
351
+ // let j: number = i + 1;
352
+ // for (; j < func.chi.length; j++) {
353
+ // if (
354
+ // func.chi[j].typ == EnumToken.IdenTokenType &&
355
+ // (func.chi[j] as IdentToken).val == "of"
356
+ // ) {
357
+ // hasSelector = true;
358
+ // break;
359
+ // }
360
+ // }
361
+ // if (hasSelector) {
362
+ // func.chi.splice(0, i);
363
+ // } else {
364
+ // tokens[tokens.indexOf(func)] = {
365
+ // typ: EnumToken.PseudoClassTokenType,
366
+ // val: ":first-child",
367
+ // [LOC]: func[LOC],
368
+ // };
369
+ // }
370
+ // break;
371
+ // } else {
372
+ // func.chi.splice(0, i);
373
+ // }
374
+ // break;
375
+ // } else
376
+ if (num.val === 0) {
408
377
  func.chi.splice(index + 1, i - index);
409
378
  if (token.val < 0) {
410
379
  token.val *= -1;
@@ -420,23 +389,24 @@ function parseSelector(tokens, context, options, errors) {
420
389
  func.chi.splice(index + 1, i - index);
421
390
  break;
422
391
  }
423
- if (token.val === 1) {
424
- Object.assign(token, {
425
- typ: EnumToken.IdenTokenType,
426
- val: Math.sign(token.val) === 1
427
- ? "n"
428
- : "-n",
429
- });
430
- }
431
- if (sign == null) {
432
- func.chi.splice(index + 1, i - index - 1);
433
- if (Math.sign(num.val) === 1) {
434
- func.chi.splice(index + 1, 0, {
435
- typ: EnumToken.LiteralTokenType,
436
- val: "+",
437
- });
438
- }
439
- }
392
+ // if (((token as DimensionToken).val as number) === 1) {
393
+ // Object.assign(token, {
394
+ // typ: EnumToken.IdenTokenType,
395
+ // val:
396
+ // Math.sign((token as DimensionToken).val as number) === 1
397
+ // ? "n"
398
+ // : "-n",
399
+ // });
400
+ // }
401
+ // if (sign == null) {
402
+ // func.chi.splice(index + 1, i - index - 1);
403
+ // if (Math.sign(num.val as number) === 1) {
404
+ // func.chi.splice(index + 1, 0, {
405
+ // typ: EnumToken.LiteralTokenType,
406
+ // val: "+",
407
+ // });
408
+ // }
409
+ // }
440
410
  }
441
411
  }
442
412
  }
@@ -448,14 +418,14 @@ function parseSelector(tokens, context, options, errors) {
448
418
  }
449
419
  }
450
420
  }
451
- return Object.defineProperties({
421
+ return {
452
422
  typ: EnumToken.RuleNodeType,
453
423
  sel: [
454
424
  ...tokens
455
425
  .reduce((acc, curr, index, array) => {
456
- if (curr.typ == EnumToken.CommentTokenType) {
457
- return acc;
458
- }
426
+ // if (curr.typ == EnumToken.CommentTokenType) {
427
+ // return acc;
428
+ // }
459
429
  if (curr.typ == EnumToken.WhitespaceTokenType) {
460
430
  if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
461
431
  trimWhiteSpace.includes(array[index + 1]?.typ) ||
@@ -491,28 +461,18 @@ function parseSelector(tokens, context, options, errors) {
491
461
  .keys(),
492
462
  ].join(","),
493
463
  chi: [],
494
- }, {
495
- state: {
496
- ...definedPropertySettings,
497
- value: result.success && allowed
498
- ? EnumAstNodeStatus.Validated
499
- : allowed
500
- ? EnumAstNodeStatus.Invalid
501
- : EnumAstNodeStatus.Disallowed,
502
- },
503
- errors: {
504
- ...definedPropertySettings,
505
- value: result.success ? [] : result.errors,
506
- },
507
- tokens: { ...definedPropertySettings, value: tokens },
508
- loc: {
509
- ...definedPropertySettings,
510
- value: {
511
- ...tokens[0].loc,
512
- end: tokens[tokens.length - 1].loc.end,
513
- },
464
+ [LOC]: {
465
+ ...tokens[0][LOC],
466
+ end: tokens[tokens.length - 1][LOC].end,
514
467
  },
515
- });
468
+ [TOKENS]: tokens,
469
+ [STATE]: result.success && allowed
470
+ ? EnumAstNodeStatus.Validated
471
+ : allowed
472
+ ? EnumAstNodeStatus.Invalid
473
+ : EnumAstNodeStatus.Disallowed,
474
+ [ERRORS]: result.success ? [] : result.errors,
475
+ };
516
476
  }
517
477
 
518
478
  export { parseSelector };