@tbela99/css-parser 1.5.0 → 1.6.1

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 (78) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +10 -10
  3. package/dist/index-umd-web.js +5998 -4972
  4. package/dist/index.cjs +6001 -4977
  5. package/dist/index.d.ts +52 -38
  6. package/dist/lib/ast/expand.js +21 -7
  7. package/dist/lib/ast/features/calc.js +17 -55
  8. package/dist/lib/ast/features/if.js +7 -3
  9. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  10. package/dist/lib/ast/features/prefix.js +41 -44
  11. package/dist/lib/ast/features/shorthand.js +10 -5
  12. package/dist/lib/ast/features/transform.js +2 -2
  13. package/dist/lib/ast/math/expression.js +207 -34
  14. package/dist/lib/ast/minify.js +121 -24
  15. package/dist/lib/ast/node.js +5 -3
  16. package/dist/lib/ast/transform/compute.js +37 -5
  17. package/dist/lib/ast/transform/minify.js +7 -7
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +1 -1
  20. package/dist/lib/ast/transform/scale.js +1 -1
  21. package/dist/lib/ast/transform/skew.js +1 -1
  22. package/dist/lib/ast/transform/translate.js +1 -1
  23. package/dist/lib/ast/transform/utils.js +46 -18
  24. package/dist/lib/ast/walk.js +28 -4
  25. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  26. package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
  27. package/dist/lib/fs/resolve.js +11 -2
  28. package/dist/lib/parser/declaration/list.js +22 -7
  29. package/dist/lib/parser/declaration/map.js +26 -8
  30. package/dist/lib/parser/declaration/set.js +3 -1
  31. package/dist/lib/parser/linesmap.js +2 -4
  32. package/dist/lib/parser/parse.js +393 -231
  33. package/dist/lib/parser/tokenize.js +1478 -819
  34. package/dist/lib/parser/utils/at-rule-container.js +28 -196
  35. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  36. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  37. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  38. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  39. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  40. package/dist/lib/parser/utils/at-rule.js +0 -18
  41. package/dist/lib/parser/utils/config.js +1 -1
  42. package/dist/lib/parser/utils/declaration.js +40 -97
  43. package/dist/lib/parser/utils/hash.js +4 -4
  44. package/dist/lib/parser/utils/selector.js +179 -224
  45. package/dist/lib/parser/utils/text.js +4 -2
  46. package/dist/lib/renderer/render.js +104 -74
  47. package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
  48. package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
  49. package/dist/lib/syntax/color/a98rgb.js +14 -4
  50. package/dist/lib/syntax/color/cmyk.js +14 -21
  51. package/dist/lib/syntax/color/color-mix.js +21 -34
  52. package/dist/lib/syntax/color/color.js +32 -49
  53. package/dist/lib/syntax/color/hsl.js +15 -15
  54. package/dist/lib/syntax/color/hwb.js +18 -17
  55. package/dist/lib/syntax/color/lab.js +17 -17
  56. package/dist/lib/syntax/color/lch.js +13 -13
  57. package/dist/lib/syntax/color/oklab.js +10 -11
  58. package/dist/lib/syntax/color/oklch.js +15 -18
  59. package/dist/lib/syntax/color/p3.js +18 -12
  60. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  61. package/dist/lib/syntax/color/rec2020.js +8 -4
  62. package/dist/lib/syntax/color/relative-color.js +26 -10
  63. package/dist/lib/syntax/color/srgb.js +9 -7
  64. package/dist/lib/syntax/color/utils/distance.js +1 -1
  65. package/dist/lib/syntax/color/xyz.js +2 -2
  66. package/dist/lib/syntax/color/xyzd50.js +2 -2
  67. package/dist/lib/syntax/constants.js +13 -3
  68. package/dist/lib/syntax/syntax.js +32 -108
  69. package/dist/lib/validation/config.js +1 -1
  70. package/dist/lib/validation/match.js +29 -26
  71. package/dist/lib/validation/parser/parse.js +7 -3
  72. package/dist/node.js +16 -9
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.js +22 -1
  76. package/dist/web.js +13 -4
  77. package/package.json +4 -4
  78. package/llms.txt +0 -80
@@ -1,6 +1,6 @@
1
1
  import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
2
2
  import { renderValue } from '../../renderer/render.js';
3
- import { LOC, ERRORS, STATE, TOKENS, pseudoElements, combinators, tokensfuncDefMap, PARENT } from '../../syntax/constants.js';
3
+ import { LOCEND, LOCSTA, LOCSRCID, ERRORS, STATE, TOKENS, pseudoElements, combinators, tokensfuncDefMap, PARENT } from '../../syntax/constants.js';
4
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';
@@ -26,7 +26,9 @@ function parseSelector(tokens, context, options, errors) {
26
26
  filtered[0] = {
27
27
  typ: EnumToken.PercentageTokenType,
28
28
  val: 0,
29
- [LOC]: filtered[0][LOC],
29
+ [LOCSRCID]: filtered[0][LOCSRCID],
30
+ [LOCSTA]: filtered[0][LOCSTA],
31
+ [LOCEND]: filtered[0][LOCEND],
30
32
  };
31
33
  }
32
34
  else if (filtered[0].typ === EnumToken.PercentageTokenType &&
@@ -34,7 +36,9 @@ function parseSelector(tokens, context, options, errors) {
34
36
  filtered[0] = {
35
37
  typ: EnumToken.IdenTokenType,
36
38
  val: "to",
37
- [LOC]: filtered[0][LOC],
39
+ [LOCSRCID]: filtered[0][LOCSRCID],
40
+ [LOCSTA]: filtered[0][LOCSTA],
41
+ [LOCEND]: filtered[0][LOCEND],
38
42
  };
39
43
  }
40
44
  part.splice(0, part.length, ...filtered);
@@ -45,7 +49,9 @@ function parseSelector(tokens, context, options, errors) {
45
49
  if (acc.length > 0) {
46
50
  acc.push({ typ: EnumToken.CommaTokenType });
47
51
  }
48
- acc.push(...curr);
52
+ for (const c of curr) {
53
+ acc.push(c);
54
+ }
49
55
  return acc;
50
56
  }, []));
51
57
  return {
@@ -57,10 +63,9 @@ function parseSelector(tokens, context, options, errors) {
57
63
  }, new Set()),
58
64
  ].join(),
59
65
  chi: [],
60
- [LOC]: {
61
- ...tokens[0][LOC],
62
- end: tokens[tokens.length - 1]?.[LOC]?.end ?? tokens[0]?.[LOC]?.end,
63
- },
66
+ [LOCSRCID]: tokens[0]?.[LOCSRCID],
67
+ [LOCSTA]: tokens[0]?.[LOCSTA],
68
+ [LOCEND]: tokens[tokens.length - 1]?.[LOCEND],
64
69
  [TOKENS]: tokens.length === 0 ? null : tokens,
65
70
  [STATE]: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
66
71
  [ERRORS]: result.errors,
@@ -69,7 +74,6 @@ function parseSelector(tokens, context, options, errors) {
69
74
  const stack = [];
70
75
  const uniq = new Map();
71
76
  let allowed = true;
72
- let i = 0;
73
77
  let index;
74
78
  let parent = context;
75
79
  let nested = false;
@@ -103,120 +107,130 @@ function parseSelector(tokens, context, options, errors) {
103
107
  nested = parent?.typ == EnumToken.RuleNodeType;
104
108
  parent = parent?.[PARENT];
105
109
  } while (!nested && parent != null);
106
- for (; i < tokens.length; i++) {
107
- if (tokens[i].typ == EnumToken.ColonTokenType) {
108
- if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) {
109
- Object.assign(tokens[i], {
110
+ const all = new Array(tokens.length);
111
+ let write = 0;
112
+ for (let read = 0; read < tokens.length; read++) {
113
+ let token = tokens[read];
114
+ if (token.typ == EnumToken.ColonTokenType) {
115
+ const next = tokens[read + 1];
116
+ if (next?.typ == EnumToken.IdenTokenType) {
117
+ all[write++] = {
118
+ ...token,
110
119
  typ: EnumToken.PseudoElementTokenType,
111
- val: ":" + tokens[i + 1].val,
112
- });
113
- tokens[i][LOC].end = tokens[i + 1][LOC].end;
114
- tokens.splice(i + 1, 1);
120
+ val: ":" + next.val,
121
+ [LOCEND]: next[LOCEND],
122
+ };
123
+ read++;
115
124
  continue;
116
125
  }
117
- if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
118
- val = ":" + tokens[i + 1].val;
119
- Object.assign(tokens[i], {
126
+ if (next?.typ == EnumToken.FunctionTokenDefType) {
127
+ val = ":" + next.val;
128
+ all[write++] = {
129
+ ...token,
120
130
  typ: val + "()" in getSyntaxConfig().selectors
121
131
  ? EnumToken.PseudoClassFunctionTokenDefType
122
- : tokens[i + 1].typ,
132
+ : next.typ,
123
133
  val,
124
- });
125
- tokens[i][LOC].end = tokens[i + 1][LOC].end;
126
- tokens.splice(i + 1, 1);
134
+ [LOCEND]: next[LOCEND],
135
+ };
136
+ read++;
127
137
  continue;
128
138
  }
129
139
  }
130
- if (tokens[i].typ == EnumToken.DoubleColonTokenType) {
131
- val = ":" + tokens[i + 1].val;
132
- if (tokens[i + 1]?.typ == EnumToken.IdenTokenType) {
133
- Object.assign(tokens[i], {
140
+ if (token.typ == EnumToken.DoubleColonTokenType) {
141
+ const next = tokens[read + 1];
142
+ val = ":" + next.val;
143
+ if (next?.typ == EnumToken.IdenTokenType) {
144
+ all[write++] = {
145
+ ...token,
134
146
  typ: EnumToken.PseudoClassTokenType,
135
147
  val: (pseudoElements.includes(val) ? "" : ":") + val,
136
- });
137
- tokens[i][LOC].end = tokens[i + 1][LOC].end;
138
- tokens.splice(i + 1, 1);
148
+ [LOCEND]: next[LOCEND],
149
+ };
150
+ read++;
139
151
  continue;
140
152
  }
141
- if (tokens[i + 1]?.typ == EnumToken.FunctionTokenDefType) {
142
- val = "::" + tokens[i + 1].val;
143
- Object.assign(tokens[i], {
153
+ if (next?.typ == EnumToken.FunctionTokenDefType) {
154
+ val = "::" + next.val;
155
+ all[write++] = {
156
+ ...token,
144
157
  typ: val + "()" in getSyntaxConfig().selectors
145
158
  ? EnumToken.PseudoClassFunctionTokenDefType
146
159
  : EnumToken.FunctionTokenDefType,
147
160
  val,
148
- });
149
- tokens[i][LOC].end = tokens[i + 1][LOC].end;
150
- tokens.splice(i + 1, 1);
161
+ [LOCEND]: next[LOCEND],
162
+ };
163
+ read++;
151
164
  continue;
152
165
  }
153
166
  }
154
- if (tokens[i].typ == EnumToken.ColorTokenType) {
155
- if (isHash(tokens[i].val)) {
156
- Object.assign(tokens[i], {
157
- typ: EnumToken.HashTokenType,
158
- });
167
+ if (token.typ == EnumToken.ColorTokenType) {
168
+ if (isHash(token.val)) {
169
+ token.typ = EnumToken.HashTokenType;
170
+ all[write++] = token;
171
+ continue;
159
172
  }
160
- else {
161
- return {
162
- typ: EnumToken.RuleNodeType,
163
- sel: [
164
- ...tokens
165
- .reduce((acc, curr, index, array) => {
166
- // if (curr.typ == EnumToken.CommentTokenType) {
167
- // return acc;
168
- // }
169
- if (curr.typ == EnumToken.WhitespaceTokenType) {
170
- if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
171
- trimWhiteSpace.includes(array[index + 1]?.typ) ||
172
- combinators.includes(array[index - 1]?.val) ||
173
- combinators.includes(array[index + 1]?.val)) {
174
- return acc;
175
- }
176
- }
177
- let t = renderValue(curr, { minify: false });
178
- if (t == ",") {
179
- acc.push([]);
180
- }
181
- else {
182
- acc[acc.length - 1].push(t);
173
+ return {
174
+ typ: EnumToken.RuleNodeType,
175
+ sel: [
176
+ ...tokens
177
+ .reduce((acc, curr, index, array) => {
178
+ if (curr.typ == EnumToken.WhitespaceTokenType) {
179
+ if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
180
+ trimWhiteSpace.includes(array[index + 1]?.typ) ||
181
+ combinators.includes(array[index - 1]?.val) ||
182
+ combinators.includes(array[index + 1]?.val)) {
183
+ return acc;
183
184
  }
184
- return acc;
185
- }, [[]])
186
- .reduce((acc, curr) => {
187
- let i = 0;
188
- for (; i < curr.length; i++) {
189
- if (i + 1 < curr.length && curr[i] == "*") {
190
- if (curr[i] == "*") {
191
- let index = curr[i + 1] == " " ? 2 : 1;
192
- if (![">", "~", "+"].includes(curr[index])) {
193
- curr.splice(i, index);
194
- }
185
+ }
186
+ let t = renderValue(curr, { minify: false });
187
+ if (t == ",") {
188
+ acc.push([]);
189
+ }
190
+ else {
191
+ acc[acc.length - 1].push(t);
192
+ }
193
+ return acc;
194
+ }, [[]])
195
+ .reduce((acc, curr) => {
196
+ let i = 0;
197
+ for (; i < curr.length; i++) {
198
+ if (i + 1 < curr.length && curr[i] == "*") {
199
+ if (curr[i] == "*") {
200
+ let index = curr[i + 1] == " " ? 2 : 1;
201
+ if (![">", "~", "+"].includes(curr[index])) {
202
+ curr.splice(i, index);
195
203
  }
196
204
  }
197
205
  }
198
- acc.set(curr.join(""), curr);
199
- return acc;
200
- }, uniq)
201
- .keys(),
202
- ].join(","),
203
- chi: [],
204
- [LOC]: {
205
- ...tokens[0][LOC],
206
- end: tokens[tokens.length - 1][LOC].end,
206
+ }
207
+ acc.set(curr.join(""), curr);
208
+ return acc;
209
+ }, uniq)
210
+ .keys(),
211
+ ].join(","),
212
+ chi: [],
213
+ [LOCSRCID]: tokens[0][LOCSRCID],
214
+ [LOCSTA]: tokens[0][LOCSTA],
215
+ [LOCEND]: tokens[tokens.length - 1][LOCEND],
216
+ [TOKENS]: tokens,
217
+ [STATE]: EnumAstNodeStatus.Invalid,
218
+ [ERRORS]: [
219
+ {
220
+ action: "drop",
221
+ node: token,
222
+ message: "invalid hash id",
207
223
  },
208
- [TOKENS]: tokens,
209
- [STATE]: EnumAstNodeStatus.Invalid,
210
- [ERRORS]: [
211
- {
212
- action: "drop",
213
- node: tokens[i],
214
- message: "invalid hash id",
215
- },
216
- ],
217
- };
218
- }
224
+ ],
225
+ };
219
226
  }
227
+ all[write++] = token;
228
+ }
229
+ if (write !== tokens.length) {
230
+ for (let index = 0; index < write; index++) {
231
+ tokens[index] = all[index];
232
+ }
233
+ tokens.length = write;
220
234
  }
221
235
  const result = matchSelectorSyntax(tokens, errors, options, nested === true);
222
236
  trimArray(tokens);
@@ -232,10 +246,9 @@ function parseSelector(tokens, context, options, errors) {
232
246
  index = tokens.indexOf(stack.at(-1));
233
247
  // @ts-expect-error
234
248
  const { val, ...attr } = stack.at(-1);
235
- attr[LOC] = {
236
- ...stack.at(-1)[LOC],
237
- end: token[LOC].end,
238
- };
249
+ attr[LOCSRCID] = stack.at(-1)[LOCSRCID];
250
+ attr[LOCSTA] = stack.at(-1)[LOCSTA];
251
+ attr[LOCEND] = token[LOCEND];
239
252
  tokens.splice(i, 1);
240
253
  Object.assign(attr, {
241
254
  typ: EnumToken.AttrTokenType,
@@ -253,7 +266,7 @@ function parseSelector(tokens, context, options, errors) {
253
266
  if (stack.at(-1)?.typ == EnumToken.PseudoClassFunctionTokenDefType) {
254
267
  const func = stack.at(-1);
255
268
  index = tokens.indexOf(func);
256
- stack.at(-1)[LOC].end = token[LOC].end;
269
+ stack.at(-1)[LOCEND] = token[LOCEND];
257
270
  tokens.splice(i, 1);
258
271
  if (tokensfuncDefMap.has(func.typ)) {
259
272
  // @ts-expect-error
@@ -270,20 +283,77 @@ function parseSelector(tokens, context, options, errors) {
270
283
  const list = [];
271
284
  let index;
272
285
  for (index = 0; index < func.chi.length; index++) {
273
- if (func.chi[index].typ == EnumToken.CommentTokenType || func.chi[index].typ == EnumToken.WhitespaceTokenType) {
286
+ if (func.chi[index].typ == EnumToken.CommentTokenType ||
287
+ func.chi[index].typ == EnumToken.WhitespaceTokenType) {
274
288
  continue;
275
289
  }
276
- if (func.chi[index].typ == EnumToken.IdenTokenType && equalsIgnoreCase('of', func.chi[index].val)) {
290
+ if (func.chi[index].typ == EnumToken.IdenTokenType &&
291
+ equalsIgnoreCase("of", func.chi[index].val)) {
277
292
  index--;
278
293
  break;
279
294
  }
280
295
  list.push(func.chi[index]);
281
296
  }
297
+ if (list.length == 2) {
298
+ if (list[1].typ == EnumToken.NumberTokenType) {
299
+ if (list[1].val == 0) {
300
+ list.length = 1;
301
+ if (list[0].typ == EnumToken.DimensionTokenType &&
302
+ list[0].val == -2) {
303
+ list[0].val = 2;
304
+ }
305
+ }
306
+ else {
307
+ const sign = Math.sign(list[1].val);
308
+ // @ts-ignore
309
+ list[1].val *= sign;
310
+ list.splice(1, 0, {
311
+ typ: EnumToken.LiteralTokenType,
312
+ val: sign > 0 ? "+" : "-",
313
+ });
314
+ }
315
+ }
316
+ if (list.length == 3 &&
317
+ list[2].typ == EnumToken.NumberTokenType &&
318
+ list[0].typ == EnumToken.DimensionTokenType &&
319
+ (list[0].val == 2 ||
320
+ list[0].val == -2)) {
321
+ if (1 == list[2].val) {
322
+ list.splice(0, 3, {
323
+ typ: EnumToken.IdenTokenType,
324
+ val: "odd",
325
+ [LOCSRCID]: list[0][LOCSRCID],
326
+ [LOCSTA]: list[0][LOCSTA],
327
+ [LOCEND]: list[0][LOCEND],
328
+ });
329
+ }
330
+ else if (0 == list[2].val) {
331
+ list.splice(0, 3, {
332
+ typ: EnumToken.IdenTokenType,
333
+ val: "even",
334
+ [LOCSRCID]: list[0][LOCSRCID],
335
+ [LOCSTA]: list[0][LOCSTA],
336
+ [LOCEND]: list[0][LOCEND],
337
+ });
338
+ }
339
+ }
340
+ func.chi.splice(0, index, ...list);
341
+ }
342
+ if (list.length == 1) {
343
+ if (list[0].typ == EnumToken.IdenTokenType &&
344
+ equalsIgnoreCase("-n", list[0].val)) {
345
+ list[0].val = "n";
346
+ }
347
+ }
282
348
  if (list.length == 3) {
283
- if (list[0].typ == EnumToken.IdenTokenType && ('n' == list[0].val || '-n' == list[0].val || '+n' == list[0].val)) {
349
+ if (list[0].typ == EnumToken.IdenTokenType &&
350
+ ("n" == list[0].val ||
351
+ "-n" == list[0].val ||
352
+ "+n" == list[0].val)) {
284
353
  if (list[1].typ == EnumToken.NextSiblingCombinatorTokenType) {
285
- if (list[2].typ == EnumToken.NumberTokenType && (0 == list[2].val)) {
286
- list[0].val = 'n';
354
+ if (list[2].typ == EnumToken.NumberTokenType &&
355
+ 0 == list[2].val) {
356
+ list[0].val = "n";
287
357
  func.chi.splice(0, index, list[0]);
288
358
  break;
289
359
  }
@@ -303,83 +373,10 @@ function parseSelector(tokens, context, options, errors) {
303
373
  }
304
374
  }
305
375
  else {
306
- // if (!/\d+$/.test((token as IdentToken | LiteralToken).val)) {
307
- // let index = func.chi.indexOf(token);
308
- // let i: number = index + 1;
309
- // let sign: Token | null = null;
310
- // let num: NumberToken | null = null;
311
- // for (; i < func.chi.length; i++) {
312
- // if (
313
- // func.chi[i].typ == EnumToken.WhitespaceTokenType ||
314
- // func.chi[i].typ == EnumToken.CommentTokenType
315
- // ) {
316
- // continue;
317
- // }
318
- // if (func.chi[i].typ == EnumToken.NumberTokenType) {
319
- // num = func.chi[i] as NumberToken;
320
- // break;
321
- // } else {
322
- // sign = func.chi[i] as Token;
323
- // }
324
- // }
325
- // if (num != null) {
326
- // if (num.val === 0) {
327
- // func.chi.splice(index + 1, i - index);
328
- // if ((token as IdentToken | LiteralToken).val == "-n") {
329
- // (token as IdentToken).val = "n";
330
- // }
331
- // break;
332
- // }
333
- // if (sign == null) {
334
- // func.chi.splice(index + 1, i - index - 1);
335
- // if (Math.sign(num.val as number) === 1) {
336
- // func.chi.splice(index + 1, 0, {
337
- // typ: EnumToken.LiteralTokenType,
338
- // val: "+",
339
- // });
340
- // }
341
- // }
342
- // } else if ((token as IdentToken | LiteralToken).val == "-n") {
343
- // (token as IdentToken).val = "n";
344
- // }
345
- // break;
346
- // }
347
376
  const matches = /^(([+-]?[0-9]*)?n)?([+-]?[0-9]+)?$/.exec(token.val);
348
377
  if (matches != null) {
349
378
  const a1 = matches[2] === "" ? 1 : matches[2] === "-" ? -1 : +matches[2];
350
379
  const b1 = +matches[3];
351
- // if (a1 === 0) {
352
- // if (b1 === 1) {
353
- // let hasSelector: boolean = false;
354
- // let i: number = func.chi.indexOf(token);
355
- // let j: number = i + 1;
356
- // for (; j < func.chi.length; j++) {
357
- // if (
358
- // func.chi[j].typ == EnumToken.IdenTokenType &&
359
- // (func.chi[j] as IdentToken).val == "of"
360
- // ) {
361
- // hasSelector = true;
362
- // break;
363
- // }
364
- // }
365
- // if (hasSelector) {
366
- // Object.assign(token, {
367
- // typ: EnumToken.NumberTokenType,
368
- // val: b1,
369
- // });
370
- // } else {
371
- // // :first-child
372
- // tokens[tokens.indexOf(func)] = {
373
- // typ: EnumToken.PseudoClassTokenType,
374
- // val: ":first-child",
375
- // [LOC]: func[LOC],
376
- // };
377
- // }
378
- // break;
379
- // } else {
380
- // Object.assign(token, { typ: EnumToken.NumberTokenType, val: b1 });
381
- // }
382
- // } else
383
380
  if (b1 === 0) {
384
381
  Object.assign(token, Math.abs(a1) === 1
385
382
  ? {
@@ -392,17 +389,6 @@ function parseSelector(tokens, context, options, errors) {
392
389
  unit: "n",
393
390
  });
394
391
  }
395
- // else if (Math.abs(a1) === 2) {
396
- // if (b1 === 0) {
397
- // Object.assign(token, {
398
- // typ: EnumToken.DimensionTokenType,
399
- // val: a1,
400
- // unit: "n",
401
- // });
402
- // } else if (Math.abs(b1) === 1) {
403
- // Object.assign(token, { typ: EnumToken.IdenTokenType, val: "odd" });
404
- // }
405
- // }
406
392
  }
407
393
  }
408
394
  }
@@ -421,36 +407,6 @@ function parseSelector(tokens, context, options, errors) {
421
407
  }
422
408
  }
423
409
  if (num != null) {
424
- // if ((token as DimensionToken).val === 0) {
425
- // if (num.val === 0) {
426
- // func.chi.splice(0, i);
427
- // } else if (num.val === 1) {
428
- // let hasSelector: boolean = false;
429
- // let j: number = i + 1;
430
- // for (; j < func.chi.length; j++) {
431
- // if (
432
- // func.chi[j].typ == EnumToken.IdenTokenType &&
433
- // (func.chi[j] as IdentToken).val == "of"
434
- // ) {
435
- // hasSelector = true;
436
- // break;
437
- // }
438
- // }
439
- // if (hasSelector) {
440
- // func.chi.splice(0, i);
441
- // } else {
442
- // tokens[tokens.indexOf(func)] = {
443
- // typ: EnumToken.PseudoClassTokenType,
444
- // val: ":first-child",
445
- // [LOC]: func[LOC],
446
- // };
447
- // }
448
- // break;
449
- // } else {
450
- // func.chi.splice(0, i);
451
- // }
452
- // break;
453
- // } else
454
410
  if (num.val === 0) {
455
411
  func.chi.splice(index + 1, i - index);
456
412
  if (token.val < 0) {
@@ -539,10 +495,9 @@ function parseSelector(tokens, context, options, errors) {
539
495
  .keys(),
540
496
  ].join(","),
541
497
  chi: [],
542
- [LOC]: {
543
- ...tokens[0][LOC],
544
- end: tokens[tokens.length - 1][LOC].end,
545
- },
498
+ [LOCSRCID]: tokens[0][LOCSRCID],
499
+ [LOCSTA]: tokens[0][LOCSTA],
500
+ [LOCEND]: tokens[tokens.length - 1][LOCEND],
546
501
  [TOKENS]: tokens,
547
502
  [STATE]: result.success && allowed
548
503
  ? EnumAstNodeStatus.Validated
@@ -7,9 +7,11 @@ function camelize(value) {
7
7
  function equalsIgnoreCase(a, b) {
8
8
  if (a.length !== b.length)
9
9
  return false;
10
+ let ca;
11
+ let cb;
10
12
  for (let i = 0; i < a.length; i++) {
11
- let ca = a.charCodeAt(i);
12
- let cb = b.charCodeAt(i);
13
+ ca = a.charCodeAt(i);
14
+ cb = b.charCodeAt(i);
13
15
  // Normalize A-Z to a-z
14
16
  if (ca >= 65 && ca <= 90)
15
17
  ca += 32;