@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,6 +1,6 @@
1
1
  import { EnumToken, EnumAstNodeStatus, ColorType, ValidationLevel } from '../../ast/types.js';
2
- import { definedPropertySettings, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace } from '../../syntax/constants.js';
3
- import { renamedStandardProperties, isColor, parseColor, isWhiteSpace, isValue } from '../../syntax/syntax.js';
2
+ import { LOC, STATE, ERRORS, tokensfuncDefMap, COLORS_NAMES, nonStandardColors, systemColors, deprecatedSystemColors, tokensMap, trimTokenSpace } from '../../syntax/constants.js';
3
+ import { renamedStandardProperties, isColor, parseColor, isWhiteSpace } from '../../syntax/syntax.js';
4
4
  import { getSyntaxRule, getParsedSyntax } from '../../validation/config.js';
5
5
  import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
6
6
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
@@ -47,44 +47,41 @@ function parseGridTemplate(template) {
47
47
  * @param tokens
48
48
  * @returns
49
49
  */
50
- function isDeclarationValue(tokens) {
51
- const stack = [];
52
- let i = 0;
53
- for (; i < tokens.length; i++) {
54
- if (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType) {
55
- continue;
56
- }
57
- else if (tokensfuncDefMap.has(tokens[i].typ) || tokens[i].typ === EnumToken.StartParensTokenType) {
58
- stack.push(tokens[i]);
59
- }
60
- else if (tokens[i].typ === EnumToken.CommaTokenType || tokens[i].typ === EnumToken.LiteralTokenType) {
61
- stack.push(tokens[i]);
62
- }
63
- else if (isValue(tokens[i])) {
64
- if (stack.at(-1)?.typ === EnumToken.LiteralTokenType) {
65
- stack.pop();
66
- }
67
- }
68
- else if (tokens[i].typ === EnumToken.EndParensTokenType) {
69
- if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
70
- stack.pop();
71
- }
72
- }
73
- }
74
- return {
75
- success: stack.length === 0,
76
- errors: stack.length > 0
77
- ? [
78
- {
79
- action: "drop",
80
- message: `unexpected declaration value at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
81
- node: stack.at(-1),
82
- location: stack.at(-1)?.loc,
83
- },
84
- ]
85
- : [],
86
- };
87
- }
50
+ // export function isDeclarationValue(tokens: Token[]): { success: boolean; errors: ErrorDescription[] } {
51
+ // const stack: Token[] = [];
52
+ // let i: number = 0;
53
+ // for (; i < tokens.length; i++) {
54
+ // if (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType) {
55
+ // continue;
56
+ // } else if (tokensfuncDefMap.has(tokens[i].typ) || tokens[i].typ === EnumToken.StartParensTokenType) {
57
+ // stack.push(tokens[i]);
58
+ // } else if (tokens[i].typ === EnumToken.CommaTokenType || tokens[i].typ === EnumToken.LiteralTokenType) {
59
+ // stack.push(tokens[i]);
60
+ // } else if (isValue(tokens[i])) {
61
+ // if (stack.at(-1)?.typ === EnumToken.LiteralTokenType) {
62
+ // stack.pop();
63
+ // }
64
+ // } else if (tokens[i].typ === EnumToken.EndParensTokenType) {
65
+ // if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
66
+ // stack.pop();
67
+ // }
68
+ // }
69
+ // }
70
+ // return {
71
+ // success: stack.length === 0,
72
+ // errors:
73
+ // stack.length > 0
74
+ // ? [
75
+ // {
76
+ // action: "drop",
77
+ // message: `unexpected declaration value at ${stack.at(-1)?.[LOC]?.src}:${stack.at(-1)?.[LOC]?.sta.lin}:${stack.at(-1)?.[LOC]?.sta.col}`,
78
+ // node: stack.at(-1),
79
+ // location: stack.at(-1)?.[LOC],
80
+ // },
81
+ // ]
82
+ // : [],
83
+ // };
84
+ // }
88
85
  /**
89
86
  * Parse declaration
90
87
  * @param tokens
@@ -98,9 +95,7 @@ function parseDeclaration(tokens, parent, options, errors) {
98
95
  let rules = null;
99
96
  let syntaxRules = null;
100
97
  let success = true;
101
- let validate = typeof options.validation === "boolean"
102
- ? options.validation
103
- : !!options.validation;
98
+ let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
104
99
  if (renamedStandardProperties.has(name.val)) {
105
100
  name.val = renamedStandardProperties.get(name.val);
106
101
  }
@@ -115,79 +110,77 @@ function parseDeclaration(tokens, parent, options, errors) {
115
110
  }
116
111
  if ((name.typ !== EnumToken.IdenTokenType && name.typ !== EnumToken.DashedIdenTokenType) ||
117
112
  tokens[i]?.typ !== EnumToken.ColonTokenType) {
118
- return Object.defineProperties(Object.assign({
113
+ name[LOC] = {
114
+ ...name[LOC],
115
+ end: tokens[tokens.length - 1]?.[LOC]?.end ?? name[LOC].end,
116
+ };
117
+ name[STATE] = EnumAstNodeStatus.Unparsed;
118
+ name[ERRORS] = [
119
+ {
120
+ action: "drop",
121
+ node: name,
122
+ location: name[LOC],
123
+ message: "invalid declaration",
124
+ },
125
+ ];
126
+ return Object.assign({
119
127
  typ: EnumToken.RawNodeTokenType,
120
128
  val: tokens,
121
- }), {
122
- state: {
123
- ...definedPropertySettings,
124
- value: EnumAstNodeStatus.Unparsed,
125
- },
126
- errors: {
127
- ...definedPropertySettings,
128
- value: [
129
- {
130
- action: "drop",
131
- node: name,
132
- location: name.loc,
133
- message: "invalid declaration",
134
- },
135
- ],
136
- },
137
- loc: {
138
- ...definedPropertySettings,
139
- value: {
140
- ...name.loc,
141
- end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
142
- },
143
- },
144
129
  });
145
130
  }
146
131
  tokens = trimArray(tokens.slice(i + 1));
147
- for (i = 0; i < tokens.length; i++) {
148
- const token = tokens[i];
149
- if (token.typ == EnumToken.WhitespaceTokenType ||
150
- token.typ == EnumToken.CommentTokenType ||
151
- token.typ == EnumToken.InvalidCommentTokenType) {
152
- continue;
153
- }
154
- if (tokens[i].typ === EnumToken.UrlFunctionTokenDefType) {
155
- let k = i;
156
- while (k < tokens.length) {
157
- if (tokens[++k]?.typ === EnumToken.WhitespaceTokenType ||
158
- tokens[k]?.typ === EnumToken.CommentTokenType) {
159
- continue;
160
- }
161
- if (tokens[k]?.typ !== EnumToken.EndParensTokenType) {
162
- break;
163
- }
164
- }
165
- if (tokens[k].typ === EnumToken.LiteralTokenType ||
166
- tokens[k].typ === EnumToken.IdenTokenType ||
167
- tokens[k].typ === EnumToken.DashedIdenTokenType ||
168
- tokens[k].typ === EnumToken.HashTokenType ||
169
- tokens[k].typ === EnumToken.ClassSelectorTokenType) {
170
- let j = k;
171
- let val = tokens[k].val;
172
- while (j + 1 < tokens.length) {
173
- if (tokens[++j].typ !== EnumToken.LiteralTokenType &&
174
- tokens[j].typ !== EnumToken.IdenTokenType &&
175
- tokens[j].typ !== EnumToken.DashedIdenTokenType &&
176
- tokens[j].typ !== EnumToken.HashTokenType &&
177
- tokens[j].typ !== EnumToken.ClassSelectorTokenType) {
178
- break;
179
- }
180
- val += tokens[j].val;
181
- }
182
- Object.assign(tokens[k], {
183
- typ: EnumToken.UrlTokenTokenType,
184
- val,
185
- });
186
- tokens[k].loc.end = tokens[j].loc.end;
187
- tokens.splice(k + 1, j - k - 1);
188
- }
189
- }
190
- }
132
+ // for (i = 0; i < tokens.length; i++) {
133
+ // const token = tokens[i];
134
+ // if (
135
+ // token.typ == EnumToken.WhitespaceTokenType ||
136
+ // token.typ == EnumToken.CommentTokenType ||
137
+ // token.typ == EnumToken.InvalidCommentTokenType
138
+ // ) {
139
+ // continue;
140
+ // }
141
+ // if (tokens[i].typ === EnumToken.UrlFunctionTokenDefType) {
142
+ // let k: number = i;
143
+ // while (k < tokens.length) {
144
+ // if (
145
+ // tokens[++k]?.typ === EnumToken.WhitespaceTokenType ||
146
+ // tokens[k]?.typ === EnumToken.CommentTokenType
147
+ // ) {
148
+ // continue;
149
+ // }
150
+ // if (tokens[k]?.typ !== EnumToken.EndParensTokenType) {
151
+ // break;
152
+ // }
153
+ // }
154
+ // if (
155
+ // tokens[k].typ === EnumToken.LiteralTokenType ||
156
+ // tokens[k].typ === EnumToken.IdenTokenType ||
157
+ // tokens[k].typ === EnumToken.DashedIdenTokenType ||
158
+ // tokens[k].typ === EnumToken.HashTokenType ||
159
+ // tokens[k].typ === EnumToken.ClassSelectorTokenType
160
+ // ) {
161
+ // let j: number = k;
162
+ // let val: string = (tokens[k] as LiteralToken | IdentToken | DashedIdentToken | HashToken).val;
163
+ // while (j + 1 < tokens.length) {
164
+ // if (
165
+ // tokens[++j].typ !== EnumToken.LiteralTokenType &&
166
+ // tokens[j].typ !== EnumToken.IdenTokenType &&
167
+ // tokens[j].typ !== EnumToken.DashedIdenTokenType &&
168
+ // tokens[j].typ !== EnumToken.HashTokenType &&
169
+ // tokens[j].typ !== EnumToken.ClassSelectorTokenType
170
+ // ) {
171
+ // break;
172
+ // }
173
+ // val += (tokens[j] as LiteralToken | IdentToken | DashedIdentToken | HashToken).val;
174
+ // }
175
+ // Object.assign(tokens[k] as LiteralToken | IdentToken | DashedIdentToken | HashToken, {
176
+ // typ: EnumToken.UrlTokenTokenType,
177
+ // val,
178
+ // });
179
+ // tokens[k][LOC]!.end = tokens[j][LOC]!.end;
180
+ // tokens.splice(k + 1, j - k - 1);
181
+ // }
182
+ // }
183
+ // }
191
184
  if (validate && name.typ === EnumToken.IdenTokenType) {
192
185
  if (parent != null &&
193
186
  parent.typ === EnumToken.AtRuleNodeType &&
@@ -208,45 +201,39 @@ function parseDeclaration(tokens, parent, options, errors) {
208
201
  rules.acceptAnyDeclaration && rules.acceptAnyRule
209
202
  ? getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase())
210
203
  : rules.getBlockRules();
211
- if (syntaxRules == null) {
212
- // check rule in nested context
213
- let pr = parent.parent;
214
- while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
215
- pr = pr.parent;
216
- }
217
- if (pr != null) {
218
- syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase());
219
- }
220
- if (syntaxRules == null) {
221
- errors.push({
222
- action: "drop",
223
- message: "declaration not allowed in context",
224
- node: name,
225
- location: name.loc,
226
- });
227
- return Object.defineProperties(Object.assign(name, {
228
- typ: EnumToken.DeclarationNodeType,
229
- nam: name.val,
230
- val: tokens,
231
- }), {
232
- state: {
233
- ...definedPropertySettings,
234
- value: EnumAstNodeStatus.Disallowed,
235
- },
236
- errors: {
237
- ...definedPropertySettings,
238
- value: [errors[errors.length - 1]],
239
- },
240
- loc: {
241
- ...definedPropertySettings,
242
- value: {
243
- ...name.loc,
244
- end: tokens[tokens.length - 1].loc.end,
245
- },
246
- },
247
- });
248
- }
249
- }
204
+ // if (syntaxRules == null) {
205
+ // // check rule in nested context
206
+ // let pr = parent[PARENT] as AstNode | null;
207
+ // while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
208
+ // pr = pr[PARENT];
209
+ // }
210
+ // if (pr != null) {
211
+ // syntaxRules = getParsedSyntax(
212
+ // ValidationSyntaxGroupEnum.Declarations,
213
+ // name.val.toLowerCase(),
214
+ // );
215
+ // }
216
+ // if (syntaxRules == null) {
217
+ // errors.push({
218
+ // action: "drop",
219
+ // message: "declaration not allowed in context",
220
+ // node: name,
221
+ // location: name[LOC],
222
+ // });
223
+ // name[LOC] = {
224
+ // ...name[LOC],
225
+ // end: tokens[tokens.length - 1][LOC]!.end,
226
+ // } as Location;
227
+ // name[STATE] = EnumAstNodeStatus.Disallowed;
228
+ // name[ERRORS] = [errors[errors.length - 1]];
229
+ // // @ts-expect-error
230
+ // return Object.assign(name, {
231
+ // typ: EnumToken.DeclarationNodeType,
232
+ // nam: name.val,
233
+ // val: tokens,
234
+ // }) as AstDeclaration;
235
+ // }
236
+ // }
250
237
  }
251
238
  }
252
239
  }
@@ -284,28 +271,19 @@ function parseDeclaration(tokens, parent, options, errors) {
284
271
  action: "drop",
285
272
  message: "declaration value missing",
286
273
  node: name,
287
- location: name.loc,
274
+ location: name[LOC],
288
275
  });
289
- return Object.defineProperties(Object.assign(name, {
276
+ name[LOC] = {
277
+ ...name[LOC],
278
+ end: tokens[tokens.length - 1]?.[LOC].end ?? name[LOC].end,
279
+ };
280
+ name[STATE] = EnumAstNodeStatus.Invalid;
281
+ name[ERRORS] = [errors[errors.length - 1]];
282
+ // @ts-expect-error
283
+ return Object.assign(name, {
290
284
  typ: EnumToken.DeclarationNodeType,
291
285
  nam: name.val,
292
286
  val: tokens,
293
- }), {
294
- state: {
295
- ...definedPropertySettings,
296
- value: EnumAstNodeStatus.Invalid,
297
- },
298
- errors: {
299
- ...definedPropertySettings,
300
- value: [errors[errors.length - 1]],
301
- },
302
- loc: {
303
- ...definedPropertySettings,
304
- value: {
305
- ...name.loc,
306
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
307
- },
308
- },
309
287
  });
310
288
  }
311
289
  const stack = [];
@@ -336,21 +314,23 @@ function parseDeclaration(tokens, parent, options, errors) {
336
314
  }
337
315
  for (i = 0; i < tokens.length; i++) {
338
316
  token = tokens[i];
339
- if (tokensfuncDefMap.has(token.typ) || token.typ == EnumToken.StartParensTokenType) {
317
+ if (tokensfuncDefMap.has(token.typ) ||
318
+ token.typ == EnumToken.StartParensTokenType ||
319
+ token.typ == EnumToken.BlockStartTokenType) {
340
320
  stack.push(token);
341
321
  continue;
342
322
  }
343
323
  switch (token.typ) {
344
- case EnumToken.IdenTokenType:
345
- if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
346
- Object.assign(token, {
347
- typ: EnumToken.FunctionTokenDefType,
348
- });
349
- token.loc.end = tokens[i + 1].loc.end;
350
- tokens.splice(i + 1, 1);
351
- stack.push(token);
352
- }
353
- break;
324
+ // case EnumToken.IdenTokenType:
325
+ // if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
326
+ // Object.assign(token, {
327
+ // typ: EnumToken.FunctionTokenDefType,
328
+ // });
329
+ // token[LOC]!.end = tokens[i + 1][LOC]!.end;
330
+ // tokens.splice(i + 1, 1);
331
+ // stack.push(token);
332
+ // }
333
+ // break;
354
334
  case EnumToken.Literal:
355
335
  if (token.val === "/" && stack.at(-1)?.typ == EnumToken.MathFunctionTokenDefType) {
356
336
  Object.assign(token, {
@@ -370,36 +350,40 @@ function parseDeclaration(tokens, parent, options, errors) {
370
350
  typ: tokensMap.get(token.typ),
371
351
  });
372
352
  break;
373
- case EnumToken.EndParensTokenType:
374
- if (stack.length == 0) {
375
- errors.push({
376
- action: "drop",
377
- message: "unbalanced parentheses",
378
- node: token,
379
- location: token.loc,
380
- });
381
- return Object.defineProperties(Object.assign(name, {
382
- typ: EnumToken.DeclarationNodeType,
383
- nam: name.val,
384
- val: tokens,
385
- }), {
386
- state: {
387
- ...definedPropertySettings,
388
- value: EnumAstNodeStatus.Invalid,
389
- },
390
- errors: {
391
- ...definedPropertySettings,
392
- value: errors[errors.length - 1],
393
- },
394
- loc: {
395
- ...definedPropertySettings,
396
- value: {
397
- ...name.loc,
398
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
399
- },
400
- },
353
+ case EnumToken.BlockEndTokenType:
354
+ if (stack.at(-1)?.typ === EnumToken.BlockStartTokenType) {
355
+ // stack.pop();index = tokens.indexOf(stack.at(-1)!);
356
+ index = tokens.indexOf(stack.at(-1));
357
+ tokens.splice(i, 1);
358
+ Object.assign(tokens[index], {
359
+ typ: EnumToken.WrappedValuesTokenType,
360
+ chi: trimArray(tokens.splice(index + 1, i - index - 1)),
401
361
  });
362
+ i = index;
363
+ stack.pop();
402
364
  }
365
+ break;
366
+ case EnumToken.EndParensTokenType:
367
+ // if (stack.length == 0) {
368
+ // errors.push({
369
+ // action: "drop",
370
+ // message: "unbalanced parentheses",
371
+ // node: token,
372
+ // location: token[LOC],
373
+ // });
374
+ // name[LOC] = {
375
+ // ...name[LOC],
376
+ // end: tokens[tokens.length - 1]?.[LOC]!.end ?? name[LOC]!.end,
377
+ // } as Location;
378
+ // name[STATE] = EnumAstNodeStatus.Invalid;
379
+ // name[ERRORS] = [errors[errors.length - 1]];
380
+ // // @ts-expect-error
381
+ // return Object.assign(name, {
382
+ // typ: EnumToken.DeclarationNodeType,
383
+ // nam: name.val,
384
+ // val: tokens,
385
+ // }) as AstDeclaration;
386
+ // }
403
387
  if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
404
388
  index = tokens.indexOf(stack.at(-1));
405
389
  tokens.splice(i, 1);
@@ -439,7 +423,9 @@ function parseDeclaration(tokens, parent, options, errors) {
439
423
  r: {
440
424
  typ: EnumToken.IfConditionTokenType,
441
425
  l: trimArray(curr.slice(0, index)),
442
- r: trimArray(curr.slice(index + 1)),
426
+ r: trimArray(curr.at(-1)?.typ === EnumToken.SemiColonTokenType
427
+ ? curr.slice(index + 1, -1)
428
+ : curr.slice(index + 1)),
443
429
  },
444
430
  };
445
431
  }
@@ -459,19 +445,24 @@ function parseDeclaration(tokens, parent, options, errors) {
459
445
  if (tokens[index].chi[l].typ === EnumToken.StringTokenType) {
460
446
  break;
461
447
  }
462
- else if (tokens[index].chi[l].typ === EnumToken.IdenTokenType) {
463
- let m = l + 1;
464
- while (tokens[index].chi[m]?.typ === EnumToken.ClassSelectorTokenType) {
465
- Object.assign(tokens[index].chi[l], {
466
- typ: EnumToken.UrlTokenTokenType,
467
- val: tokens[index].chi[l].val +
468
- tokens[index].chi[m].val,
469
- });
470
- tokens[index].chi[l].loc.end = tokens[index].chi[m].loc.end;
471
- tokens[index].chi.splice(m, 1);
472
- }
473
- break;
474
- }
448
+ // else if ((tokens[index] as FunctionToken).chi[l].typ === EnumToken.IdenTokenType) {
449
+ // let m: number = l + 1;
450
+ // while (
451
+ // (tokens[index] as FunctionToken).chi[m]?.typ === EnumToken.ClassSelectorTokenType
452
+ // ) {
453
+ // Object.assign((tokens[index] as FunctionToken).chi[l], {
454
+ // typ: EnumToken.UrlTokenTokenType,
455
+ // val:
456
+ // ((tokens[index] as FunctionToken).chi[l] as IdentToken | UrlToken).val +
457
+ // ((tokens[index] as FunctionToken).chi[m] as ClassSelectorToken).val,
458
+ // });
459
+ // (tokens[index] as FunctionToken).chi[l][LOC]!.end = (
460
+ // tokens[index] as FunctionToken
461
+ // ).chi[m][LOC]!.end;
462
+ // (tokens[index] as FunctionToken).chi.splice(m, 1);
463
+ // }
464
+ // break;
465
+ // }
475
466
  }
476
467
  if (tokens[index].chi[l]?.typ === EnumToken.StringTokenType &&
477
468
  /^[a-zA-Z0-0/_.-]+$/.test(tokens[index].chi[l].val.slice(1, -1))) {
@@ -495,12 +486,12 @@ function parseDeclaration(tokens, parent, options, errors) {
495
486
  tokens[index].typ = EnumToken.FunctionTokenType;
496
487
  errors.push({
497
488
  action: "drop",
498
- message: `invalid color at ${tokens[index].loc?.src}:${tokens[index].loc?.sta.lin}:${tokens[index].loc?.sta.col}`,
489
+ message: `invalid color at ${tokens[index][LOC]?.src}:${tokens[index][LOC]?.sta.lin}:${tokens[index][LOC]?.sta.col}`,
499
490
  });
500
491
  }
501
492
  }
493
+ stack.pop();
502
494
  }
503
- stack.pop();
504
495
  break;
505
496
  case EnumToken.IdenTokenType:
506
497
  {
@@ -545,30 +536,21 @@ function parseDeclaration(tokens, parent, options, errors) {
545
536
  if (stack.length > 0) {
546
537
  errors.push({
547
538
  action: "drop",
548
- message: "unbalanced parenthesis",
539
+ message: "unbalanced token",
549
540
  node: stack[stack.length - 1],
550
- location: stack[stack.length - 1].loc,
541
+ location: stack[stack.length - 1][LOC],
551
542
  });
552
- return Object.defineProperties(Object.assign(name, {
543
+ name[LOC] = {
544
+ ...name[LOC],
545
+ end: tokens[tokens.length - 1][LOC].end,
546
+ };
547
+ name[STATE] = EnumAstNodeStatus.Invalid;
548
+ name[ERRORS] = result?.errors ?? [];
549
+ //@ts-expect-error
550
+ return Object.assign(name, {
553
551
  typ: EnumToken.DeclarationNodeType,
554
552
  nam: name.val,
555
553
  val: tokens,
556
- }), {
557
- state: {
558
- ...definedPropertySettings,
559
- value: EnumAstNodeStatus.Invalid,
560
- },
561
- errors: {
562
- ...definedPropertySettings,
563
- value: result?.errors ?? [],
564
- },
565
- loc: {
566
- ...definedPropertySettings,
567
- value: {
568
- ...name.loc,
569
- end: tokens[tokens.length - 1].loc.end,
570
- },
571
- },
572
554
  });
573
555
  }
574
556
  for (const { value } of walkValues(tokens)) {
@@ -594,35 +576,26 @@ function parseDeclaration(tokens, parent, options, errors) {
594
576
  }
595
577
  }
596
578
  if (validate && syntaxRules == null && name.typ === EnumToken.IdenTokenType) {
597
- const node = Object.defineProperties(Object.assign(name, {
579
+ name[LOC] = {
580
+ ...name[LOC],
581
+ end: tokens[tokens.length - 1]?.[LOC]?.end ?? name[LOC].end,
582
+ };
583
+ name[STATE] = EnumAstNodeStatus.Unknown;
584
+ name[ERRORS] = result?.errors ?? [];
585
+ // @ts-expect-error
586
+ const node = Object.assign(name, {
598
587
  typ: EnumToken.DeclarationNodeType,
599
588
  nam: name.val,
600
589
  val: tokens,
601
- }), {
602
- state: {
603
- ...definedPropertySettings,
604
- value: EnumAstNodeStatus.Unknown,
605
- },
606
- errors: {
607
- ...definedPropertySettings,
608
- value: result?.errors ?? [],
609
- },
610
- loc: {
611
- ...definedPropertySettings,
612
- value: {
613
- ...name.loc,
614
- end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
615
- },
616
- },
617
590
  });
618
- if (options.validation & ValidationLevel.Declaration) {
619
- errors.push({
620
- action: "drop",
621
- message: "unknown declaration",
622
- node: node,
623
- location: node.loc,
624
- });
625
- }
591
+ // if ((options.validation as ValidationLevel) & ValidationLevel.Declaration) {
592
+ // errors.push({
593
+ // action: "drop",
594
+ // message: "unknown declaration",
595
+ // node: node,
596
+ // location: node[LOC],
597
+ // });
598
+ // }
626
599
  return node;
627
600
  }
628
601
  if (equalsIgnoreCase("composes", name.val)) {
@@ -636,45 +609,34 @@ function parseDeclaration(tokens, parent, options, errors) {
636
609
  const left = trimArray(index == -1 ? tokens : tokens.slice(0, index));
637
610
  const right = index == -1 ? null : trimArray(tokens.slice(index + 1));
638
611
  tokens = [
639
- Object.defineProperty({
612
+ {
640
613
  typ: EnumToken.ComposesSelectorNodeType,
641
614
  l: left,
642
615
  r: right?.[0] ?? null,
643
- }, "loc", {
644
- ...definedPropertySettings,
645
- value: {
646
- ...tokens[0].loc,
647
- sta: left[0]?.loc?.sta,
648
- end: index != -1 ? right[right.length - 1]?.loc?.end : left[left.length - 1].loc.end,
616
+ [LOC]: {
617
+ ...tokens[0][LOC],
618
+ sta: left[0]?.[LOC]?.sta,
619
+ end: index != -1 ? right[right.length - 1]?.[LOC]?.end : left[left.length - 1][LOC].end,
649
620
  },
650
- }),
621
+ },
651
622
  ];
652
623
  }
653
- return Object.defineProperties(Object.assign(name, {
654
- typ: success ? EnumToken.DeclarationNodeType : EnumToken.DeclarationNodeType,
624
+ name[LOC] = {
625
+ ...name[LOC],
626
+ end: (tokens[tokens.length - 1] ?? name)[LOC].end,
627
+ };
628
+ name[STATE] = success
629
+ ? result == null
630
+ ? EnumAstNodeStatus.Unvalidated
631
+ : EnumAstNodeStatus.Validated
632
+ : EnumAstNodeStatus.ValidationFailed;
633
+ name[ERRORS] = result?.errors ?? [];
634
+ // @ts-expect-error
635
+ return Object.assign(name, {
636
+ typ: EnumToken.DeclarationNodeType,
655
637
  nam: name.val,
656
638
  val: tokens,
657
- }), {
658
- state: {
659
- ...definedPropertySettings,
660
- value: success
661
- ? result == null
662
- ? EnumAstNodeStatus.Unvalidated
663
- : EnumAstNodeStatus.Validated
664
- : EnumAstNodeStatus.ValidationFailed,
665
- },
666
- errors: {
667
- ...definedPropertySettings,
668
- value: result?.errors ?? [],
669
- },
670
- loc: {
671
- ...definedPropertySettings,
672
- value: {
673
- ...name.loc,
674
- end: (tokens[tokens.length - 1] ?? name).loc.end,
675
- },
676
- },
677
639
  });
678
640
  }
679
641
 
680
- export { isDeclarationValue, parseDeclaration };
642
+ export { parseDeclaration };