@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
@@ -6,7 +6,7 @@ import { minify } from '../ast/minify.js';
6
6
  import { expand } from '../ast/expand.js';
7
7
  import { WalkerEvent, walk, walkValues } from '../ast/walk.js';
8
8
  import { tokenizeStream, tokenize } from './tokenize.js';
9
- import { definedPropertySettings, tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
9
+ import { ROOT, LOC, tokensfuncDefMap, STATE, PARENT, TOKENS, ERRORS, pageMarginBoxType } from '../syntax/constants.js';
10
10
  import { hashAlgorithms, hash } from './utils/hash.js';
11
11
  import { parseSelector } from './utils/selector.js';
12
12
  import { parseDeclaration } from './utils/declaration.js';
@@ -46,7 +46,6 @@ const BadTokensTypes = [
46
46
  EnumToken.BadStringTokenType,
47
47
  ];
48
48
  let keyNameCounter = 0;
49
- let keyNameCache = {};
50
49
  const forbiddenStartCharacters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].map((c) => c.charCodeAt(0));
51
50
  /**
52
51
  * Short-scoped name generator.
@@ -59,17 +58,13 @@ const forbiddenStartCharacters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "
59
58
  * @returns string
60
59
  */
61
60
  const getShortNameGenerator = memoize((localName, filePath, pattern, hashLength = 5) => {
62
- const key = `${localName}_${filePath}_${pattern}_${hashLength}`;
63
- if (key in keyNameCache) {
64
- return keyNameCache[key];
65
- }
66
61
  let value = keyNameCounter.toString(36);
67
62
  keyNameCounter++;
68
63
  while (forbiddenStartCharacters.includes(value.charCodeAt(0))) {
69
64
  value = keyNameCounter.toString(36);
70
65
  keyNameCounter++;
71
66
  }
72
- return (keyNameCache[key] = value);
67
+ return value;
73
68
  });
74
69
  function reject(reason) {
75
70
  throw new Error(reason ?? "Parsing aborted");
@@ -267,8 +262,9 @@ async function doParse(iter, options = {}) {
267
262
  };
268
263
  let tokens = [];
269
264
  let context = ast;
265
+ ast[ROOT] = ast;
270
266
  if (options.sourcemap) {
271
- ast.loc = {
267
+ ast[LOC] = {
272
268
  sta: {
273
269
  ind: 0,
274
270
  lin: 1,
@@ -294,6 +290,7 @@ async function doParse(iter, options = {}) {
294
290
  // @ts-ignore ignore error
295
291
  let isAsync = typeof iter[Symbol.asyncIterator] === "function";
296
292
  let parensMatch = 0;
293
+ let curlyBracketMatch = 0;
297
294
  if (options.visitor != null) {
298
295
  valuesHandlers = new Map();
299
296
  preValuesHandlers = new Map();
@@ -406,13 +403,6 @@ async function doParse(iter, options = {}) {
406
403
  iter.next().value)) {
407
404
  stats.bytesIn = item.bytesIn;
408
405
  stats.tokensCount++;
409
- if (options.sourcemap !== false) {
410
- Object.defineProperty(item.token, "loc", {
411
- ...definedPropertySettings,
412
- value: item.token.loc,
413
- enumerable: true,
414
- });
415
- }
416
406
  if (BadTokensTypes.includes(item.token.typ)) {
417
407
  tokens.push(item.token);
418
408
  errors.push({
@@ -420,7 +410,7 @@ async function doParse(iter, options = {}) {
420
410
  message: "Bad token",
421
411
  syntax: null,
422
412
  node: item.token,
423
- location: item.token.loc,
413
+ location: item.token[LOC],
424
414
  });
425
415
  // bad token
426
416
  continue;
@@ -431,11 +421,19 @@ async function doParse(iter, options = {}) {
431
421
  else if (item.token.typ === EnumToken.EndParensTokenType && parensMatch > 0) {
432
422
  parensMatch--;
433
423
  }
424
+ if (item.token.typ === EnumToken.BlockStartTokenType) {
425
+ curlyBracketMatch++;
426
+ }
427
+ else if (item.token.typ === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
428
+ curlyBracketMatch--;
429
+ }
434
430
  tokens.push(item.token);
435
- if ((parensMatch === 0 &&
431
+ // console.debug([item.token, {parensMatch, curlyBracketMatch}]);
432
+ // if (parensMatch === 0) {
433
+ if (parensMatch === 0 &&
436
434
  (item.token.typ === EnumToken.SemiColonTokenType ||
437
- item.token.typ === EnumToken.BlockStartTokenType)) ||
438
- item.token.typ === EnumToken.EOFTokenType) {
435
+ item.token.typ === EnumToken.BlockStartTokenType ||
436
+ item.token.typ === EnumToken.EOFTokenType)) {
439
437
  node = parseNode(tokens, context, options, errors, stats, invalidNodes);
440
438
  if (node != null) {
441
439
  if ("chi" in node) {
@@ -472,18 +470,18 @@ async function doParse(iter, options = {}) {
472
470
  message: "invalid block",
473
471
  location: {
474
472
  src,
475
- sta: tokens[0].loc.sta,
476
- end: tokens[tokens.length - 1].loc.end,
473
+ sta: tokens[0][LOC].sta,
474
+ end: tokens[tokens.length - 1][LOC].end,
477
475
  },
478
476
  });
479
477
  }
480
478
  }
481
479
  tokens = [];
482
480
  }
483
- else if (item.token.typ === EnumToken.BlockEndTokenType) {
481
+ else if ((parensMatch === 0 || curlyBracketMatch === 0) && item.token.typ === EnumToken.BlockEndTokenType) {
484
482
  parseNode(tokens, context, options, errors, stats, invalidNodes);
485
- if (context.loc != null) {
486
- context.loc.end = item.token.loc.end;
483
+ if (context[LOC] != null) {
484
+ context[LOC].end = item.token[LOC].end;
487
485
  }
488
486
  const previousNode = stack.pop();
489
487
  context = (stack[stack.length - 1] ?? ast);
@@ -494,7 +492,10 @@ async function doParse(iter, options = {}) {
494
492
  context.chi.pop();
495
493
  }
496
494
  tokens = [];
495
+ parensMatch = 0;
496
+ curlyBracketMatch = 0;
497
497
  }
498
+ // }
498
499
  }
499
500
  if (tokens.length > 0) {
500
501
  node = parseNode(tokens, context, options, errors, stats, invalidNodes);
@@ -510,10 +511,10 @@ async function doParse(iter, options = {}) {
510
511
  }
511
512
  if (imports.length > 0 && options.resolveImport) {
512
513
  await Promise.all(imports.map(async (node) => {
513
- if (node.state !== EnumAstNodeStatus.Validated) {
514
+ if (node[STATE] !== EnumAstNodeStatus.Validated) {
514
515
  return;
515
516
  }
516
- const token = node.tokens[0];
517
+ const token = node[TOKENS][0];
517
518
  const url = token.typ == EnumToken.StringTokenType ? token.val.slice(1, -1) : token.val;
518
519
  try {
519
520
  const result = options.load(url, options.src || options.cwd);
@@ -536,7 +537,7 @@ async function doParse(iter, options = {}) {
536
537
  }));
537
538
  stats.importedBytesIn += root.stats.bytesIn;
538
539
  stats.imports.push(root.stats);
539
- node.parent.chi.splice(node.parent.chi.indexOf(node), 1, ...root.ast.chi);
540
+ node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1, ...root.ast.chi);
540
541
  if (root.errors.length > 0) {
541
542
  errors.push(...root.errors);
542
543
  }
@@ -605,7 +606,7 @@ async function doParse(iter, options = {}) {
605
606
  continue;
606
607
  }
607
608
  // @ts-expect-error
608
- replacement = callable(node, result.parent, ast, function* () {
609
+ replacement = callable(node, result[PARENT], ast, function* () {
609
610
  if (parens == null) {
610
611
  // @ts-expect-error
611
612
  parens = [...result.parents()];
@@ -720,9 +721,9 @@ async function doParse(iter, options = {}) {
720
721
  }
721
722
  if (node != result.node) {
722
723
  // @ts-ignore
723
- replaceNodeOrValue(result.parent, value, node);
724
+ replaceNodeOrValue(result[PARENT], value, node);
724
725
  }
725
- const tokens = Array.isArray(result.node.tokens) ? result.node.tokens : [];
726
+ const tokens = Array.isArray(result.node[TOKENS]) ? result.node[TOKENS] : [];
726
727
  if (Array.isArray(result.node.val)) {
727
728
  tokens.push(...result.node.val);
728
729
  }
@@ -769,16 +770,19 @@ async function doParse(iter, options = {}) {
769
770
  }
770
771
  }
771
772
  }
773
+ // console.debug("invalid nodes", invalidNodes);
772
774
  if (invalidNodes.length > 0) {
773
775
  let k = invalidNodes.length;
774
776
  while (k-- > 0) {
775
- if (invalidNodes[k].state == EnumAstNodeStatus.Validated || invalidNodes[k].state == EnumAstNodeStatus.Unvalidated || invalidNodes[k].state == EnumAstNodeStatus.ValidationFailed) {
777
+ if (invalidNodes[k][STATE] == EnumAstNodeStatus.Validated ||
778
+ invalidNodes[k][STATE] == EnumAstNodeStatus.Unvalidated ||
779
+ invalidNodes[k][STATE] == EnumAstNodeStatus.ValidationFailed) {
776
780
  continue;
777
781
  }
778
- if (options.lenient && invalidNodes[k].state == EnumAstNodeStatus.Unknown) {
782
+ if (options.lenient && invalidNodes[k][STATE] == EnumAstNodeStatus.Unknown) {
779
783
  continue;
780
784
  }
781
- invalidNodes[k].parent.chi.splice(invalidNodes[k].parent.chi.indexOf(invalidNodes[k]), 1);
785
+ invalidNodes[k][PARENT].chi.splice(invalidNodes[k][PARENT].chi.indexOf(invalidNodes[k]), 1);
782
786
  }
783
787
  }
784
788
  while (stack.length > 0 && context != ast) {
@@ -792,18 +796,6 @@ async function doParse(iter, options = {}) {
792
796
  context.chi.pop();
793
797
  continue;
794
798
  }
795
- // remove invalid nodes
796
- if (!options.lenient &&
797
- previousNode?.parent != null &&
798
- // @ts-expect-error
799
- (previousNode.typ == EnumToken.InvalidRuleNodeType || previousNode.typ == EnumToken.InvalidAtRuleNodeType)) {
800
- for (let i = context.chi.length - 1; i >= 0; i--) {
801
- if (context.chi[i] == previousNode) {
802
- context.chi.splice(i, 1);
803
- break;
804
- }
805
- }
806
- }
807
799
  break;
808
800
  }
809
801
  if (options.minify) {
@@ -984,9 +976,9 @@ async function doParse(iter, options = {}) {
984
976
  }
985
977
  }
986
978
  // find parent rule
987
- let parentRule = node.parent;
979
+ let parentRule = node[PARENT];
988
980
  while (parentRule != null && parentRule.typ != EnumToken.RuleNodeType) {
989
- parentRule = parentRule.parent;
981
+ parentRule = parentRule[PARENT];
990
982
  }
991
983
  if ( /* !isValid || */tokens.length == 0) {
992
984
  errors.push({
@@ -1019,7 +1011,7 @@ async function doParse(iter, options = {}) {
1019
1011
  revMapping[mapping[rule.val]] = rule.val;
1020
1012
  }
1021
1013
  if (parentRule != null) {
1022
- for (const tk of parentRule.tokens) {
1014
+ for (const tk of parentRule[TOKENS]) {
1023
1015
  if (tk.typ == EnumToken.ClassSelectorTokenType) {
1024
1016
  const val = tk.val.slice(1);
1025
1017
  if (val in revMapping) {
@@ -1064,7 +1056,7 @@ async function doParse(iter, options = {}) {
1064
1056
  importMapping[srcIndex] = {};
1065
1057
  }
1066
1058
  if (parentRule != null) {
1067
- for (const tk of parentRule.tokens) {
1059
+ for (const tk of parentRule[TOKENS]) {
1068
1060
  if (tk.typ == EnumToken.ClassSelectorTokenType) {
1069
1061
  const val = tk.val.slice(1);
1070
1062
  if (val in revMapping) {
@@ -1102,7 +1094,7 @@ async function doParse(iter, options = {}) {
1102
1094
  // global
1103
1095
  if (parentRule != null) {
1104
1096
  if (equalsIgnoreCase("global", token.r.val)) {
1105
- for (const tk of parentRule.tokens) {
1097
+ for (const tk of parentRule[TOKENS]) {
1106
1098
  if (tk.typ == EnumToken.ClassSelectorTokenType) {
1107
1099
  const val = tk.val.slice(1);
1108
1100
  if (val in revMapping) {
@@ -1255,19 +1247,25 @@ async function doParse(iter, options = {}) {
1255
1247
  }
1256
1248
  for (const { value, parent } of walkValues(node.val, node)) {
1257
1249
  if (value.typ == EnumToken.DashedIdenTokenType) {
1258
- if (!(value.val in mapping)) {
1259
- const result = moduleSettings.scoped & ModuleScopeEnumOptions.Global
1260
- ? value.val
1261
- : moduleSettings.generateScopedName(value.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
1262
- let val = result instanceof Promise ? await result : result;
1263
- mapping[value.val] =
1264
- "--" +
1265
- (moduleSettings.naming & ModuleCaseTransformEnum.DashCaseOnly ||
1266
- moduleSettings.naming & ModuleCaseTransformEnum.CamelCaseOnly
1267
- ? getKeyName(val, moduleSettings.naming)
1268
- : val);
1269
- revMapping[mapping[value.val]] = value.val;
1270
- }
1250
+ // if (!((value as DashedIdentToken).val in mapping)) {
1251
+ // const result =
1252
+ // moduleSettings.scoped! & ModuleScopeEnumOptions.Global
1253
+ // ? (value as DashedIdentToken).val
1254
+ // : moduleSettings.generateScopedName!(
1255
+ // (value as DashedIdentToken).val,
1256
+ // moduleSettings.filePath as string,
1257
+ // moduleSettings.pattern as string,
1258
+ // moduleSettings.hashLength,
1259
+ // );
1260
+ // let val: string = result instanceof Promise ? await result : result;
1261
+ // mapping[(value as DashedIdentToken).val] =
1262
+ // "--" +
1263
+ // (moduleSettings.naming! & ModuleCaseTransformEnum.DashCaseOnly ||
1264
+ // moduleSettings.naming! & ModuleCaseTransformEnum.CamelCaseOnly
1265
+ // ? getKeyName(val, moduleSettings.naming as ModuleCaseTransformEnum)
1266
+ // : val);
1267
+ // revMapping[mapping[(value as DashedIdentToken).val]] = (value as DashedIdentToken).val;
1268
+ // }
1271
1269
  value.val = mapping[value.val];
1272
1270
  }
1273
1271
  else if ((value.typ == EnumToken.IdenTokenType || isIdentColor(value)) &&
@@ -1277,61 +1275,64 @@ async function doParse(iter, options = {}) {
1277
1275
  }
1278
1276
  }
1279
1277
  else if (node.typ == EnumToken.RuleNodeType) {
1280
- if (node.tokens == null) {
1278
+ if (node[TOKENS] == null) {
1281
1279
  const tokens = parseString(node.sel);
1282
1280
  matchSelectorSyntax(tokens, [], options);
1283
- Object.defineProperty(node, "tokens", {
1284
- ...definedPropertySettings,
1285
- value: trimArray(tokens),
1286
- });
1287
- let i;
1288
- const stack = [];
1289
- for (i = 0; i < tokens.length; i++) {
1290
- if (tokensfuncDefMap.has(tokens[i].typ)) {
1291
- stack.push(tokens[i]);
1292
- continue;
1293
- }
1294
- else if (tokens[i].typ == EnumToken.EndParensTokenType) {
1295
- const func = stack.at(-1);
1296
- tokens.splice(i, 1);
1297
- // @ts-expect-error
1298
- func.typ = tokensfuncDefMap.get(func.typ);
1299
- func.chi = tokens.splice(tokens.indexOf(func) + 1, i - 1);
1300
- stack.pop();
1301
- }
1302
- }
1281
+ node[TOKENS] = trimArray(tokens);
1282
+ // let i: number;
1283
+ // const stack: Token[] = [];
1284
+ // for (i = 0; i < tokens.length; i++) {
1285
+ // if (tokensfuncDefMap.has(tokens[i].typ)) {
1286
+ // stack.push(tokens[i]);
1287
+ // continue;
1288
+ // } else if (tokens[i].typ == EnumToken.EndParensTokenType) {
1289
+ // const func = stack.at(-1) as PseudoClassFunctionToken;
1290
+ // tokens.splice(i, 1);
1291
+ // // @ts-expect-error
1292
+ // func.typ = tokensfuncDefMap.get(func.typ)!;
1293
+ // func.chi = tokens.splice(tokens.indexOf(func) + 1, i - 1);
1294
+ // stack.pop();
1295
+ // }
1296
+ // }
1303
1297
  }
1304
1298
  let hasIdOrClass = false;
1305
- for (const { value } of walkValues(node.tokens, node,
1299
+ for (const { value } of walkValues(node[TOKENS], node,
1306
1300
  // @ts-ignore
1307
1301
  (value, parent) => {
1308
- if (value.typ == EnumToken.PseudoClassTokenType) {
1302
+ if (value.typ == EnumToken.PseudoClassTokenType ||
1303
+ value.typ == EnumToken.PseudoElementTokenType) {
1309
1304
  const val = value.val.toLowerCase();
1310
1305
  switch (val) {
1311
1306
  case ":local":
1312
1307
  case ":global":
1313
1308
  {
1314
- let index = parent.tokens.indexOf(value);
1315
- parent.tokens.splice(index, 1);
1316
- if (parent.tokens[index]?.typ == EnumToken.WhitespaceTokenType ||
1317
- parent.tokens[index]?.typ ==
1309
+ let index = parent[TOKENS].indexOf(value);
1310
+ parent[TOKENS].splice(index, 1);
1311
+ if (parent[TOKENS][index]?.typ == EnumToken.WhitespaceTokenType ||
1312
+ parent[TOKENS][index]?.typ ==
1318
1313
  EnumToken.DescendantCombinatorTokenType) {
1319
- parent.tokens.splice(index, 1);
1320
- }
1321
- if (val == ":global") {
1322
- for (; index < parent.tokens.length; index++) {
1323
- if (parent.tokens[index].typ ==
1324
- EnumToken.CommaTokenType ||
1325
- ([
1326
- EnumToken.PseudoClassFuncTokenType,
1327
- EnumToken.PseudoClassTokenType,
1328
- ].includes(parent.tokens[index].typ) &&
1329
- [":global", ":local"].includes(parent.tokens[index].val.toLowerCase()))) {
1330
- break;
1331
- }
1332
- global.add(parent.tokens[index]);
1333
- }
1314
+ parent[TOKENS].splice(index, 1);
1334
1315
  }
1316
+ // if (val == ":global") {
1317
+ // for (; index < (parent as AstRule)[TOKENS]!.length; index++) {
1318
+ // if (
1319
+ // (parent as AstRule)[TOKENS]![index].typ ==
1320
+ // EnumToken.CommaTokenType ||
1321
+ // ([
1322
+ // EnumToken.PseudoClassFuncTokenType,
1323
+ // EnumToken.PseudoClassTokenType,
1324
+ // ].includes((parent as AstRule)[TOKENS]![index].typ) &&
1325
+ // [":global", ":local"].includes(
1326
+ // (
1327
+ // (parent as AstRule)[TOKENS]![index] as PseudoClassToken
1328
+ // ).val.toLowerCase(),
1329
+ // ))
1330
+ // ) {
1331
+ // break;
1332
+ // }
1333
+ // global.add((parent as AstRule)[TOKENS]![index]);
1334
+ // }
1335
+ // }
1335
1336
  }
1336
1337
  break;
1337
1338
  }
@@ -1342,11 +1343,15 @@ async function doParse(iter, options = {}) {
1342
1343
  for (const token of value.chi) {
1343
1344
  global.add(token);
1344
1345
  }
1345
- parent.tokens.splice(parent.tokens.indexOf(value), 1, ...value.chi);
1346
- break;
1347
1346
  case ":local":
1348
- parent.tokens.splice(parent.tokens.indexOf(value), 1, ...value.chi);
1347
+ parent[TOKENS].splice(parent[TOKENS].indexOf(value), 1, ...value.chi);
1349
1348
  break;
1349
+ // (parent as AstRule)[TOKENS]!.splice(
1350
+ // (parent as AstRule)[TOKENS]!.indexOf(value),
1351
+ // 1,
1352
+ // ...(value as FunctionToken).chi,
1353
+ // );
1354
+ // break;
1350
1355
  }
1351
1356
  }
1352
1357
  })) {
@@ -1357,7 +1362,7 @@ async function doParse(iter, options = {}) {
1357
1362
  continue;
1358
1363
  }
1359
1364
  processed.add(value);
1360
- if (value.typ == EnumToken.PseudoClassTokenType) ;
1365
+ if (value.typ == EnumToken.PseudoClassTokenType || value.typ == EnumToken.PseudoElementTokenType) ;
1361
1366
  else if (value.typ == EnumToken.PseudoClassFuncTokenType) ;
1362
1367
  else {
1363
1368
  if (global.has(value)) {
@@ -1383,26 +1388,22 @@ async function doParse(iter, options = {}) {
1383
1388
  }
1384
1389
  if (moduleSettings.scoped & ModuleScopeEnumOptions.Pure) {
1385
1390
  if (!hasIdOrClass) {
1386
- throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${node.loc?.src ?? ""}':${node.loc?.sta?.lin ?? ""}:${node.loc?.sta?.col ?? ""}`);
1391
+ throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${node[LOC]?.src ?? ""}':${node[LOC]?.sta?.lin ?? ""}:${node[LOC]?.sta?.col ?? ""}`);
1387
1392
  }
1388
1393
  }
1389
1394
  node.sel = "";
1390
- for (const token of node.tokens) {
1395
+ for (const token of node[TOKENS]) {
1391
1396
  node.sel += renderValue(token);
1392
1397
  }
1393
1398
  }
1394
1399
  else if (node.typ == EnumToken.AtRuleNodeType || node.typ == EnumToken.KeyframesAtRuleNodeType) {
1395
1400
  const val = node.nam.toLowerCase();
1396
- if (node.tokens == null) {
1397
- Object.defineProperty(node, "tokens", {
1398
- ...definedPropertySettings,
1399
- // @ts-ignore
1400
- value: parseString(node.val),
1401
- });
1401
+ if (node[TOKENS] == null) {
1402
+ node[TOKENS] = parseString(node.val);
1402
1403
  }
1403
1404
  if (val == "property" || val == "keyframes") {
1404
1405
  const prefix = val == "property" ? "--" : "";
1405
- for (const value of node.tokens) {
1406
+ for (const value of node[TOKENS]) {
1406
1407
  if ((prefix == "--" && value.typ == EnumToken.DashedIdenTokenType) ||
1407
1408
  (prefix == "" && value.typ == EnumToken.IdenTokenType)) {
1408
1409
  if (!(value.val in mapping)) {
@@ -1421,25 +1422,33 @@ async function doParse(iter, options = {}) {
1421
1422
  value.val = mapping[value.val];
1422
1423
  }
1423
1424
  }
1424
- node.val = renderTokens(node.tokens);
1425
- }
1426
- else {
1427
- let isReplaced = false;
1428
- for (const { value, parent } of walkValues(node.tokens, node)) {
1429
- if (EnumToken.MediaQueryConditionTokenType == parent.typ &&
1430
- // @ts-expect-error
1431
- value != parent.l) {
1432
- if ((value.typ == EnumToken.IdenTokenType || isIdentColor(value)) &&
1433
- value.val in importedCssVariables) {
1434
- isReplaced = true;
1435
- parent.r.splice(parent.r.indexOf(value), 1, ...importedCssVariables[value.val].val);
1436
- }
1437
- }
1438
- }
1439
- if (isReplaced) {
1440
- node.val = renderTokens(node.tokens);
1441
- }
1425
+ node.val = renderTokens(node[TOKENS]);
1442
1426
  }
1427
+ // else {
1428
+ // let isReplaced: boolean = false;
1429
+ // for (const { value, parent } of walkValues(node[TOKENS], node)) {
1430
+ // if (
1431
+ // EnumToken.MediaQueryConditionTokenType == parent.typ &&
1432
+ // // @ts-expect-error
1433
+ // value != (parent as MediaQueryConditionToken).l
1434
+ // ) {
1435
+ // if (
1436
+ // (value.typ == EnumToken.IdenTokenType || isIdentColor(value)) &&
1437
+ // (value as IdentToken).val in importedCssVariables
1438
+ // ) {
1439
+ // isReplaced = true;
1440
+ // (parent as MediaQueryConditionToken).r.splice(
1441
+ // (parent as MediaQueryConditionToken).r.indexOf(value),
1442
+ // 1,
1443
+ // ...importedCssVariables[(value as IdentToken).val].val,
1444
+ // );
1445
+ // }
1446
+ // }
1447
+ // }
1448
+ // if (isReplaced) {
1449
+ // node.val = renderTokens(node[TOKENS]!);
1450
+ // }
1451
+ // }
1443
1452
  }
1444
1453
  }
1445
1454
  if (moduleSettings.naming != ModuleCaseTransformEnum.IgnoreCase) {
@@ -1471,7 +1480,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1471
1480
  tokens.pop();
1472
1481
  // check parenthesis are balanced
1473
1482
  let matchCount = 0;
1474
- let position = tokens.at(-1)?.loc;
1483
+ let position = tokens.at(-1)?.[LOC];
1475
1484
  for (let i = 0; i < tokens.length; i++) {
1476
1485
  const token = tokens[i];
1477
1486
  if (token.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(token.typ)) {
@@ -1495,13 +1504,10 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1495
1504
  sta: { ...position.sta, ind: position.sta.ind + 1, col: position.sta.col + 1 },
1496
1505
  end: { ...position.end, ind: position.end.ind + 1, col: position.end.col + 1 },
1497
1506
  };
1498
- tokens.push(Object.defineProperty({
1507
+ tokens.push({
1499
1508
  typ: EnumToken.EndParensTokenType,
1500
- loc: tokens.at(-1)?.loc,
1501
- }, "loc", {
1502
- ...definedPropertySettings,
1503
- value: { ...position },
1504
- }));
1509
+ [LOC]: { ...position },
1510
+ });
1505
1511
  matchCount--;
1506
1512
  }
1507
1513
  }
@@ -1512,7 +1518,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1512
1518
  action: "drop",
1513
1519
  message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
1514
1520
  node: tokens[i],
1515
- location: tokens[i].loc,
1521
+ location: tokens[i][LOC],
1516
1522
  });
1517
1523
  tokens[i].typ = EnumToken.InvalidCommentTokenType;
1518
1524
  continue;
@@ -1530,7 +1536,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1530
1536
  }
1531
1537
  for (; i < tokens.length; i++) {
1532
1538
  if (tokens[i].typ == EnumToken.CommentTokenType || tokens[i].typ == EnumToken.CDOCOMMTokenType) {
1533
- const location = tokens[i]?.loc;
1539
+ const location = tokens[i]?.[LOC];
1534
1540
  if (tokens[i].typ == EnumToken.CDOCOMMTokenType && context.typ != EnumToken.StyleSheetNodeType) {
1535
1541
  errors.push({
1536
1542
  action: "drop",
@@ -1541,6 +1547,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1541
1547
  tokens[i].typ = EnumToken.InvalidCommentTokenType;
1542
1548
  continue;
1543
1549
  }
1550
+ tokens[i][ROOT] = context[ROOT];
1544
1551
  context.chi.push(tokens[i]);
1545
1552
  stats.nodesCount++;
1546
1553
  }
@@ -1569,23 +1576,25 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1569
1576
  nestedRule = true;
1570
1577
  break;
1571
1578
  }
1572
- parent = parent.parent;
1579
+ parent = parent[PARENT];
1573
1580
  }
1574
1581
  node = parseAtRule(tokens, context, { ...options, nestedRule }, errors, delim.typ == EnumToken.BlockStartTokenType);
1575
1582
  if (node == null) {
1576
1583
  return null;
1577
1584
  }
1578
- if (node.state == EnumAstNodeStatus.Invalid ||
1579
- node.state == EnumAstNodeStatus.Disallowed ||
1580
- node.state == EnumAstNodeStatus.Unknown ||
1581
- node.state == EnumAstNodeStatus.Unparsed ||
1582
- node.state == EnumAstNodeStatus.Malformed) {
1585
+ if (node[STATE] == EnumAstNodeStatus.Invalid ||
1586
+ node[STATE] == EnumAstNodeStatus.Disallowed ||
1587
+ node[STATE] == EnumAstNodeStatus.Unknown ||
1588
+ node[STATE] == EnumAstNodeStatus.Unparsed ||
1589
+ node[STATE] == EnumAstNodeStatus.Malformed) {
1583
1590
  invalidNodes.push(node);
1584
1591
  }
1585
1592
  stats.nodesCount++;
1586
1593
  context.chi.push(node);
1587
- // @ts-expect-error
1588
- return Object.defineProperty(node, "parent", { ...definedPropertySettings, value: context });
1594
+ node[ROOT] = context[ROOT];
1595
+ node[PARENT] = context;
1596
+ // @ts-ignore
1597
+ return node;
1589
1598
  }
1590
1599
  else {
1591
1600
  stats.nodesCount++;
@@ -1593,36 +1602,38 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
1593
1602
  if (delim.typ == EnumToken.BlockStartTokenType) {
1594
1603
  const node = parseSelector(tokens, context, options, errors);
1595
1604
  context.chi.push(node);
1596
- Object.defineProperty(node, "parent", { ...definedPropertySettings, value: context });
1597
- if (node.state == EnumAstNodeStatus.Invalid ||
1598
- node.state == EnumAstNodeStatus.Disallowed ||
1599
- node.state == EnumAstNodeStatus.Unknown ||
1600
- node.state == EnumAstNodeStatus.Unparsed ||
1601
- node.state == EnumAstNodeStatus.Malformed) {
1605
+ node[PARENT] = context;
1606
+ node[ROOT] = context[ROOT];
1607
+ if (node[STATE] == EnumAstNodeStatus.Invalid ||
1608
+ node[STATE] == EnumAstNodeStatus.Disallowed ||
1609
+ node[STATE] == EnumAstNodeStatus.Unknown ||
1610
+ node[STATE] == EnumAstNodeStatus.Unparsed ||
1611
+ node[STATE] == EnumAstNodeStatus.Malformed) {
1602
1612
  invalidNodes.push(node);
1603
1613
  }
1604
1614
  return node;
1605
1615
  }
1606
1616
  else {
1607
1617
  const node = parseDeclaration(tokens, context, options, errors);
1608
- Object.defineProperty(node, "parent", { ...definedPropertySettings, value: context });
1618
+ node[PARENT] = context;
1619
+ node[ROOT] = context[ROOT];
1609
1620
  if (context.typ === EnumToken.StyleSheetNodeType && node.typ === EnumToken.DeclarationNodeType) {
1610
- node.state = EnumAstNodeStatus.Invalid;
1621
+ node[STATE] = EnumAstNodeStatus.Invalid;
1611
1622
  errors.push({
1612
1623
  message: "<declaration> not allowed in <stylesheet>",
1613
1624
  action: "drop",
1614
1625
  node,
1615
- location: node.loc,
1626
+ location: node[LOC],
1616
1627
  });
1617
1628
  }
1618
1629
  else if (options.lenient || node.typ === EnumToken.DeclarationNodeType) {
1619
1630
  context.chi.push(node);
1620
1631
  }
1621
- if (node.state == EnumAstNodeStatus.Invalid ||
1622
- node.state == EnumAstNodeStatus.Disallowed ||
1623
- node.state == EnumAstNodeStatus.Unknown ||
1624
- node.state == EnumAstNodeStatus.Unparsed ||
1625
- node.state == EnumAstNodeStatus.Malformed) {
1632
+ if (node[STATE] == EnumAstNodeStatus.Invalid ||
1633
+ node[STATE] == EnumAstNodeStatus.Disallowed ||
1634
+ node[STATE] == EnumAstNodeStatus.Unknown ||
1635
+ node[STATE] == EnumAstNodeStatus.Unparsed ||
1636
+ node[STATE] == EnumAstNodeStatus.Malformed) {
1626
1637
  invalidNodes.push(node);
1627
1638
  }
1628
1639
  }
@@ -1649,26 +1660,19 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1649
1660
  errors.push({
1650
1661
  action: "drop",
1651
1662
  node: atRule,
1652
- location: atRule.loc,
1663
+ location: atRule[LOC],
1653
1664
  message: "unknown at-rule",
1654
1665
  });
1655
1666
  const result = matchGenericSyntax(stream);
1667
+ atRule[TOKENS] = parseTokens(stream);
1668
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Unknown : EnumAstNodeStatus.Invalid;
1669
+ atRule[ERRORS] = result.success ? [errors[errors.length - 1]] : [errors[errors.length - 1], ...result.errors];
1656
1670
  // @ts-expect-error
1657
- return Object.defineProperties(Object.assign(atRule, {
1671
+ return Object.assign(atRule, {
1658
1672
  typ: EnumToken.AtRuleNodeType,
1659
1673
  val: renderTokens(trimArray(stream), options),
1660
1674
  ...(parseAsBlock ? { chi: [] } : {}),
1661
- }), {
1662
- state: {
1663
- ...definedPropertySettings,
1664
- value: result.success ? EnumAstNodeStatus.Unknown : EnumAstNodeStatus.Invalid,
1665
- },
1666
- errors: {
1667
- ...definedPropertySettings,
1668
- value: result.success ? [errors[errors.length - 1]] : [errors[errors.length - 1], ...result.errors],
1669
- },
1670
1675
  });
1671
- // }
1672
1676
  }
1673
1677
  else if (context.typ === EnumToken.AtRuleNodeType &&
1674
1678
  "page" === context.nam &&
@@ -1677,23 +1681,17 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1677
1681
  errors.push({
1678
1682
  action: "drop",
1679
1683
  node: atRule,
1680
- location: atRule.loc,
1684
+ location: atRule[LOC],
1681
1685
  message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
1682
1686
  });
1687
+ atRule[TOKENS] = parseTokens(stream);
1688
+ atRule[STATE] = EnumAstNodeStatus.Invalid;
1689
+ atRule[ERRORS] = [errors[errors.length - 1]];
1683
1690
  // @ts-expect-error
1684
- return Object.defineProperties(Object.assign(atRule, {
1691
+ return Object.assign(atRule, {
1685
1692
  typ: EnumToken.AtRuleNodeType,
1686
1693
  val: renderTokens(trimArray(stream), options),
1687
1694
  ...(parseAsBlock ? { chi: [] } : {}),
1688
- }), {
1689
- state: {
1690
- ...definedPropertySettings,
1691
- value: EnumAstNodeStatus.Invalid,
1692
- },
1693
- errors: {
1694
- ...definedPropertySettings,
1695
- value: [errors[errors.length - 1]],
1696
- },
1697
1695
  });
1698
1696
  }
1699
1697
  const token = stream.find((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ === EnumToken.CommentTokenType) ?? null;
@@ -1701,23 +1699,17 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1701
1699
  errors.push({
1702
1700
  action: "drop",
1703
1701
  node: token,
1704
- location: token.loc,
1705
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
1702
+ location: token[LOC],
1703
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
1706
1704
  });
1705
+ atRule[TOKENS] = parseTokens(stream);
1706
+ atRule[STATE] = EnumAstNodeStatus.Invalid;
1707
+ atRule[ERRORS] = [errors[errors.length - 1]];
1707
1708
  // @ts-expect-error
1708
- return Object.defineProperties(Object.assign(atRule, {
1709
+ return Object.assign(atRule, {
1709
1710
  typ: EnumToken.AtRuleNodeType,
1710
1711
  val: renderTokens(trimArray(stream), options),
1711
1712
  ...(parseAsBlock ? { chi: [] } : {}),
1712
- }), {
1713
- state: {
1714
- ...definedPropertySettings,
1715
- value: EnumAstNodeStatus.Invalid,
1716
- },
1717
- errors: {
1718
- ...definedPropertySettings,
1719
- value: [errors[errors.length - 1]],
1720
- },
1721
1713
  });
1722
1714
  }
1723
1715
  }
@@ -1729,23 +1721,17 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1729
1721
  errors.push({
1730
1722
  action: "drop",
1731
1723
  node: atRule,
1732
- location: atRule.loc,
1724
+ location: atRule[LOC],
1733
1725
  message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
1734
1726
  });
1727
+ atRule[TOKENS] = parseTokens(stream);
1728
+ atRule[STATE] = EnumAstNodeStatus.Invalid;
1729
+ atRule[ERRORS] = [errors[errors.length - 1]];
1735
1730
  // @ts-expect-error
1736
- return Object.defineProperties(Object.assign(atRule, {
1731
+ return Object.assign(atRule, {
1737
1732
  typ: EnumToken.AtRuleNodeType,
1738
1733
  val: renderTokens(trimArray(stream), options),
1739
1734
  ...(parseAsBlock ? { chi: [] } : {}),
1740
- }), {
1741
- state: {
1742
- ...definedPropertySettings,
1743
- value: EnumAstNodeStatus.Invalid,
1744
- },
1745
- errors: {
1746
- ...definedPropertySettings,
1747
- value: [errors[errors.length - 1]],
1748
- },
1749
1735
  });
1750
1736
  }
1751
1737
  switch (atRuleName) {
@@ -1758,7 +1744,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1758
1744
  errors.push({
1759
1745
  action: "drop",
1760
1746
  node: stream[0] ?? atRule,
1761
- location: (stream[0] ?? atRule).loc,
1747
+ location: (stream[0] ?? atRule)[LOC],
1762
1748
  message: "expecting <space>",
1763
1749
  });
1764
1750
  }
@@ -1767,7 +1753,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1767
1753
  errors.push({
1768
1754
  action: "drop",
1769
1755
  node: stream[1] ?? atRule,
1770
- location: (stream[1] ?? atRule).loc,
1756
+ location: (stream[1] ?? atRule)[LOC],
1771
1757
  message: "expecting <string>",
1772
1758
  });
1773
1759
  }
@@ -1776,52 +1762,32 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1776
1762
  errors.push({
1777
1763
  action: "drop",
1778
1764
  node: stream[1] ?? atRule,
1779
- location: (stream[1] ?? atRule).loc,
1765
+ location: (stream[1] ?? atRule)[LOC],
1780
1766
  message: "expecting double-quoted string",
1781
1767
  });
1782
1768
  }
1783
1769
  if (!success) {
1770
+ atRule[TOKENS] = stream;
1771
+ atRule[STATE] = EnumAstNodeStatus.Invalid;
1772
+ atRule[ERRORS] = [errors[errors.length - 1]];
1773
+ atRule[LOC] = { ...atRule[LOC], end: (stream.at(-1) ?? atRule)[LOC].end };
1784
1774
  // @ts-expect-error
1785
- return Object.defineProperties(Object.assign(atRule, {
1775
+ return Object.assign(atRule, {
1786
1776
  typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
1787
1777
  val: renderTokens(trimArray(stream), options),
1788
- }), {
1789
- state: {
1790
- ...definedPropertySettings,
1791
- value: EnumAstNodeStatus.Invalid,
1792
- },
1793
- errors: {
1794
- ...definedPropertySettings,
1795
- value: [errors[errors.length - 1]],
1796
- },
1797
- loc: {
1798
- ...definedPropertySettings,
1799
- value: { ...atRule.loc, end: (stream.at(-1) ?? atRule).loc.end },
1800
- },
1801
- tokens: { ...definedPropertySettings, value: stream },
1802
1778
  });
1803
1779
  }
1804
1780
  if (options.removeCharset) {
1805
1781
  return null;
1806
1782
  }
1783
+ atRule[TOKENS] = stream;
1784
+ atRule[STATE] = EnumAstNodeStatus.Validated;
1785
+ atRule[ERRORS] = [];
1786
+ atRule[LOC] = { ...atRule[LOC], end: (stream.at(-1) ?? atRule)[LOC].end };
1807
1787
  // @ts-expect-error
1808
- return Object.defineProperties(Object.assign(atRule, {
1788
+ return Object.assign(atRule, {
1809
1789
  typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
1810
1790
  val: renderTokens(trimArray(stream), options),
1811
- }), {
1812
- state: {
1813
- ...definedPropertySettings,
1814
- value: EnumAstNodeStatus.Validated,
1815
- },
1816
- errors: {
1817
- ...definedPropertySettings,
1818
- value: [],
1819
- },
1820
- loc: {
1821
- ...definedPropertySettings,
1822
- value: { ...atRule.loc, end: (stream.at(-1) ?? atRule).loc.end },
1823
- },
1824
- tokens: { ...definedPropertySettings, value: stream },
1825
1791
  });
1826
1792
  }
1827
1793
  case "font-feature-values": {
@@ -1829,25 +1795,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1829
1795
  if (result.errors.length > 0) {
1830
1796
  errors.push(...result.errors);
1831
1797
  }
1798
+ atRule[TOKENS] = stream;
1799
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1800
+ atRule[ERRORS] = result.success ? [] : result.errors;
1801
+ atRule[LOC] = { ...atRule[LOC], end: (stream.at(-1) ?? atRule)[LOC].end };
1832
1802
  // @ts-expect-error
1833
- return Object.defineProperties(Object.assign(atRule, {
1803
+ return Object.assign(atRule, {
1834
1804
  typ: EnumToken.AtRuleNodeType,
1835
1805
  val: renderTokens(trimWhiteSpaceTokens(stream), options),
1836
1806
  chi: [],
1837
- }), {
1838
- state: {
1839
- ...definedPropertySettings,
1840
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
1841
- },
1842
- errors: {
1843
- ...definedPropertySettings,
1844
- value: result.success ? [] : result.errors,
1845
- },
1846
- loc: {
1847
- ...definedPropertySettings,
1848
- value: { ...atRule.loc, end: (stream.at(-1) ?? atRule).loc.end },
1849
- },
1850
- tokens: { ...definedPropertySettings, value: stream },
1851
1807
  });
1852
1808
  }
1853
1809
  case "stylistic":
@@ -1861,7 +1817,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1861
1817
  errors.push({
1862
1818
  action: "drop",
1863
1819
  node: atRule,
1864
- location: atRule.loc,
1820
+ location: atRule[LOC],
1865
1821
  message: `unexpected at-rule ${atRule.nam}`,
1866
1822
  });
1867
1823
  }
@@ -1872,31 +1828,21 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1872
1828
  errors.push({
1873
1829
  action: "drop",
1874
1830
  node: token,
1875
- location: token.loc,
1876
- message: `unexpected token ${EnumToken[token.typ]} at ${token.loc.src}:${token.loc.sta.lin}:${token.loc.sta.col}`,
1831
+ location: token[LOC],
1832
+ message: `unexpected token ${EnumToken[token.typ]} at ${token[LOC].src}:${token[LOC].sta.lin}:${token[LOC].sta.col}`,
1877
1833
  });
1878
1834
  }
1879
1835
  }
1880
1836
  }
1837
+ atRule[LOC] = { ...atRule[LOC], end: (stream.at(-1) ?? atRule)[LOC].end };
1838
+ atRule[TOKENS] = stream;
1839
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1840
+ atRule[ERRORS] = [errors[errors.length - 1]];
1881
1841
  // @ts-expect-error
1882
- return Object.defineProperties(Object.assign(atRule, {
1842
+ return Object.assign(atRule, {
1883
1843
  typ: EnumToken.AtRuleNodeType,
1884
1844
  val: renderTokens(trimWhiteSpaceTokens(stream), options),
1885
1845
  chi: [],
1886
- }), {
1887
- state: {
1888
- ...definedPropertySettings,
1889
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
1890
- },
1891
- errors: {
1892
- ...definedPropertySettings,
1893
- value: [errors[errors.length - 1]],
1894
- },
1895
- loc: {
1896
- ...definedPropertySettings,
1897
- value: { ...atRule.loc, end: (stream.at(-1) ?? atRule).loc.end },
1898
- },
1899
- tokens: { ...definedPropertySettings, value: stream },
1900
1846
  });
1901
1847
  }
1902
1848
  case "container": {
@@ -1904,25 +1850,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1904
1850
  if (result.errors.length > 0) {
1905
1851
  errors.push(...result.errors);
1906
1852
  }
1853
+ atRule[LOC] = { ...atRule[LOC], end: (stream.at(-1) ?? atRule)[LOC].end };
1854
+ atRule[TOKENS] = stream;
1855
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1856
+ atRule[ERRORS] = result.success ? [] : result.errors;
1907
1857
  // @ts-expect-error
1908
- return Object.defineProperties(Object.assign(atRule, {
1858
+ return Object.assign(atRule, {
1909
1859
  typ: EnumToken.AtRuleNodeType,
1910
1860
  val: renderTokens(trimWhiteSpaceTokens(stream), options),
1911
1861
  chi: [],
1912
- }), {
1913
- state: {
1914
- ...definedPropertySettings,
1915
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
1916
- },
1917
- errors: {
1918
- ...definedPropertySettings,
1919
- value: result.success ? [] : result.errors,
1920
- },
1921
- loc: {
1922
- ...definedPropertySettings,
1923
- value: { ...atRule.loc, end: (stream.at(-1) ?? atRule).loc.end },
1924
- },
1925
- tokens: { ...definedPropertySettings, value: stream },
1926
1862
  });
1927
1863
  }
1928
1864
  case "custom-media": {
@@ -1933,24 +1869,14 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1933
1869
  }
1934
1870
  // @ts-expect-error
1935
1871
  options = { ...options, convertColor: false };
1872
+ atRule[LOC] = { ...atRule[LOC], end: (tokens.at(-1) ?? atRule)[LOC].end };
1873
+ atRule[TOKENS] = tokens;
1874
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed;
1875
+ atRule[ERRORS] = result.success ? [] : result.errors;
1936
1876
  // @ts-expect-error
1937
- return Object.defineProperties(Object.assign(atRule, {
1877
+ return Object.assign(atRule, {
1938
1878
  typ: EnumToken.AtRuleNodeType,
1939
1879
  val: renderTokens(trimWhiteSpaceTokens(tokens), options),
1940
- }), {
1941
- state: {
1942
- ...definedPropertySettings,
1943
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed,
1944
- },
1945
- errors: {
1946
- ...definedPropertySettings,
1947
- value: result.success ? [] : result.errors,
1948
- },
1949
- loc: {
1950
- ...definedPropertySettings,
1951
- value: { ...atRule.loc, end: (tokens.at(-1) ?? atRule).loc.end },
1952
- },
1953
- tokens: { ...definedPropertySettings, value: tokens },
1954
1880
  });
1955
1881
  }
1956
1882
  case "keyframes": {
@@ -1963,32 +1889,22 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
1963
1889
  errors.push({
1964
1890
  action: "drop",
1965
1891
  node: atRule,
1966
- location: atRule.loc,
1967
- message: `expected <keyframe-name> at ${atRule.loc.src}:${atRule.loc.sta.lin}:${atRule.loc.sta.col}`,
1892
+ location: atRule[LOC],
1893
+ message: `expected <keyframe-name> at ${atRule[LOC].src}:${atRule[LOC].sta.lin}:${atRule[LOC].sta.col}`,
1968
1894
  });
1969
1895
  success = false;
1970
1896
  }
1971
1897
  // @ts-expect-error
1972
1898
  options = { ...options, convertColor: false };
1899
+ atRule[LOC] = { ...atRule[LOC], end: (tokens.at(-1) ?? atRule)[LOC].end };
1900
+ atRule[TOKENS] = tokens;
1901
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1902
+ atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
1973
1903
  // @ts-expect-error
1974
- return Object.defineProperties(Object.assign(atRule, {
1904
+ return Object.assign(atRule, {
1975
1905
  typ: EnumToken.KeyframesAtRuleNodeType,
1976
1906
  val: renderTokens(tokens, options),
1977
1907
  chi: [],
1978
- }), {
1979
- state: {
1980
- ...definedPropertySettings,
1981
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
1982
- },
1983
- errors: {
1984
- ...definedPropertySettings,
1985
- value: success ? [] : errors[errors.length - 1],
1986
- },
1987
- loc: {
1988
- ...definedPropertySettings,
1989
- value: { ...atRule.loc, end: (tokens.at(-1) ?? atRule).loc.end },
1990
- },
1991
- tokens: { ...definedPropertySettings, value: tokens },
1992
1908
  });
1993
1909
  }
1994
1910
  case "namespace": {
@@ -2025,8 +1941,12 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2025
1941
  }
2026
1942
  // @ts-expect-error
2027
1943
  options = { ...options, convertColor: false };
1944
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
1945
+ atRule[TOKENS] = stream.slice();
1946
+ atRule[STATE] = valid ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1947
+ atRule[ERRORS] = valid ? [] : result.errors;
2028
1948
  // @ts-expect-error
2029
- return Object.defineProperties(Object.assign(atRule, {
1949
+ return Object.assign(atRule, {
2030
1950
  typ: EnumToken.AtRuleNodeType,
2031
1951
  val: trimArray(stream).reduce((acc, t, index) => acc +
2032
1952
  (t.typ === EnumToken.CommentTokenType ||
@@ -2036,20 +1956,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2036
1956
  ? ""
2037
1957
  : renderValue(t, options)), ""),
2038
1958
  ...(parseAsBlock ? { chi: [] } : {}),
2039
- }), {
2040
- state: {
2041
- ...definedPropertySettings,
2042
- value: valid ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2043
- },
2044
- errors: {
2045
- ...definedPropertySettings,
2046
- value: valid ? [] : result.errors,
2047
- },
2048
- tokens: { ...definedPropertySettings, value: stream.slice() },
2049
- loc: {
2050
- ...definedPropertySettings,
2051
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2052
- },
2053
1959
  });
2054
1960
  }
2055
1961
  case "import": {
@@ -2063,8 +1969,12 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2063
1969
  stream.splice(0, 1, ...stream[0].chi);
2064
1970
  }
2065
1971
  }
1972
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
1973
+ atRule[TOKENS] = stream.slice();
1974
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
1975
+ atRule[ERRORS] = result.success ? [] : result.errors;
2066
1976
  // @ts-expect-error
2067
- return Object.defineProperties(Object.assign(atRule, {
1977
+ return Object.assign(atRule, {
2068
1978
  typ: EnumToken.AtRuleNodeType,
2069
1979
  val: stream.reduce((acc, t, index) => acc +
2070
1980
  (t.typ === EnumToken.CommentTokenType ||
@@ -2073,20 +1983,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2073
1983
  (stream.length < index + 3 || stream[index + 2]?.typ === EnumToken.WhitespaceTokenType))
2074
1984
  ? ""
2075
1985
  : renderValue(t, options)), ""),
2076
- }), {
2077
- state: {
2078
- ...definedPropertySettings,
2079
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2080
- },
2081
- errors: {
2082
- ...definedPropertySettings,
2083
- value: result.success ? [] : result.errors,
2084
- },
2085
- tokens: { ...definedPropertySettings, value: stream.slice() },
2086
- loc: {
2087
- ...definedPropertySettings,
2088
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2089
- },
2090
1986
  });
2091
1987
  }
2092
1988
  case "supports":
@@ -2131,7 +2027,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2131
2027
  errors.push({
2132
2028
  action: "drop",
2133
2029
  node: atRule,
2134
- location: atRule.loc,
2030
+ location: atRule[LOC],
2135
2031
  message: "at-rule @when is required before @else block",
2136
2032
  });
2137
2033
  }
@@ -2140,32 +2036,22 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2140
2036
  errors.push({
2141
2037
  action: "drop",
2142
2038
  node: atRule,
2143
- location: atRule.loc,
2039
+ location: atRule[LOC],
2144
2040
  message: "at-rule @else block is defined after last @else block",
2145
2041
  });
2146
2042
  }
2147
2043
  }
2148
2044
  // @ts-expect-error
2149
2045
  options = { ...options, minify: false, convertColor: false };
2046
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2047
+ atRule[TOKENS] = stream.slice();
2048
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2049
+ atRule[ERRORS] = result.success ? [] : [errors[errors.length - 1]].concat(result.errors);
2150
2050
  // @ts-expect-error
2151
- return Object.defineProperties(Object.assign(atRule, {
2051
+ return Object.assign(atRule, {
2152
2052
  typ: EnumToken.AtRuleNodeType,
2153
2053
  val: renderTokens(stream, options),
2154
2054
  chi: [],
2155
- }), {
2156
- state: {
2157
- ...definedPropertySettings,
2158
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2159
- },
2160
- errors: {
2161
- ...definedPropertySettings,
2162
- value: result.success ? [] : [errors[errors.length - 1]].concat(result.errors),
2163
- },
2164
- tokens: { ...definedPropertySettings, value: stream.slice() },
2165
- loc: {
2166
- ...definedPropertySettings,
2167
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2168
- },
2169
2055
  });
2170
2056
  }
2171
2057
  case "media": {
@@ -2174,25 +2060,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2174
2060
  if (result.errors.length > 0) {
2175
2061
  errors.push(...result.errors);
2176
2062
  }
2063
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2064
+ atRule[TOKENS] = stream.slice();
2065
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2066
+ atRule[ERRORS] = result.success ? [] : result.errors;
2177
2067
  // @ts-expect-error
2178
- return Object.defineProperties(Object.assign(atRule, {
2068
+ return Object.assign(atRule, {
2179
2069
  typ: EnumToken.AtRuleNodeType,
2180
2070
  val: renderTokens(stream, options),
2181
2071
  chi: [],
2182
- }), {
2183
- state: {
2184
- ...definedPropertySettings,
2185
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2186
- },
2187
- errors: {
2188
- ...definedPropertySettings,
2189
- value: result.success ? [] : result.errors,
2190
- },
2191
- tokens: { ...definedPropertySettings, value: stream.slice() },
2192
- loc: {
2193
- ...definedPropertySettings,
2194
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2195
- },
2196
2072
  });
2197
2073
  }
2198
2074
  case "scope": {
@@ -2204,7 +2080,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2204
2080
  errors.push({
2205
2081
  action: "drop",
2206
2082
  node: range[0] ?? atRule,
2207
- location: (range[0] ?? atRule).loc,
2083
+ location: (range[0] ?? atRule)[LOC],
2208
2084
  message: "expected '(' at start of @scope block",
2209
2085
  });
2210
2086
  success = false;
@@ -2213,7 +2089,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2213
2089
  errors.push({
2214
2090
  action: "drop",
2215
2091
  node: range.at(-1) ?? atRule,
2216
- location: (range.at(-1) ?? atRule).loc,
2092
+ location: (range.at(-1) ?? atRule)[LOC],
2217
2093
  message: "expected ')' at end of @scope block",
2218
2094
  });
2219
2095
  success = false;
@@ -2239,7 +2115,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2239
2115
  errors.push({
2240
2116
  action: "drop",
2241
2117
  node: stream[index],
2242
- location: stream[index]?.loc,
2118
+ location: stream[index]?.[LOC],
2243
2119
  message: "expected 'to' at end of @scope block",
2244
2120
  });
2245
2121
  success = false;
@@ -2252,7 +2128,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2252
2128
  errors.push({
2253
2129
  action: "drop",
2254
2130
  node: stream[index],
2255
- location: stream[index]?.loc,
2131
+ location: stream[index]?.[LOC],
2256
2132
  message: "expected 'to' at end of @scope block",
2257
2133
  });
2258
2134
  success = false;
@@ -2265,7 +2141,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2265
2141
  errors.push({
2266
2142
  action: "drop",
2267
2143
  node: range.at(-1) ?? atRule,
2268
- location: (range.at(-1) ?? atRule).loc,
2144
+ location: (range.at(-1) ?? atRule)[LOC],
2269
2145
  message: "expected ')' at end of @scope block",
2270
2146
  });
2271
2147
  success = false;
@@ -2284,48 +2160,28 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2284
2160
  }
2285
2161
  }
2286
2162
  }
2163
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2164
+ atRule[TOKENS] = stream.slice();
2165
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2166
+ atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
2287
2167
  // @ts-expect-error
2288
- return Object.defineProperties(Object.assign(atRule, {
2168
+ return Object.assign(atRule, {
2289
2169
  typ: EnumToken.AtRuleNodeType,
2290
2170
  val: renderTokens(stream, options),
2291
2171
  chi: [],
2292
- }), {
2293
- state: {
2294
- ...definedPropertySettings,
2295
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2296
- },
2297
- errors: {
2298
- ...definedPropertySettings,
2299
- value: success ? [] : [errors[errors.length - 1]],
2300
- },
2301
- tokens: { ...definedPropertySettings, value: stream.slice() },
2302
- loc: {
2303
- ...definedPropertySettings,
2304
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2305
- },
2306
2172
  });
2307
2173
  }
2308
2174
  case "page": {
2309
2175
  trimArray(stream);
2176
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2177
+ atRule[TOKENS] = stream.slice();
2178
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2179
+ atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
2310
2180
  // @ts-expect-error
2311
- return Object.defineProperties(Object.assign(atRule, {
2181
+ return Object.assign(atRule, {
2312
2182
  typ: EnumToken.AtRuleNodeType,
2313
2183
  val: renderTokens(stream, options),
2314
2184
  chi: [],
2315
- }), {
2316
- state: {
2317
- ...definedPropertySettings,
2318
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2319
- },
2320
- errors: {
2321
- ...definedPropertySettings,
2322
- value: success ? [] : [errors[errors.length - 1]],
2323
- },
2324
- tokens: { ...definedPropertySettings, value: stream.slice() },
2325
- loc: {
2326
- ...definedPropertySettings,
2327
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2328
- },
2329
2185
  });
2330
2186
  }
2331
2187
  case "top-left-corner":
@@ -2348,7 +2204,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2348
2204
  errors.push({
2349
2205
  action: "drop",
2350
2206
  node: atRule,
2351
- location: atRule.loc,
2207
+ location: atRule[LOC],
2352
2208
  message: "node is allowd only in @page rule",
2353
2209
  });
2354
2210
  }
@@ -2361,32 +2217,22 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2361
2217
  errors.push({
2362
2218
  action: "drop",
2363
2219
  node: stream[i],
2364
- location: stream[i].loc,
2220
+ location: stream[i][LOC],
2365
2221
  message: "expected whitespace or comment",
2366
2222
  });
2367
2223
  break;
2368
2224
  }
2369
2225
  }
2370
2226
  }
2227
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2228
+ atRule[TOKENS] = stream.slice();
2229
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2230
+ atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
2371
2231
  // @ts-expect-error
2372
- return Object.defineProperties(Object.assign(atRule, {
2232
+ return Object.assign(atRule, {
2373
2233
  typ: EnumToken.AtRuleNodeType,
2374
2234
  val: renderTokens(stream, options),
2375
2235
  chi: [],
2376
- }), {
2377
- state: {
2378
- ...definedPropertySettings,
2379
- value: success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2380
- },
2381
- errors: {
2382
- ...definedPropertySettings,
2383
- value: success ? [] : [errors[errors.length - 1]],
2384
- },
2385
- tokens: { ...definedPropertySettings, value: stream.slice() },
2386
- loc: {
2387
- ...definedPropertySettings,
2388
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2389
- },
2390
2236
  });
2391
2237
  }
2392
2238
  case "value": {
@@ -2398,12 +2244,10 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2398
2244
  typ: EnumToken.IdenTokenType,
2399
2245
  val: stream[index].val.slice(1),
2400
2246
  });
2401
- stream.splice(index, 0, Object.defineProperty({
2247
+ stream.splice(index, 0, {
2402
2248
  typ: EnumToken.ColonTokenType,
2403
- }, "loc", {
2404
- ...definedPropertySettings,
2405
- value: { ...stream[index].loc, end: { ...stream[index]?.loc?.sta } },
2406
- }));
2249
+ [LOC]: { ...stream[index][LOC], end: { ...stream[index]?.[LOC]?.sta } },
2250
+ });
2407
2251
  isVarDeclaration = true;
2408
2252
  break;
2409
2253
  }
@@ -2421,65 +2265,59 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2421
2265
  // @value id : <declaration-value>; // variable declaration
2422
2266
  // @value <ident># from <ident>; // import variables from alias
2423
2267
  let result = matchAllSyntaxes(syntaxRules?.getPreludeRules()?.slice?.(1), createValidationContext(stream), options);
2268
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2269
+ atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
2424
2270
  if (!result.success) {
2425
2271
  errors.push(...result.errors);
2426
- return Object.defineProperties({
2272
+ return {
2427
2273
  typ: EnumToken.AtRuleNodeType,
2428
2274
  val: renderTokens(stream, options),
2429
- }, {
2430
- state: {
2431
- ...definedPropertySettings,
2432
- value: EnumAstNodeStatus.Invalid,
2433
- },
2434
- errors: {
2435
- ...definedPropertySettings,
2436
- value: result.errors,
2437
- },
2438
- loc: {
2439
- ...definedPropertySettings,
2440
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2275
+ [LOC]: {
2276
+ ...atRule[LOC],
2277
+ end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) },
2441
2278
  },
2442
- });
2279
+ [TOKENS]: stream,
2280
+ [STATE]: EnumAstNodeStatus.Invalid,
2281
+ [ERRORS]: result.errors,
2282
+ };
2443
2283
  }
2444
2284
  if (isVarDeclaration) {
2445
2285
  const nam = stream.find((t) => t.typ == EnumToken.IdenTokenType);
2446
2286
  const value = trimArray(stream.slice(index + 1).filter((t) => t.typ != EnumToken.CommentTokenType));
2447
2287
  if (value.length == 1 && value[0].typ == EnumToken.StringTokenType) {
2448
2288
  // import from file as alias
2449
- return Object.defineProperties({
2289
+ return {
2450
2290
  typ: EnumToken.CssVariableImportTokenType,
2451
2291
  nam: nam.val,
2452
2292
  val: value,
2453
- }, {
2454
- loc: {
2455
- ...definedPropertySettings,
2456
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2293
+ [LOC]: {
2294
+ ...atRule[LOC],
2295
+ end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) },
2457
2296
  },
2458
- });
2297
+ [TOKENS]: stream,
2298
+ [STATE]: EnumAstNodeStatus.Validated,
2299
+ [ERRORS]: [],
2300
+ };
2459
2301
  }
2460
2302
  // import variables from alias
2461
- return Object.defineProperties({
2303
+ return {
2462
2304
  typ: EnumToken.CssVariableTokenType,
2463
2305
  nam: nam.val,
2464
2306
  val: value,
2465
- }, {
2466
- loc: {
2467
- ...definedPropertySettings,
2468
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2469
- },
2470
- });
2307
+ [LOC]: { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } },
2308
+ [TOKENS]: stream,
2309
+ [STATE]: EnumAstNodeStatus.Validated,
2310
+ [ERRORS]: [],
2311
+ };
2471
2312
  }
2313
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2314
+ atRule[STATE] = EnumAstNodeStatus.Validated;
2315
+ atRule[ERRORS] = [];
2472
2316
  // @ts-expect-error
2473
- return Object.defineProperties(Object.assign(atRule, {
2317
+ return Object.assign(atRule, {
2474
2318
  typ: EnumToken.CssVariableDeclarationMapTokenType,
2475
2319
  vars: trimArray(stream.slice(0, index)),
2476
2320
  from: stream.slice(index + 1),
2477
- }), {
2478
- tokens: { ...definedPropertySettings, value: stream.slice() },
2479
- loc: {
2480
- ...definedPropertySettings,
2481
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2482
- },
2483
2321
  });
2484
2322
  }
2485
2323
  default: {
@@ -2513,7 +2351,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2513
2351
  }
2514
2352
  if (stream[i].typ === EnumToken.EndParensTokenType && stack.length > 0) {
2515
2353
  const index = stream.indexOf(stack[stack.length - 1]);
2516
- stream[index].loc.end = stream[i].loc.end;
2354
+ stream[index][LOC].end = stream[i][LOC].end;
2517
2355
  Object.assign(stream[index], {
2518
2356
  typ: tokensfuncDefMap.get(stream[index].typ),
2519
2357
  chi: stream.splice(index + 1, i - index - 1),
@@ -2526,25 +2364,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2526
2364
  }
2527
2365
  }
2528
2366
  }
2367
+ atRule[LOC] = { ...atRule[LOC], end: { ...(stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end) } };
2368
+ atRule[TOKENS] = stream.slice();
2369
+ atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2370
+ atRule[ERRORS] = result.errors;
2529
2371
  // @ts-expect-error
2530
- return Object.defineProperties(Object.assign(atRule, {
2372
+ return Object.assign(atRule, {
2531
2373
  typ: EnumToken.AtRuleNodeType,
2532
2374
  val: renderTokens(trimWhiteSpaceTokens(stream), options),
2533
2375
  ...(parseAsBlock ? { chi: [] } : {}),
2534
- }), {
2535
- state: {
2536
- ...definedPropertySettings,
2537
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid,
2538
- },
2539
- errors: {
2540
- ...definedPropertySettings,
2541
- value: result.errors,
2542
- },
2543
- tokens: { ...definedPropertySettings, value: stream.slice() },
2544
- loc: {
2545
- ...definedPropertySettings,
2546
- value: { ...atRule.loc, end: { ...(stream.at(-1)?.loc?.end ?? atRule.loc.end) } },
2547
- },
2548
2376
  });
2549
2377
  }
2550
2378
  }
@@ -2568,8 +2396,7 @@ async function parseDeclarations(declaration) {
2568
2396
  position: { ind: 0, lin: 1, col: 1 },
2569
2397
  currentPosition: { ind: -1, lin: 1, col: 0 },
2570
2398
  }), { setParent: false, minify: false, validation: false }).then((result) => {
2571
- return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType ||
2572
- t.typ == EnumToken.CommentNodeType);
2399
+ return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType);
2573
2400
  });
2574
2401
  }
2575
2402
  /**
@@ -2651,7 +2478,7 @@ function parseTokens(tokens, options, errors) {
2651
2478
  val: (tokens[i - 1].typ === EnumToken.ColonTokenType ? ":" : "::") +
2652
2479
  tokens[i].val,
2653
2480
  });
2654
- t.loc.end = tokens[i].loc.end;
2481
+ t[LOC].end = tokens[i][LOC].end;
2655
2482
  tokens.splice(i--, 1);
2656
2483
  }
2657
2484
  }
@@ -2668,9 +2495,9 @@ function parseTokens(tokens, options, errors) {
2668
2495
  const node = stack.at(-1);
2669
2496
  errors?.push?.({
2670
2497
  action: "drop",
2671
- message: `Unbalanced token ')' at ${node.loc.src}:${node.loc.sta.lin}:${node.loc.sta.col}`,
2498
+ message: `Unbalanced token ')' at ${node[LOC].src}:${node[LOC].sta.lin}:${node[LOC].sta.col}`,
2672
2499
  node,
2673
- location: node.loc,
2500
+ location: node[LOC],
2674
2501
  });
2675
2502
  // return [];
2676
2503
  continue;
@@ -2696,16 +2523,16 @@ function parseTokens(tokens, options, errors) {
2696
2523
  const node = stack.at(-1);
2697
2524
  errors?.push?.({
2698
2525
  action: "drop",
2699
- message: `Unbalanced token ']' at ${node.loc.src}:${node.loc.sta.lin}:${node.loc.sta.col}`,
2526
+ message: `Unbalanced token ']' at ${node[LOC].src}:${node[LOC].sta.lin}:${node[LOC].sta.col}`,
2700
2527
  node,
2701
- location: node.loc,
2528
+ location: node[LOC],
2702
2529
  });
2703
2530
  // return [];
2704
2531
  continue;
2705
2532
  }
2706
2533
  index = tokens.indexOf(stack.at(-1));
2707
2534
  const attr = stack.at(-1);
2708
- attr.loc.end = t.loc.end;
2535
+ attr[LOC].end = t[LOC].end;
2709
2536
  tokens.splice(i, 1);
2710
2537
  Object.assign(attr, {
2711
2538
  typ: EnumToken.AttrTokenType,
@@ -2821,7 +2648,7 @@ function parseTokens(tokens, options, errors) {
2821
2648
  action: "drop",
2822
2649
  message: `Unbalanced token. Expecting ${node.typ === EnumToken.AttrStartTokenType ? "']'" : ")"}'`,
2823
2650
  node,
2824
- location: node.loc,
2651
+ location: node[LOC],
2825
2652
  });
2826
2653
  // return [];
2827
2654
  }