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