@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,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';
@@ -8,7 +8,6 @@ import { walkValues } from '../../ast/walk.js';
8
8
  import { equalsIgnoreCase } from './text.js';
9
9
  import { buildExpression } from '../../ast/math/expression.js';
10
10
  import { splitTokenList } from '../../validation/utils/list.js';
11
- import { parseTokens } from '../parse.js';
12
11
 
13
12
  /**
14
13
  *
@@ -48,44 +47,41 @@ function parseGridTemplate(template) {
48
47
  * @param tokens
49
48
  * @returns
50
49
  */
51
- function isDeclarationValue(tokens) {
52
- const stack = [];
53
- let i = 0;
54
- for (; i < tokens.length; i++) {
55
- if (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType) {
56
- continue;
57
- }
58
- else if (tokensfuncDefMap.has(tokens[i].typ) || tokens[i].typ === EnumToken.StartParensTokenType) {
59
- stack.push(tokens[i]);
60
- }
61
- else if (tokens[i].typ === EnumToken.CommaTokenType || tokens[i].typ === EnumToken.LiteralTokenType) {
62
- stack.push(tokens[i]);
63
- }
64
- else if (isValue(tokens[i])) {
65
- if (stack.at(-1)?.typ === EnumToken.LiteralTokenType) {
66
- stack.pop();
67
- }
68
- }
69
- else if (tokens[i].typ === EnumToken.EndParensTokenType) {
70
- if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
71
- stack.pop();
72
- }
73
- }
74
- }
75
- return {
76
- success: stack.length === 0,
77
- errors: stack.length > 0
78
- ? [
79
- {
80
- action: "drop",
81
- message: `unexpected declaration value at ${stack.at(-1)?.loc?.src}:${stack.at(-1)?.loc?.sta.lin}:${stack.at(-1)?.loc?.sta.col}`,
82
- node: stack.at(-1),
83
- location: stack.at(-1)?.loc,
84
- },
85
- ]
86
- : [],
87
- };
88
- }
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
+ // }
89
85
  /**
90
86
  * Parse declaration
91
87
  * @param tokens
@@ -99,9 +95,7 @@ function parseDeclaration(tokens, parent, options, errors) {
99
95
  let rules = null;
100
96
  let syntaxRules = null;
101
97
  let success = true;
102
- let validate = typeof options.validation === "boolean"
103
- ? options.validation
104
- : !!options.validation;
98
+ let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
105
99
  if (renamedStandardProperties.has(name.val)) {
106
100
  name.val = renamedStandardProperties.get(name.val);
107
101
  }
@@ -116,79 +110,77 @@ function parseDeclaration(tokens, parent, options, errors) {
116
110
  }
117
111
  if ((name.typ !== EnumToken.IdenTokenType && name.typ !== EnumToken.DashedIdenTokenType) ||
118
112
  tokens[i]?.typ !== EnumToken.ColonTokenType) {
119
- 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({
120
127
  typ: EnumToken.RawNodeTokenType,
121
128
  val: tokens,
122
- }), {
123
- state: {
124
- ...definedPropertySettings,
125
- value: EnumAstNodeStatus.Unparsed,
126
- },
127
- errors: {
128
- ...definedPropertySettings,
129
- value: [
130
- {
131
- action: "drop",
132
- node: name,
133
- location: name.loc,
134
- message: "invalid declaration",
135
- },
136
- ],
137
- },
138
- loc: {
139
- ...definedPropertySettings,
140
- value: {
141
- ...name.loc,
142
- end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
143
- },
144
- },
145
129
  });
146
130
  }
147
131
  tokens = trimArray(tokens.slice(i + 1));
148
- for (i = 0; i < tokens.length; i++) {
149
- const token = tokens[i];
150
- if (token.typ == EnumToken.WhitespaceTokenType ||
151
- token.typ == EnumToken.CommentTokenType ||
152
- token.typ == EnumToken.InvalidCommentTokenType) {
153
- continue;
154
- }
155
- if (tokens[i].typ === EnumToken.UrlFunctionTokenDefType) {
156
- let k = i;
157
- while (k < tokens.length) {
158
- if (tokens[++k]?.typ === EnumToken.WhitespaceTokenType ||
159
- tokens[k]?.typ === EnumToken.CommentTokenType) {
160
- continue;
161
- }
162
- if (tokens[k]?.typ !== EnumToken.EndParensTokenType) {
163
- break;
164
- }
165
- }
166
- if (tokens[k].typ === EnumToken.LiteralTokenType ||
167
- tokens[k].typ === EnumToken.IdenTokenType ||
168
- tokens[k].typ === EnumToken.DashedIdenTokenType ||
169
- tokens[k].typ === EnumToken.HashTokenType ||
170
- tokens[k].typ === EnumToken.ClassSelectorTokenType) {
171
- let j = k;
172
- let val = tokens[k].val;
173
- while (j + 1 < tokens.length) {
174
- if (tokens[++j].typ !== EnumToken.LiteralTokenType &&
175
- tokens[j].typ !== EnumToken.IdenTokenType &&
176
- tokens[j].typ !== EnumToken.DashedIdenTokenType &&
177
- tokens[j].typ !== EnumToken.HashTokenType &&
178
- tokens[j].typ !== EnumToken.ClassSelectorTokenType) {
179
- break;
180
- }
181
- val += tokens[j].val;
182
- }
183
- Object.assign(tokens[k], {
184
- typ: EnumToken.UrlTokenTokenType,
185
- val,
186
- });
187
- tokens[k].loc.end = tokens[j].loc.end;
188
- tokens.splice(k + 1, j - k - 1);
189
- }
190
- }
191
- }
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
+ // }
192
184
  if (validate && name.typ === EnumToken.IdenTokenType) {
193
185
  if (parent != null &&
194
186
  parent.typ === EnumToken.AtRuleNodeType &&
@@ -209,45 +201,39 @@ function parseDeclaration(tokens, parent, options, errors) {
209
201
  rules.acceptAnyDeclaration && rules.acceptAnyRule
210
202
  ? getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase())
211
203
  : rules.getBlockRules();
212
- if (syntaxRules == null) {
213
- // check rule in nested context
214
- let pr = parent.parent;
215
- while (pr != null && pr.typ !== EnumToken.RuleNodeType) {
216
- pr = pr.parent;
217
- }
218
- if (pr != null) {
219
- syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, name.val.toLowerCase());
220
- }
221
- if (syntaxRules == null) {
222
- errors.push({
223
- action: "drop",
224
- message: "declaration not allowed in context",
225
- node: name,
226
- location: name.loc,
227
- });
228
- return Object.defineProperties(Object.assign(name, {
229
- typ: EnumToken.DeclarationNodeType,
230
- nam: name.val,
231
- val: tokens,
232
- }), {
233
- state: {
234
- ...definedPropertySettings,
235
- value: EnumAstNodeStatus.Disallowed,
236
- },
237
- errors: {
238
- ...definedPropertySettings,
239
- value: [errors[errors.length - 1]],
240
- },
241
- loc: {
242
- ...definedPropertySettings,
243
- value: {
244
- ...name.loc,
245
- end: tokens[tokens.length - 1].loc.end,
246
- },
247
- },
248
- });
249
- }
250
- }
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
+ // }
251
237
  }
252
238
  }
253
239
  }
@@ -285,28 +271,19 @@ function parseDeclaration(tokens, parent, options, errors) {
285
271
  action: "drop",
286
272
  message: "declaration value missing",
287
273
  node: name,
288
- location: name.loc,
274
+ location: name[LOC],
289
275
  });
290
- 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, {
291
284
  typ: EnumToken.DeclarationNodeType,
292
285
  nam: name.val,
293
286
  val: tokens,
294
- }), {
295
- state: {
296
- ...definedPropertySettings,
297
- value: EnumAstNodeStatus.Invalid,
298
- },
299
- errors: {
300
- ...definedPropertySettings,
301
- value: [errors[errors.length - 1]],
302
- },
303
- loc: {
304
- ...definedPropertySettings,
305
- value: {
306
- ...name.loc,
307
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
308
- },
309
- },
310
287
  });
311
288
  }
312
289
  const stack = [];
@@ -333,48 +310,27 @@ function parseDeclaration(tokens, parent, options, errors) {
333
310
  if (!doNotValidate && !result?.success && result.errors.length > 0) {
334
311
  errors.push(...result.errors);
335
312
  }
336
- if (!doNotValidate && !(success || result.success)) {
337
- return Object.defineProperties(Object.assign(name, {
338
- typ: EnumToken.DeclarationNodeType,
339
- nam: name.val,
340
- val: parseTokens(tokens),
341
- }), {
342
- state: {
343
- ...definedPropertySettings,
344
- value: EnumAstNodeStatus.ValidationFailed,
345
- },
346
- errors: {
347
- ...definedPropertySettings,
348
- value: result?.errors ?? [],
349
- },
350
- loc: {
351
- ...definedPropertySettings,
352
- value: {
353
- ...name.loc,
354
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
355
- },
356
- },
357
- });
358
- }
359
313
  }
360
314
  }
361
315
  for (i = 0; i < tokens.length; i++) {
362
316
  token = tokens[i];
363
- 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) {
364
320
  stack.push(token);
365
321
  continue;
366
322
  }
367
323
  switch (token.typ) {
368
- case EnumToken.IdenTokenType:
369
- if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
370
- Object.assign(token, {
371
- typ: EnumToken.FunctionTokenDefType,
372
- });
373
- token.loc.end = tokens[i + 1].loc.end;
374
- tokens.splice(i + 1, 1);
375
- stack.push(token);
376
- }
377
- 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;
378
334
  case EnumToken.Literal:
379
335
  if (token.val === "/" && stack.at(-1)?.typ == EnumToken.MathFunctionTokenDefType) {
380
336
  Object.assign(token, {
@@ -394,36 +350,40 @@ function parseDeclaration(tokens, parent, options, errors) {
394
350
  typ: tokensMap.get(token.typ),
395
351
  });
396
352
  break;
397
- case EnumToken.EndParensTokenType:
398
- if (stack.length == 0) {
399
- errors.push({
400
- action: "drop",
401
- message: "unbalanced parentheses",
402
- node: token,
403
- location: token.loc,
404
- });
405
- return Object.defineProperties(Object.assign(name, {
406
- typ: EnumToken.DeclarationNodeType,
407
- nam: name.val,
408
- val: tokens,
409
- }), {
410
- state: {
411
- ...definedPropertySettings,
412
- value: EnumAstNodeStatus.Invalid,
413
- },
414
- errors: {
415
- ...definedPropertySettings,
416
- value: errors[errors.length - 1],
417
- },
418
- loc: {
419
- ...definedPropertySettings,
420
- value: {
421
- ...name.loc,
422
- end: tokens[tokens.length - 1]?.loc.end ?? name.loc.end,
423
- },
424
- },
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)),
425
361
  });
362
+ i = index;
363
+ stack.pop();
426
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
+ // }
427
387
  if (stack.at(-1)?.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(stack.at(-1)?.typ)) {
428
388
  index = tokens.indexOf(stack.at(-1));
429
389
  tokens.splice(i, 1);
@@ -463,7 +423,9 @@ function parseDeclaration(tokens, parent, options, errors) {
463
423
  r: {
464
424
  typ: EnumToken.IfConditionTokenType,
465
425
  l: trimArray(curr.slice(0, index)),
466
- 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)),
467
429
  },
468
430
  };
469
431
  }
@@ -483,19 +445,24 @@ function parseDeclaration(tokens, parent, options, errors) {
483
445
  if (tokens[index].chi[l].typ === EnumToken.StringTokenType) {
484
446
  break;
485
447
  }
486
- else if (tokens[index].chi[l].typ === EnumToken.IdenTokenType) {
487
- let m = l + 1;
488
- while (tokens[index].chi[m]?.typ === EnumToken.ClassSelectorTokenType) {
489
- Object.assign(tokens[index].chi[l], {
490
- typ: EnumToken.UrlTokenTokenType,
491
- val: tokens[index].chi[l].val +
492
- tokens[index].chi[m].val,
493
- });
494
- tokens[index].chi[l].loc.end = tokens[index].chi[m].loc.end;
495
- tokens[index].chi.splice(m, 1);
496
- }
497
- break;
498
- }
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
+ // }
499
466
  }
500
467
  if (tokens[index].chi[l]?.typ === EnumToken.StringTokenType &&
501
468
  /^[a-zA-Z0-0/_.-]+$/.test(tokens[index].chi[l].val.slice(1, -1))) {
@@ -519,12 +486,12 @@ function parseDeclaration(tokens, parent, options, errors) {
519
486
  tokens[index].typ = EnumToken.FunctionTokenType;
520
487
  errors.push({
521
488
  action: "drop",
522
- 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}`,
523
490
  });
524
491
  }
525
492
  }
493
+ stack.pop();
526
494
  }
527
- stack.pop();
528
495
  break;
529
496
  case EnumToken.IdenTokenType:
530
497
  {
@@ -569,30 +536,21 @@ function parseDeclaration(tokens, parent, options, errors) {
569
536
  if (stack.length > 0) {
570
537
  errors.push({
571
538
  action: "drop",
572
- message: "unbalanced parenthesis",
539
+ message: "unbalanced token",
573
540
  node: stack[stack.length - 1],
574
- location: stack[stack.length - 1].loc,
541
+ location: stack[stack.length - 1][LOC],
575
542
  });
576
- 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, {
577
551
  typ: EnumToken.DeclarationNodeType,
578
552
  nam: name.val,
579
553
  val: tokens,
580
- }), {
581
- state: {
582
- ...definedPropertySettings,
583
- value: EnumAstNodeStatus.Invalid,
584
- },
585
- errors: {
586
- ...definedPropertySettings,
587
- value: result?.errors ?? [],
588
- },
589
- loc: {
590
- ...definedPropertySettings,
591
- value: {
592
- ...name.loc,
593
- end: tokens[tokens.length - 1].loc.end,
594
- },
595
- },
596
554
  });
597
555
  }
598
556
  for (const { value } of walkValues(tokens)) {
@@ -618,35 +576,26 @@ function parseDeclaration(tokens, parent, options, errors) {
618
576
  }
619
577
  }
620
578
  if (validate && syntaxRules == null && name.typ === EnumToken.IdenTokenType) {
621
- 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, {
622
587
  typ: EnumToken.DeclarationNodeType,
623
588
  nam: name.val,
624
589
  val: tokens,
625
- }), {
626
- state: {
627
- ...definedPropertySettings,
628
- value: EnumAstNodeStatus.Unknown,
629
- },
630
- errors: {
631
- ...definedPropertySettings,
632
- value: result?.errors ?? [],
633
- },
634
- loc: {
635
- ...definedPropertySettings,
636
- value: {
637
- ...name.loc,
638
- end: tokens[tokens.length - 1]?.loc?.end ?? name.loc.end,
639
- },
640
- },
641
590
  });
642
- if (options.validation & ValidationLevel.Declaration) {
643
- errors.push({
644
- action: "drop",
645
- message: "unknown declaration",
646
- node: node,
647
- location: node.loc,
648
- });
649
- }
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
+ // }
650
599
  return node;
651
600
  }
652
601
  if (equalsIgnoreCase("composes", name.val)) {
@@ -660,45 +609,34 @@ function parseDeclaration(tokens, parent, options, errors) {
660
609
  const left = trimArray(index == -1 ? tokens : tokens.slice(0, index));
661
610
  const right = index == -1 ? null : trimArray(tokens.slice(index + 1));
662
611
  tokens = [
663
- Object.defineProperty({
612
+ {
664
613
  typ: EnumToken.ComposesSelectorNodeType,
665
614
  l: left,
666
615
  r: right?.[0] ?? null,
667
- }, "loc", {
668
- ...definedPropertySettings,
669
- value: {
670
- ...tokens[0].loc,
671
- sta: left[0]?.loc?.sta,
672
- 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,
673
620
  },
674
- }),
621
+ },
675
622
  ];
676
623
  }
677
- return Object.defineProperties(Object.assign(name, {
678
- 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,
679
637
  nam: name.val,
680
638
  val: tokens,
681
- }), {
682
- state: {
683
- ...definedPropertySettings,
684
- value: success
685
- ? result == null
686
- ? EnumAstNodeStatus.Unvalidated
687
- : EnumAstNodeStatus.Validated
688
- : EnumAstNodeStatus.ValidationFailed,
689
- },
690
- errors: {
691
- ...definedPropertySettings,
692
- value: result?.errors ?? [],
693
- },
694
- loc: {
695
- ...definedPropertySettings,
696
- value: {
697
- ...name.loc,
698
- end: (tokens[tokens.length - 1] ?? name).loc.end,
699
- },
700
- },
701
639
  });
702
640
  }
703
641
 
704
- export { isDeclarationValue, parseDeclaration };
642
+ export { parseDeclaration };