@tbela99/css-parser 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/README.md +10 -10
- package/dist/index-umd-web.js +5998 -4972
- package/dist/index.cjs +6001 -4977
- package/dist/index.d.ts +52 -38
- package/dist/lib/ast/expand.js +21 -7
- package/dist/lib/ast/features/calc.js +17 -55
- package/dist/lib/ast/features/if.js +7 -3
- package/dist/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/lib/ast/features/prefix.js +41 -44
- package/dist/lib/ast/features/shorthand.js +10 -5
- package/dist/lib/ast/features/transform.js +2 -2
- package/dist/lib/ast/math/expression.js +207 -34
- package/dist/lib/ast/minify.js +121 -24
- package/dist/lib/ast/node.js +5 -3
- package/dist/lib/ast/transform/compute.js +37 -5
- package/dist/lib/ast/transform/minify.js +7 -7
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +46 -18
- package/dist/lib/ast/walk.js +28 -4
- package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
- package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
- package/dist/lib/fs/resolve.js +11 -2
- package/dist/lib/parser/declaration/list.js +22 -7
- package/dist/lib/parser/declaration/map.js +26 -8
- package/dist/lib/parser/declaration/set.js +3 -1
- package/dist/lib/parser/linesmap.js +2 -4
- package/dist/lib/parser/parse.js +393 -231
- package/dist/lib/parser/tokenize.js +1478 -819
- package/dist/lib/parser/utils/at-rule-container.js +28 -196
- package/dist/lib/parser/utils/at-rule-generic.js +6 -7
- package/dist/lib/parser/utils/at-rule-import.js +17 -13
- package/dist/lib/parser/utils/at-rule-media.js +36 -19
- package/dist/lib/parser/utils/at-rule-support.js +19 -9
- package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
- package/dist/lib/parser/utils/at-rule.js +0 -18
- package/dist/lib/parser/utils/config.js +1 -1
- package/dist/lib/parser/utils/declaration.js +40 -97
- package/dist/lib/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +179 -224
- package/dist/lib/parser/utils/text.js +4 -2
- package/dist/lib/renderer/render.js +104 -74
- package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
- package/dist/lib/syntax/color/a98rgb.js +14 -4
- package/dist/lib/syntax/color/cmyk.js +14 -21
- package/dist/lib/syntax/color/color-mix.js +21 -34
- package/dist/lib/syntax/color/color.js +32 -49
- package/dist/lib/syntax/color/hsl.js +15 -15
- package/dist/lib/syntax/color/hwb.js +18 -17
- package/dist/lib/syntax/color/lab.js +17 -17
- package/dist/lib/syntax/color/lch.js +13 -13
- package/dist/lib/syntax/color/oklab.js +10 -11
- package/dist/lib/syntax/color/oklch.js +15 -18
- package/dist/lib/syntax/color/p3.js +18 -12
- package/dist/lib/syntax/color/prophotorgb.js +26 -28
- package/dist/lib/syntax/color/rec2020.js +8 -4
- package/dist/lib/syntax/color/relative-color.js +26 -10
- package/dist/lib/syntax/color/srgb.js +9 -7
- package/dist/lib/syntax/color/utils/distance.js +1 -1
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/color/xyzd50.js +2 -2
- package/dist/lib/syntax/constants.js +13 -3
- package/dist/lib/syntax/syntax.js +32 -108
- package/dist/lib/validation/config.js +1 -1
- package/dist/lib/validation/match.js +29 -26
- package/dist/lib/validation/parser/parse.js +7 -3
- package/dist/node.js +16 -9
- package/dist/types.d.ts +5 -1
- package/dist/types.js +4 -0
- package/dist/utils/sync.js +22 -1
- package/dist/web.js +13 -4
- package/package.json +4 -4
- package/llms.txt +0 -80
package/dist/lib/parser/parse.js
CHANGED
|
@@ -5,8 +5,8 @@ import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumO
|
|
|
5
5
|
import { minify } from '../ast/minify.js';
|
|
6
6
|
import { expand } from '../ast/expand.js';
|
|
7
7
|
import { walk, walkValues, WalkerEvent } from '../ast/walk.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Tokenizer } from './tokenize.js';
|
|
9
|
+
import { LOCSRCID, LOCSTA, LOCEND, tokensfuncDefMap, STATE, PARENT, TOKENS, ROOT, ERRORS, pageMarginBoxType } from '../syntax/constants.js';
|
|
10
10
|
import { hashAlgorithms, hash, syncHash } from './utils/hash.js';
|
|
11
11
|
import { parseSelector } from './utils/selector.js';
|
|
12
12
|
import { parseDeclaration } from './utils/declaration.js';
|
|
@@ -354,7 +354,9 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
else {
|
|
357
|
-
|
|
357
|
+
for (const val of Object.entries(value)) {
|
|
358
|
+
visitors.push(val);
|
|
359
|
+
}
|
|
358
360
|
}
|
|
359
361
|
}
|
|
360
362
|
else {
|
|
@@ -371,7 +373,6 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
371
373
|
.push(value);
|
|
372
374
|
}
|
|
373
375
|
else if (typeof value == "object") {
|
|
374
|
-
// visitors.push(...Object.entries(value));
|
|
375
376
|
if ("type" in value && "handler" in value && value.type in WalkerEvent) {
|
|
376
377
|
if (value.type == WalkerEvent.Enter) {
|
|
377
378
|
if (!preVisitorsHandlersMap.has(key)) {
|
|
@@ -439,7 +440,7 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
439
440
|
* @throws Error
|
|
440
441
|
* @private
|
|
441
442
|
*/
|
|
442
|
-
function doParseSync(
|
|
443
|
+
function doParseSync(tokenizer, options = {}) {
|
|
443
444
|
if (options.signal != null) {
|
|
444
445
|
options.signal.addEventListener("abort", reject);
|
|
445
446
|
}
|
|
@@ -501,46 +502,78 @@ function doParseSync(iter, options = {}) {
|
|
|
501
502
|
// @ts-ignore ignore error
|
|
502
503
|
let parensMatch = 0;
|
|
503
504
|
let curlyBracketMatch = 0;
|
|
504
|
-
let currentItemIndex;
|
|
505
|
-
|
|
506
|
-
ast[
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
505
|
+
// let currentItemIndex: number;
|
|
506
|
+
ast[LOCSRCID] = options.source.id;
|
|
507
|
+
ast[LOCSTA] = 0;
|
|
508
|
+
// let tokenizer: Tokenizer;
|
|
509
|
+
while (!tokenizer.done()) {
|
|
510
|
+
tokenizer.next();
|
|
511
|
+
// item = (iter as Array<TokenizeResult>)[currentItemIndex];
|
|
512
|
+
if (tokenizer.unit != null) {
|
|
513
|
+
item = {
|
|
514
|
+
typ: tokenizer.typ,
|
|
515
|
+
val: tokenizer.val,
|
|
516
|
+
unit: tokenizer.unit,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
else if (tokenizer.nam != null) {
|
|
520
|
+
item = {
|
|
521
|
+
typ: tokenizer.typ,
|
|
522
|
+
nam: tokenizer.nam,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
else if (tokenizer.val === null) {
|
|
526
|
+
item = {
|
|
527
|
+
typ: tokenizer.typ,
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
else if (tokenizer.kin != null) {
|
|
531
|
+
item = {
|
|
532
|
+
typ: tokenizer.typ,
|
|
533
|
+
val: tokenizer.val,
|
|
534
|
+
kin: tokenizer.kin,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
item = {
|
|
539
|
+
typ: tokenizer.typ,
|
|
540
|
+
val: tokenizer.val,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
item[LOCSRCID] = tokenizer.srcId;
|
|
544
|
+
item[LOCSTA] = tokenizer.sta;
|
|
545
|
+
item[LOCEND] = tokenizer.end;
|
|
546
|
+
stats.bytesIn = tokenizer.bytesIn;
|
|
514
547
|
stats.tokensCount++;
|
|
515
|
-
if (BadTokensTypes.includes(item.
|
|
516
|
-
tokens.push(item
|
|
548
|
+
if (BadTokensTypes.includes(item.typ)) {
|
|
549
|
+
tokens.push(item);
|
|
517
550
|
errors.push({
|
|
518
551
|
action: "drop",
|
|
519
552
|
message: "Bad token",
|
|
520
553
|
syntax: null,
|
|
521
|
-
node: item
|
|
522
|
-
location: options.source.getSourceLocation(item
|
|
554
|
+
node: item,
|
|
555
|
+
location: options.source.getSourceLocation(item[LOCSTA]),
|
|
523
556
|
});
|
|
524
557
|
// bad token
|
|
525
558
|
continue;
|
|
526
559
|
}
|
|
527
|
-
if (item.
|
|
560
|
+
if (item.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(item.typ)) {
|
|
528
561
|
parensMatch++;
|
|
529
562
|
}
|
|
530
|
-
else if (item.
|
|
563
|
+
else if (item.typ === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
531
564
|
parensMatch--;
|
|
532
565
|
}
|
|
533
|
-
if (item.
|
|
566
|
+
if (item.typ === EnumToken.BlockStartTokenType) {
|
|
534
567
|
curlyBracketMatch++;
|
|
535
568
|
}
|
|
536
|
-
else if (item.
|
|
569
|
+
else if (item.typ === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
537
570
|
curlyBracketMatch--;
|
|
538
571
|
}
|
|
539
|
-
tokens.push(item
|
|
572
|
+
tokens.push(item);
|
|
540
573
|
if (parensMatch === 0 &&
|
|
541
|
-
(item.
|
|
542
|
-
item.
|
|
543
|
-
item.
|
|
574
|
+
(item.typ === EnumToken.SemiColonTokenType ||
|
|
575
|
+
item.typ === EnumToken.BlockStartTokenType ||
|
|
576
|
+
item.typ === EnumToken.EOFTokenType)) {
|
|
544
577
|
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
545
578
|
if (node != null) {
|
|
546
579
|
if ("chi" in node) {
|
|
@@ -548,37 +581,67 @@ function doParseSync(iter, options = {}) {
|
|
|
548
581
|
context = node;
|
|
549
582
|
}
|
|
550
583
|
}
|
|
551
|
-
else if (item.
|
|
584
|
+
else if (item.typ == EnumToken.BlockStartTokenType) {
|
|
552
585
|
let inBlock = 1;
|
|
553
|
-
tokens =
|
|
586
|
+
tokens.length = 0;
|
|
587
|
+
tokens.push(item);
|
|
554
588
|
do {
|
|
555
|
-
|
|
556
|
-
if (
|
|
557
|
-
|
|
589
|
+
tokenizer.next();
|
|
590
|
+
if (tokenizer.unit != null) {
|
|
591
|
+
item = {
|
|
592
|
+
typ: tokenizer.typ,
|
|
593
|
+
val: tokenizer.val,
|
|
594
|
+
unit: tokenizer.unit,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
else if (tokenizer.nam != null) {
|
|
598
|
+
item = {
|
|
599
|
+
typ: tokenizer.typ,
|
|
600
|
+
nam: tokenizer.nam,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
else if (tokenizer.val === null) {
|
|
604
|
+
item = {
|
|
605
|
+
typ: tokenizer.typ,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
else if (tokenizer.kin != null) {
|
|
609
|
+
item = {
|
|
610
|
+
typ: tokenizer.typ,
|
|
611
|
+
val: tokenizer.val,
|
|
612
|
+
kin: tokenizer.kin,
|
|
613
|
+
};
|
|
558
614
|
}
|
|
559
|
-
|
|
560
|
-
|
|
615
|
+
else {
|
|
616
|
+
item = {
|
|
617
|
+
typ: tokenizer.typ,
|
|
618
|
+
val: tokenizer.val,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
item[LOCSRCID] = tokenizer.srcId;
|
|
622
|
+
item[LOCSTA] = tokenizer.sta;
|
|
623
|
+
item[LOCEND] = tokenizer.end;
|
|
624
|
+
tokens.push(item);
|
|
625
|
+
if (item.typ === EnumToken.BlockStartTokenType) {
|
|
561
626
|
inBlock++;
|
|
562
627
|
}
|
|
563
|
-
else if (item.
|
|
628
|
+
else if (item.typ === EnumToken.BlockEndTokenType) {
|
|
564
629
|
inBlock--;
|
|
565
630
|
}
|
|
566
|
-
} while (inBlock != 0);
|
|
631
|
+
} while (inBlock != 0 && !tokenizer.done());
|
|
567
632
|
if (tokens.length > 0) {
|
|
568
633
|
errors.push({
|
|
569
634
|
action: "drop",
|
|
570
635
|
message: "invalid block",
|
|
571
|
-
location: options.source.getSourceLocation(tokens[0][
|
|
636
|
+
location: options.source.getSourceLocation(tokens[0][LOCSTA]),
|
|
572
637
|
});
|
|
573
638
|
}
|
|
574
639
|
}
|
|
575
|
-
tokens =
|
|
640
|
+
tokens.length = 0;
|
|
576
641
|
}
|
|
577
|
-
else if ((parensMatch === 0 || curlyBracketMatch === 0) && item.
|
|
642
|
+
else if ((parensMatch === 0 || curlyBracketMatch === 0) && item.typ === EnumToken.BlockEndTokenType) {
|
|
578
643
|
parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
579
|
-
|
|
580
|
-
context[LOC].end = item.token[LOC].end;
|
|
581
|
-
}
|
|
644
|
+
context[LOCEND] = item[LOCEND];
|
|
582
645
|
const previousNode = stack.pop();
|
|
583
646
|
context = (stack[stack.length - 1] ?? ast);
|
|
584
647
|
if (options.removeEmpty &&
|
|
@@ -587,7 +650,7 @@ function doParseSync(iter, options = {}) {
|
|
|
587
650
|
context.chi[context.chi.length - 1] == previousNode) {
|
|
588
651
|
context.chi.pop();
|
|
589
652
|
}
|
|
590
|
-
tokens =
|
|
653
|
+
tokens.length = 0;
|
|
591
654
|
parensMatch = 0;
|
|
592
655
|
curlyBracketMatch = 0;
|
|
593
656
|
}
|
|
@@ -630,17 +693,23 @@ function doParseSync(iter, options = {}) {
|
|
|
630
693
|
case EnumToken.AtRuleNodeType:
|
|
631
694
|
case EnumToken.KeyframesRuleNodeType:
|
|
632
695
|
case EnumToken.KeyframesAtRuleNodeType:
|
|
633
|
-
|
|
696
|
+
for (const token of nodes[i][TOKENS]) {
|
|
697
|
+
subNodes.push(token);
|
|
698
|
+
}
|
|
634
699
|
break;
|
|
635
700
|
case EnumToken.DeclarationNodeType:
|
|
636
|
-
|
|
701
|
+
for (const token of nodes[i].val) {
|
|
702
|
+
subNodes.push(token);
|
|
703
|
+
}
|
|
637
704
|
break;
|
|
638
705
|
}
|
|
639
706
|
}
|
|
640
707
|
// @ts-ignore
|
|
641
708
|
if (nodes[i].chi != null) {
|
|
642
709
|
// @ts-ignore
|
|
643
|
-
|
|
710
|
+
for (const child of nodes[i].chi) {
|
|
711
|
+
subNodes.push(child);
|
|
712
|
+
}
|
|
644
713
|
}
|
|
645
714
|
if (subNodes.length > 0) {
|
|
646
715
|
if (freeBlock <= i) {
|
|
@@ -802,7 +871,7 @@ function doParseSync(iter, options = {}) {
|
|
|
802
871
|
...stats,
|
|
803
872
|
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
804
873
|
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
805
|
-
tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
|
|
874
|
+
// tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
|
|
806
875
|
total: `${(endTime - startTime).toFixed(2)}ms`,
|
|
807
876
|
},
|
|
808
877
|
};
|
|
@@ -831,7 +900,7 @@ function doParseSync(iter, options = {}) {
|
|
|
831
900
|
: (moduleSettings.filePath ?? options.src);
|
|
832
901
|
filePath =
|
|
833
902
|
filePath === ""
|
|
834
|
-
? options.src
|
|
903
|
+
? options.resolve(options.src, options.cwd).relative
|
|
835
904
|
: options.resolve(filePath, options.dirname(options.src), options.cwd).relative;
|
|
836
905
|
if (typeof options.module == "number") {
|
|
837
906
|
if (options.module & ModuleCaseTransformEnum.CamelCase) {
|
|
@@ -876,7 +945,7 @@ function doParseSync(iter, options = {}) {
|
|
|
876
945
|
for (const { node, parent } of walk(ast)) {
|
|
877
946
|
if (node.typ == EnumToken.CssVariableImportTokenType) {
|
|
878
947
|
throw new Error("css variable import not supported by parseSync() or transformSync(). use parse() or transform() instead.\nat " +
|
|
879
|
-
options.source.getSourceLocation(node[
|
|
948
|
+
options.source.getSourceLocation(node[LOCSTA]).join(":"));
|
|
880
949
|
}
|
|
881
950
|
// @ts-ignore
|
|
882
951
|
if (node.typ == EnumToken.CssVariableDeclarationMapTokenType) {
|
|
@@ -995,7 +1064,7 @@ function doParseSync(iter, options = {}) {
|
|
|
995
1064
|
}
|
|
996
1065
|
// composes: a b c from 'file.css';
|
|
997
1066
|
else if (token.r.typ == EnumToken.String) {
|
|
998
|
-
throw new Error(`composes from file is not supported using parseSync() or transformSync(). Use parse() or transform() instead.\nat ${options.source.getSourceLocation(node[
|
|
1067
|
+
throw new Error(`composes from file is not supported using parseSync() or transformSync(). Use parse() or transform() instead.\nat ${options.source.getSourceLocation(node[LOCSTA]).join(":")}`);
|
|
999
1068
|
}
|
|
1000
1069
|
// composes: a b c from global;
|
|
1001
1070
|
else if (token.r.typ == EnumToken.IdenTokenType) {
|
|
@@ -1229,7 +1298,7 @@ function doParseSync(iter, options = {}) {
|
|
|
1229
1298
|
}
|
|
1230
1299
|
if (moduleSettings.scoped & ModuleScopeEnumOptions.Pure) {
|
|
1231
1300
|
if (!hasIdOrClass) {
|
|
1232
|
-
throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${options.source.getOffsets(node[
|
|
1301
|
+
throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${options.source.getOffsets(node[LOCSTA]).join(":")}'`);
|
|
1233
1302
|
}
|
|
1234
1303
|
}
|
|
1235
1304
|
node.sel = "";
|
|
@@ -1362,56 +1431,84 @@ async function doParse(iter, options = {}) {
|
|
|
1362
1431
|
const imports = [];
|
|
1363
1432
|
let item;
|
|
1364
1433
|
let node;
|
|
1365
|
-
// @ts-ignore ignore error
|
|
1366
|
-
let isAsync = typeof iter[Symbol.asyncIterator] === "function";
|
|
1367
1434
|
let parensMatch = 0;
|
|
1368
1435
|
let curlyBracketMatch = 0;
|
|
1436
|
+
let tokenizer = iter instanceof Promise ? await iter : iter;
|
|
1369
1437
|
// ast[ROOT] = ast;
|
|
1370
|
-
ast[
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1438
|
+
ast[LOCSRCID] = options.source.id;
|
|
1439
|
+
ast[LOCSTA] = 0;
|
|
1440
|
+
ast[LOCEND] = 0;
|
|
1441
|
+
// if (Array.isArray(iter)) {
|
|
1442
|
+
// // @ts-expect-error
|
|
1443
|
+
// iter = iter[Symbol.iterator]() as Iterator<TokenizeResult>;
|
|
1444
|
+
// }
|
|
1445
|
+
while (!tokenizer.done()) {
|
|
1446
|
+
tokenizer.next();
|
|
1447
|
+
if (tokenizer.unit != null) {
|
|
1448
|
+
item = {
|
|
1449
|
+
typ: tokenizer.typ,
|
|
1450
|
+
val: tokenizer.val,
|
|
1451
|
+
unit: tokenizer.unit,
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
else if (tokenizer.nam != null) {
|
|
1455
|
+
item = {
|
|
1456
|
+
typ: tokenizer.typ,
|
|
1457
|
+
nam: tokenizer.nam,
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
else if (tokenizer.val === null) {
|
|
1461
|
+
item = {
|
|
1462
|
+
typ: tokenizer.typ,
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
else if (tokenizer.kin != null) {
|
|
1466
|
+
item = {
|
|
1467
|
+
typ: tokenizer.typ,
|
|
1468
|
+
val: tokenizer.val,
|
|
1469
|
+
kin: tokenizer.kin,
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1472
|
+
else {
|
|
1473
|
+
item = {
|
|
1474
|
+
typ: tokenizer.typ,
|
|
1475
|
+
val: tokenizer.val,
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
item[LOCSRCID] = tokenizer.srcId;
|
|
1479
|
+
item[LOCSTA] = tokenizer.sta;
|
|
1480
|
+
item[LOCEND] = tokenizer.end;
|
|
1481
|
+
stats.bytesIn = tokenizer.bytesIn;
|
|
1385
1482
|
stats.tokensCount++;
|
|
1386
|
-
if (BadTokensTypes.includes(item.
|
|
1387
|
-
tokens.push(item
|
|
1483
|
+
if (BadTokensTypes.includes(item.typ)) {
|
|
1484
|
+
tokens.push(item);
|
|
1388
1485
|
errors.push({
|
|
1389
1486
|
action: "drop",
|
|
1390
1487
|
message: "Bad token",
|
|
1391
1488
|
syntax: null,
|
|
1392
|
-
node: item
|
|
1393
|
-
location: options.source.getSourceLocation(item
|
|
1489
|
+
node: item,
|
|
1490
|
+
location: options.source.getSourceLocation(item[LOCSTA]),
|
|
1394
1491
|
});
|
|
1395
1492
|
// bad token
|
|
1396
1493
|
continue;
|
|
1397
1494
|
}
|
|
1398
|
-
if (item.
|
|
1495
|
+
if (item.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(item.typ)) {
|
|
1399
1496
|
parensMatch++;
|
|
1400
1497
|
}
|
|
1401
|
-
else if (item.
|
|
1498
|
+
else if (item.typ === EnumToken.EndParensTokenType && parensMatch > 0) {
|
|
1402
1499
|
parensMatch--;
|
|
1403
1500
|
}
|
|
1404
|
-
if (item.
|
|
1501
|
+
if (item.typ === EnumToken.BlockStartTokenType) {
|
|
1405
1502
|
curlyBracketMatch++;
|
|
1406
1503
|
}
|
|
1407
|
-
else if (item.
|
|
1504
|
+
else if (item.typ === EnumToken.BlockEndTokenType && curlyBracketMatch > 0) {
|
|
1408
1505
|
curlyBracketMatch--;
|
|
1409
1506
|
}
|
|
1410
|
-
tokens.push(item
|
|
1507
|
+
tokens.push(item);
|
|
1411
1508
|
if (parensMatch === 0 &&
|
|
1412
|
-
(item.
|
|
1413
|
-
item.
|
|
1414
|
-
item.
|
|
1509
|
+
(item.typ === EnumToken.SemiColonTokenType ||
|
|
1510
|
+
item.typ === EnumToken.BlockStartTokenType ||
|
|
1511
|
+
item.typ === EnumToken.EOFTokenType)) {
|
|
1415
1512
|
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
1416
1513
|
if (node != null) {
|
|
1417
1514
|
if ("chi" in node) {
|
|
@@ -1422,41 +1519,67 @@ async function doParse(iter, options = {}) {
|
|
|
1422
1519
|
imports.push(node);
|
|
1423
1520
|
}
|
|
1424
1521
|
}
|
|
1425
|
-
else if (item.
|
|
1522
|
+
else if (item.typ == EnumToken.BlockStartTokenType) {
|
|
1426
1523
|
let inBlock = 1;
|
|
1427
|
-
tokens =
|
|
1524
|
+
tokens.length = 0;
|
|
1525
|
+
tokens.push(item);
|
|
1428
1526
|
do {
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1527
|
+
tokenizer.next();
|
|
1528
|
+
if (tokenizer.unit != null) {
|
|
1529
|
+
item = {
|
|
1530
|
+
typ: tokenizer.typ,
|
|
1531
|
+
val: tokenizer.val,
|
|
1532
|
+
unit: tokenizer.unit,
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
else if (tokenizer.nam != null) {
|
|
1536
|
+
item = {
|
|
1537
|
+
typ: tokenizer.typ,
|
|
1538
|
+
nam: tokenizer.nam,
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
else if (tokenizer.val === null) {
|
|
1542
|
+
item = {
|
|
1543
|
+
typ: tokenizer.typ,
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
else if (tokenizer.kin != null) {
|
|
1547
|
+
item = {
|
|
1548
|
+
typ: tokenizer.typ,
|
|
1549
|
+
val: tokenizer.val,
|
|
1550
|
+
kin: tokenizer.kin,
|
|
1551
|
+
};
|
|
1436
1552
|
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1553
|
+
else {
|
|
1554
|
+
item = {
|
|
1555
|
+
typ: tokenizer.typ,
|
|
1556
|
+
val: tokenizer.val,
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
item[LOCSRCID] = tokenizer.srcId;
|
|
1560
|
+
item[LOCSTA] = tokenizer.sta;
|
|
1561
|
+
item[LOCEND] = tokenizer.end;
|
|
1562
|
+
tokens.push(item);
|
|
1563
|
+
if (item.typ === EnumToken.BlockStartTokenType) {
|
|
1439
1564
|
inBlock++;
|
|
1440
1565
|
}
|
|
1441
|
-
else if (item.
|
|
1566
|
+
else if (item.typ === EnumToken.BlockEndTokenType) {
|
|
1442
1567
|
inBlock--;
|
|
1443
1568
|
}
|
|
1444
|
-
} while (inBlock != 0);
|
|
1569
|
+
} while (inBlock != 0 && !tokenizer.done());
|
|
1445
1570
|
if (tokens.length > 0) {
|
|
1446
1571
|
errors.push({
|
|
1447
1572
|
action: "drop",
|
|
1448
1573
|
message: "invalid block",
|
|
1449
|
-
location: options.source.getSourceLocation(tokens[0][
|
|
1574
|
+
location: options.source.getSourceLocation(tokens[0][LOCSTA]),
|
|
1450
1575
|
});
|
|
1451
1576
|
}
|
|
1452
1577
|
}
|
|
1453
|
-
tokens =
|
|
1578
|
+
tokens.length = 0;
|
|
1454
1579
|
}
|
|
1455
|
-
else if ((parensMatch === 0 || curlyBracketMatch === 0) && item.
|
|
1580
|
+
else if ((parensMatch === 0 || curlyBracketMatch === 0) && item.typ === EnumToken.BlockEndTokenType) {
|
|
1456
1581
|
parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
1457
|
-
|
|
1458
|
-
context[LOC].end = item.token[LOC].end;
|
|
1459
|
-
}
|
|
1582
|
+
context[LOCEND] = item[LOCEND];
|
|
1460
1583
|
const previousNode = stack.pop();
|
|
1461
1584
|
context = (stack[stack.length - 1] ?? ast);
|
|
1462
1585
|
if (options.removeEmpty &&
|
|
@@ -1465,7 +1588,7 @@ async function doParse(iter, options = {}) {
|
|
|
1465
1588
|
context.chi[context.chi.length - 1] == previousNode) {
|
|
1466
1589
|
context.chi.pop();
|
|
1467
1590
|
}
|
|
1468
|
-
tokens =
|
|
1591
|
+
tokens.length = 0;
|
|
1469
1592
|
parensMatch = 0;
|
|
1470
1593
|
curlyBracketMatch = 0;
|
|
1471
1594
|
}
|
|
@@ -1504,8 +1627,11 @@ async function doParse(iter, options = {}) {
|
|
|
1504
1627
|
source,
|
|
1505
1628
|
position: 0,
|
|
1506
1629
|
currentPosition: 0,
|
|
1630
|
+
time: 0,
|
|
1507
1631
|
};
|
|
1508
|
-
const root = await doParse(stream instanceof ReadableStream
|
|
1632
|
+
const root = await doParse(stream instanceof ReadableStream
|
|
1633
|
+
? new Tokenizer(parseInfo, stream).tokenizeStream()
|
|
1634
|
+
: new Tokenizer(parseInfo), Object.assign({}, options, {
|
|
1509
1635
|
minify: false,
|
|
1510
1636
|
setParent: false,
|
|
1511
1637
|
src: options.resolve(url, options.src || options.cwd).relative,
|
|
@@ -1517,7 +1643,9 @@ async function doParse(iter, options = {}) {
|
|
|
1517
1643
|
// @ts-ignore
|
|
1518
1644
|
node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1, ...root.ast.chi);
|
|
1519
1645
|
if (root.errors.length > 0) {
|
|
1520
|
-
|
|
1646
|
+
for (const error of root.errors) {
|
|
1647
|
+
errors.push(error);
|
|
1648
|
+
}
|
|
1521
1649
|
}
|
|
1522
1650
|
}
|
|
1523
1651
|
catch (error) {
|
|
@@ -1554,17 +1682,24 @@ async function doParse(iter, options = {}) {
|
|
|
1554
1682
|
case EnumToken.AtRuleNodeType:
|
|
1555
1683
|
case EnumToken.KeyframesRuleNodeType:
|
|
1556
1684
|
case EnumToken.KeyframesAtRuleNodeType:
|
|
1557
|
-
|
|
1685
|
+
for (const token of nodes[i][TOKENS]) {
|
|
1686
|
+
subNodes.push(token);
|
|
1687
|
+
}
|
|
1558
1688
|
break;
|
|
1559
1689
|
case EnumToken.DeclarationNodeType:
|
|
1560
|
-
|
|
1690
|
+
for (const token of nodes[i].val) {
|
|
1691
|
+
subNodes.push(token);
|
|
1692
|
+
}
|
|
1561
1693
|
break;
|
|
1562
1694
|
}
|
|
1563
1695
|
}
|
|
1564
1696
|
// @ts-ignore
|
|
1565
1697
|
if (nodes[i].chi != null) {
|
|
1566
1698
|
// @ts-ignore
|
|
1567
|
-
|
|
1699
|
+
for (k = 0; k < nodes[i].chi.length; k++) {
|
|
1700
|
+
// @ts-ignore
|
|
1701
|
+
subNodes.push(nodes[i].chi[k]);
|
|
1702
|
+
}
|
|
1568
1703
|
}
|
|
1569
1704
|
if (subNodes.length > 0) {
|
|
1570
1705
|
if (freeblock <= i) {
|
|
@@ -1729,7 +1864,7 @@ async function doParse(iter, options = {}) {
|
|
|
1729
1864
|
...stats,
|
|
1730
1865
|
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
1731
1866
|
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
1732
|
-
tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
|
|
1867
|
+
// tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
|
|
1733
1868
|
total: `${(endTime - startTime).toFixed(2)}ms`,
|
|
1734
1869
|
},
|
|
1735
1870
|
};
|
|
@@ -1758,7 +1893,7 @@ async function doParse(iter, options = {}) {
|
|
|
1758
1893
|
: (moduleSettings.filePath ?? options.src);
|
|
1759
1894
|
filePath =
|
|
1760
1895
|
filePath === ""
|
|
1761
|
-
? options.src
|
|
1896
|
+
? options.resolve(options.src, options.cwd).relative
|
|
1762
1897
|
: options.resolve(filePath, options.dirname(options.src), options.cwd).relative;
|
|
1763
1898
|
if (typeof options.module == "number") {
|
|
1764
1899
|
if (options.module & ModuleCaseTransformEnum.CamelCase) {
|
|
@@ -1819,13 +1954,15 @@ async function doParse(iter, options = {}) {
|
|
|
1819
1954
|
position: 0,
|
|
1820
1955
|
currentPosition: 0,
|
|
1821
1956
|
};
|
|
1822
|
-
const root = await doParse(stream instanceof ReadableStream
|
|
1957
|
+
const root = await doParse(stream instanceof ReadableStream
|
|
1958
|
+
? new Tokenizer(parseInfo, stream).tokenizeStream()
|
|
1959
|
+
: new Tokenizer(parseInfo), Object.assign({}, options, {
|
|
1823
1960
|
source,
|
|
1824
1961
|
minify: false,
|
|
1825
1962
|
setParent: false,
|
|
1826
1963
|
src: src.relative,
|
|
1827
1964
|
}));
|
|
1828
|
-
options.parseInfo
|
|
1965
|
+
// options.parseInfo!.time += parseInfo.time;
|
|
1829
1966
|
cssVariablesMap[node.nam] = root.cssModuleVariables;
|
|
1830
1967
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
1831
1968
|
continue;
|
|
@@ -1960,13 +2097,13 @@ async function doParse(iter, options = {}) {
|
|
|
1960
2097
|
? await result
|
|
1961
2098
|
: result;
|
|
1962
2099
|
const root = await doParse(stream instanceof ReadableStream
|
|
1963
|
-
?
|
|
2100
|
+
? new Tokenizer({
|
|
1964
2101
|
offset: 0,
|
|
1965
2102
|
source: new SourceFile("", [], src.relative),
|
|
1966
2103
|
position: 0,
|
|
1967
2104
|
currentPosition: 0,
|
|
1968
|
-
})
|
|
1969
|
-
:
|
|
2105
|
+
}, stream).tokenizeStream()
|
|
2106
|
+
: new Tokenizer({
|
|
1970
2107
|
stream,
|
|
1971
2108
|
offset: 0,
|
|
1972
2109
|
position: 0,
|
|
@@ -2265,7 +2402,7 @@ async function doParse(iter, options = {}) {
|
|
|
2265
2402
|
}
|
|
2266
2403
|
if (moduleSettings.scoped & ModuleScopeEnumOptions.Pure) {
|
|
2267
2404
|
if (!hasIdOrClass) {
|
|
2268
|
-
throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${(options.source?.getOffsets?.(node[
|
|
2405
|
+
throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${(options.source?.getOffsets?.(node[LOCSTA]) ?? []).join(":")}'`);
|
|
2269
2406
|
}
|
|
2270
2407
|
}
|
|
2271
2408
|
node.sel = "";
|
|
@@ -2302,31 +2439,6 @@ async function doParse(iter, options = {}) {
|
|
|
2302
2439
|
}
|
|
2303
2440
|
node.val = renderTokens(node[TOKENS]);
|
|
2304
2441
|
}
|
|
2305
|
-
// else {
|
|
2306
|
-
// let isReplaced: boolean = false;
|
|
2307
|
-
// for (const { value, parent } of walkValues(node[TOKENS], node)) {
|
|
2308
|
-
// if (
|
|
2309
|
-
// EnumToken.MediaQueryConditionTokenType == parent.typ &&
|
|
2310
|
-
// // @ts-expect-error
|
|
2311
|
-
// value != (parent as MediaQueryConditionToken).l
|
|
2312
|
-
// ) {
|
|
2313
|
-
// if (
|
|
2314
|
-
// (value.typ == EnumToken.IdenTokenType || isIdentColor(value)) &&
|
|
2315
|
-
// (value as IdentToken).val in importedCssVariables
|
|
2316
|
-
// ) {
|
|
2317
|
-
// isReplaced = true;
|
|
2318
|
-
// (parent as MediaQueryConditionToken).r.splice(
|
|
2319
|
-
// (parent as MediaQueryConditionToken).r.indexOf(value),
|
|
2320
|
-
// 1,
|
|
2321
|
-
// ...importedCssVariables[(value as IdentToken).val].val,
|
|
2322
|
-
// );
|
|
2323
|
-
// }
|
|
2324
|
-
// }
|
|
2325
|
-
// }
|
|
2326
|
-
// if (isReplaced) {
|
|
2327
|
-
// node.val = renderTokens(node[TOKENS]!);
|
|
2328
|
-
// }
|
|
2329
|
-
// }
|
|
2330
2442
|
}
|
|
2331
2443
|
}
|
|
2332
2444
|
if (moduleSettings.naming != ModuleCaseTransformEnum.IgnoreCase) {
|
|
@@ -2358,7 +2470,6 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2358
2470
|
tokens.pop();
|
|
2359
2471
|
// check parenthesis are balanced
|
|
2360
2472
|
let matchCount = 0;
|
|
2361
|
-
let position = tokens.at(-1)?.[LOC];
|
|
2362
2473
|
for (let i = 0; i < tokens.length; i++) {
|
|
2363
2474
|
const token = tokens[i];
|
|
2364
2475
|
if (token.typ === EnumToken.StartParensTokenType || tokensfuncDefMap.has(token.typ)) {
|
|
@@ -2379,7 +2490,9 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2379
2490
|
while (matchCount > 0) {
|
|
2380
2491
|
tokens.push({
|
|
2381
2492
|
typ: EnumToken.EndParensTokenType,
|
|
2382
|
-
[
|
|
2493
|
+
[LOCSRCID]: tokens[k]?.[LOCSRCID],
|
|
2494
|
+
[LOCSTA]: tokens[k]?.[LOCSTA],
|
|
2495
|
+
[LOCEND]: tokens[k]?.[LOCEND],
|
|
2383
2496
|
});
|
|
2384
2497
|
matchCount--;
|
|
2385
2498
|
}
|
|
@@ -2391,7 +2504,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2391
2504
|
action: "drop",
|
|
2392
2505
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
2393
2506
|
node: tokens[i],
|
|
2394
|
-
location: options.source.getSourceLocation(tokens[i][
|
|
2507
|
+
location: options.source.getSourceLocation(tokens[i][LOCSTA]),
|
|
2395
2508
|
});
|
|
2396
2509
|
tokens[i].typ = EnumToken.InvalidCommentTokenType;
|
|
2397
2510
|
continue;
|
|
@@ -2414,7 +2527,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2414
2527
|
action: "drop",
|
|
2415
2528
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
2416
2529
|
node: tokens[i],
|
|
2417
|
-
location: options.source.getSourceLocation(tokens[i][
|
|
2530
|
+
location: options.source.getSourceLocation(tokens[i][LOCSTA]),
|
|
2418
2531
|
});
|
|
2419
2532
|
tokens[i].typ = EnumToken.InvalidCommentTokenType;
|
|
2420
2533
|
continue;
|
|
@@ -2495,7 +2608,7 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
2495
2608
|
message: "<declaration> not allowed in <stylesheet>",
|
|
2496
2609
|
action: "drop",
|
|
2497
2610
|
node,
|
|
2498
|
-
location: options.source.getSourceLocation(node[
|
|
2611
|
+
location: options.source.getSourceLocation(node[LOCSTA]),
|
|
2499
2612
|
});
|
|
2500
2613
|
}
|
|
2501
2614
|
else if (options.lenient || node.typ === EnumToken.DeclarationNodeType) {
|
|
@@ -2534,7 +2647,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2534
2647
|
errors.push({
|
|
2535
2648
|
action: "drop",
|
|
2536
2649
|
node: atRule,
|
|
2537
|
-
location: options.source.getSourceLocation(atRule[
|
|
2650
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2538
2651
|
message: "unknown at-rule",
|
|
2539
2652
|
});
|
|
2540
2653
|
const result = matchGenericSyntax(stream, options);
|
|
@@ -2555,7 +2668,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2555
2668
|
errors.push({
|
|
2556
2669
|
action: "drop",
|
|
2557
2670
|
node: atRule,
|
|
2558
|
-
location: options.source.getSourceLocation(atRule[
|
|
2671
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2559
2672
|
message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
|
|
2560
2673
|
});
|
|
2561
2674
|
atRule[TOKENS] = parseTokens(stream);
|
|
@@ -2573,8 +2686,8 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2573
2686
|
errors.push({
|
|
2574
2687
|
action: "drop",
|
|
2575
2688
|
node: token,
|
|
2576
|
-
location: options.source.getSourceLocation(token[
|
|
2577
|
-
message: `unexpected token
|
|
2689
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
2690
|
+
message: `unexpected token`,
|
|
2578
2691
|
});
|
|
2579
2692
|
atRule[TOKENS] = parseTokens(stream);
|
|
2580
2693
|
atRule[STATE] = EnumAstNodeStatus.Invalid;
|
|
@@ -2594,7 +2707,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2594
2707
|
errors.push({
|
|
2595
2708
|
action: "drop",
|
|
2596
2709
|
node: atRule,
|
|
2597
|
-
location: options.source.getSourceLocation(atRule[
|
|
2710
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2598
2711
|
message: parseAsBlock ? "at-rule block not supported" : "at-rule block is required",
|
|
2599
2712
|
});
|
|
2600
2713
|
atRule[TOKENS] = parseTokens(stream);
|
|
@@ -2617,7 +2730,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2617
2730
|
errors.push({
|
|
2618
2731
|
action: "drop",
|
|
2619
2732
|
node: stream[0] ?? atRule,
|
|
2620
|
-
location: options.source.getSourceLocation((stream[0] ?? atRule)[
|
|
2733
|
+
location: options.source.getSourceLocation((stream[0] ?? atRule)[LOCSTA]),
|
|
2621
2734
|
message: "expecting <space>",
|
|
2622
2735
|
});
|
|
2623
2736
|
}
|
|
@@ -2626,7 +2739,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2626
2739
|
errors.push({
|
|
2627
2740
|
action: "drop",
|
|
2628
2741
|
node: stream[1] ?? atRule,
|
|
2629
|
-
location: options.source.getSourceLocation((stream[1] ?? atRule)[
|
|
2742
|
+
location: options.source.getSourceLocation((stream[1] ?? atRule)[LOCSTA]),
|
|
2630
2743
|
message: "expecting <string>",
|
|
2631
2744
|
});
|
|
2632
2745
|
}
|
|
@@ -2635,7 +2748,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2635
2748
|
errors.push({
|
|
2636
2749
|
action: "drop",
|
|
2637
2750
|
node: stream[1] ?? atRule,
|
|
2638
|
-
location: options.source.getSourceLocation((stream[1] ?? atRule)[
|
|
2751
|
+
location: options.source.getSourceLocation((stream[1] ?? atRule)[LOCSTA]),
|
|
2639
2752
|
message: "expecting double-quoted string",
|
|
2640
2753
|
});
|
|
2641
2754
|
}
|
|
@@ -2643,7 +2756,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2643
2756
|
atRule[TOKENS] = stream;
|
|
2644
2757
|
atRule[STATE] = EnumAstNodeStatus.Invalid;
|
|
2645
2758
|
atRule[ERRORS] = [errors[errors.length - 1]];
|
|
2646
|
-
atRule[
|
|
2759
|
+
atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
|
|
2647
2760
|
// @ts-expect-error
|
|
2648
2761
|
return Object.assign(atRule, {
|
|
2649
2762
|
typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
|
|
@@ -2656,7 +2769,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2656
2769
|
atRule[TOKENS] = stream;
|
|
2657
2770
|
atRule[STATE] = EnumAstNodeStatus.Validated;
|
|
2658
2771
|
atRule[ERRORS] = [];
|
|
2659
|
-
atRule[
|
|
2772
|
+
atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
|
|
2660
2773
|
// @ts-expect-error
|
|
2661
2774
|
return Object.assign(atRule, {
|
|
2662
2775
|
typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
|
|
@@ -2666,12 +2779,14 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2666
2779
|
case "font-feature-values": {
|
|
2667
2780
|
const result = parseAtRuleFontFeatureValues(stream, atRule, options);
|
|
2668
2781
|
if (result.errors.length > 0) {
|
|
2669
|
-
|
|
2782
|
+
for (const error of result.errors) {
|
|
2783
|
+
errors.push(error);
|
|
2784
|
+
}
|
|
2670
2785
|
}
|
|
2671
2786
|
atRule[TOKENS] = stream;
|
|
2672
2787
|
atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2673
2788
|
atRule[ERRORS] = result.success ? [] : result.errors;
|
|
2674
|
-
atRule[
|
|
2789
|
+
atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
|
|
2675
2790
|
// @ts-expect-error
|
|
2676
2791
|
return Object.assign(atRule, {
|
|
2677
2792
|
typ: EnumToken.AtRuleNodeType,
|
|
@@ -2690,7 +2805,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2690
2805
|
errors.push({
|
|
2691
2806
|
action: "drop",
|
|
2692
2807
|
node: atRule,
|
|
2693
|
-
location: options.source.getSourceLocation(atRule[
|
|
2808
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2694
2809
|
message: `unexpected at-rule ${atRule.nam}`,
|
|
2695
2810
|
});
|
|
2696
2811
|
}
|
|
@@ -2701,13 +2816,13 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2701
2816
|
errors.push({
|
|
2702
2817
|
action: "drop",
|
|
2703
2818
|
node: token,
|
|
2704
|
-
location: options.source.getSourceLocation(token[
|
|
2705
|
-
message: `unexpected token
|
|
2819
|
+
location: options.source.getSourceLocation(token[LOCSTA]),
|
|
2820
|
+
message: `unexpected token`,
|
|
2706
2821
|
});
|
|
2707
2822
|
}
|
|
2708
2823
|
}
|
|
2709
2824
|
}
|
|
2710
|
-
atRule[
|
|
2825
|
+
atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
|
|
2711
2826
|
atRule[TOKENS] = stream;
|
|
2712
2827
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2713
2828
|
atRule[ERRORS] = [errors[errors.length - 1]];
|
|
@@ -2721,9 +2836,11 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2721
2836
|
case "container": {
|
|
2722
2837
|
const result = parseAtRuleContainerQueryList(stream, atRule, options);
|
|
2723
2838
|
if (result.errors.length > 0) {
|
|
2724
|
-
|
|
2839
|
+
for (const error of result.errors) {
|
|
2840
|
+
errors.push(error);
|
|
2841
|
+
}
|
|
2725
2842
|
}
|
|
2726
|
-
atRule[
|
|
2843
|
+
atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
|
|
2727
2844
|
atRule[TOKENS] = stream;
|
|
2728
2845
|
atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2729
2846
|
atRule[ERRORS] = result.success ? [] : result.errors;
|
|
@@ -2738,11 +2855,13 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2738
2855
|
const tokens = trimArray(stream.slice(1));
|
|
2739
2856
|
const result = matchAllSyntaxes(syntax, createValidationContext(tokens), options);
|
|
2740
2857
|
if (result.errors.length > 0) {
|
|
2741
|
-
|
|
2858
|
+
for (const error of result.errors) {
|
|
2859
|
+
errors.push(error);
|
|
2860
|
+
}
|
|
2742
2861
|
}
|
|
2743
2862
|
// @ts-expect-error
|
|
2744
2863
|
options = { ...options, convertColor: false };
|
|
2745
|
-
atRule[
|
|
2864
|
+
atRule[LOCEND] = (tokens.at(-1) ?? atRule)[LOCEND];
|
|
2746
2865
|
atRule[TOKENS] = tokens;
|
|
2747
2866
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed;
|
|
2748
2867
|
atRule[ERRORS] = result.success ? [] : result.errors;
|
|
@@ -2762,14 +2881,14 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2762
2881
|
errors.push({
|
|
2763
2882
|
action: "drop",
|
|
2764
2883
|
node: atRule,
|
|
2765
|
-
location: options.source.getSourceLocation(atRule[
|
|
2766
|
-
message: `expected <keyframe-name
|
|
2884
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2885
|
+
message: `expected <keyframe-name>`,
|
|
2767
2886
|
});
|
|
2768
2887
|
success = false;
|
|
2769
2888
|
}
|
|
2770
2889
|
// @ts-expect-error
|
|
2771
2890
|
options = { ...options, convertColor: false };
|
|
2772
|
-
atRule[
|
|
2891
|
+
atRule[LOCEND] = (tokens.at(-1) ?? atRule)[LOCEND];
|
|
2773
2892
|
atRule[TOKENS] = tokens;
|
|
2774
2893
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2775
2894
|
atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
|
|
@@ -2783,7 +2902,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2783
2902
|
case "namespace": {
|
|
2784
2903
|
const result = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
2785
2904
|
if (!result.success) {
|
|
2786
|
-
|
|
2905
|
+
for (const error of result.errors) {
|
|
2906
|
+
errors.push(error);
|
|
2907
|
+
}
|
|
2787
2908
|
}
|
|
2788
2909
|
// else {
|
|
2789
2910
|
// parseUrlToken(stream);
|
|
@@ -2812,7 +2933,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2812
2933
|
stream.splice(start - 1, end - start + 2, ...stream.slice(start, end));
|
|
2813
2934
|
}
|
|
2814
2935
|
}
|
|
2815
|
-
atRule[
|
|
2936
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
2816
2937
|
atRule[TOKENS] = stream.slice();
|
|
2817
2938
|
atRule[STATE] = valid ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2818
2939
|
atRule[ERRORS] = valid ? [] : result.errors;
|
|
@@ -2832,7 +2953,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2832
2953
|
case "import": {
|
|
2833
2954
|
const result = matchAtRuleImportSyntax(atRule, stream, context, options);
|
|
2834
2955
|
if (result.errors.length > 0) {
|
|
2835
|
-
|
|
2956
|
+
for (const error of result.errors) {
|
|
2957
|
+
errors.push(error);
|
|
2958
|
+
}
|
|
2836
2959
|
}
|
|
2837
2960
|
else {
|
|
2838
2961
|
if (stream[0]?.typ == EnumToken.UrlFunctionTokenType &&
|
|
@@ -2840,8 +2963,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2840
2963
|
stream.splice(0, 1, ...stream[0].chi);
|
|
2841
2964
|
}
|
|
2842
2965
|
}
|
|
2843
|
-
|
|
2844
|
-
atRule[LOC].end = stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end;
|
|
2966
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
2845
2967
|
atRule[TOKENS] = stream.slice();
|
|
2846
2968
|
atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2847
2969
|
atRule[ERRORS] = result.success ? [] : result.errors;
|
|
@@ -2865,7 +2987,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2865
2987
|
? parseAtRuleSupportSyntax(stream, atRule, options)
|
|
2866
2988
|
: matchAtRuleWhenElseSyntax(stream, atRule, options);
|
|
2867
2989
|
if (result.errors.length > 0) {
|
|
2868
|
-
|
|
2990
|
+
for (const error of result.errors) {
|
|
2991
|
+
errors.push(error);
|
|
2992
|
+
}
|
|
2869
2993
|
}
|
|
2870
2994
|
let success = result.success;
|
|
2871
2995
|
if (atRule.nam === "else") {
|
|
@@ -2902,7 +3026,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2902
3026
|
errors.push({
|
|
2903
3027
|
action: "drop",
|
|
2904
3028
|
node: atRule,
|
|
2905
|
-
location: options.source.getSourceLocation(atRule[
|
|
3029
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2906
3030
|
message: "at-rule @when is required before @else block",
|
|
2907
3031
|
});
|
|
2908
3032
|
}
|
|
@@ -2911,14 +3035,14 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2911
3035
|
errors.push({
|
|
2912
3036
|
action: "drop",
|
|
2913
3037
|
node: atRule,
|
|
2914
|
-
location: options.source.getSourceLocation(atRule[
|
|
3038
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
2915
3039
|
message: "at-rule @else block is defined after last @else block",
|
|
2916
3040
|
});
|
|
2917
3041
|
}
|
|
2918
3042
|
}
|
|
2919
3043
|
// @ts-expect-error
|
|
2920
3044
|
options = { ...options, minify: false, convertColor: false };
|
|
2921
|
-
atRule[
|
|
3045
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
2922
3046
|
atRule[TOKENS] = stream.slice();
|
|
2923
3047
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2924
3048
|
atRule[ERRORS] = result.success ? [] : [errors[errors.length - 1]].concat(result.errors);
|
|
@@ -2933,9 +3057,11 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2933
3057
|
options = { ...options, parseColor: false };
|
|
2934
3058
|
const result = parseMediaqueryList(stream, options);
|
|
2935
3059
|
if (result.errors.length > 0) {
|
|
2936
|
-
|
|
3060
|
+
for (const error of result.errors) {
|
|
3061
|
+
errors.push(error);
|
|
3062
|
+
}
|
|
2937
3063
|
}
|
|
2938
|
-
atRule[
|
|
3064
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
2939
3065
|
atRule[TOKENS] = stream.slice();
|
|
2940
3066
|
atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
2941
3067
|
atRule[ERRORS] = result.success ? [] : result.errors;
|
|
@@ -2955,7 +3081,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2955
3081
|
errors.push({
|
|
2956
3082
|
action: "drop",
|
|
2957
3083
|
node: range[0] ?? atRule,
|
|
2958
|
-
location: options.source.getSourceLocation((range[0] ?? atRule)[
|
|
3084
|
+
location: options.source.getSourceLocation((range[0] ?? atRule)[LOCSTA]),
|
|
2959
3085
|
message: "expected '(' at start of @scope block",
|
|
2960
3086
|
});
|
|
2961
3087
|
success = false;
|
|
@@ -2964,7 +3090,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2964
3090
|
errors.push({
|
|
2965
3091
|
action: "drop",
|
|
2966
3092
|
node: range.at(-1) ?? atRule,
|
|
2967
|
-
location: options.source.getSourceLocation((range.at(-1) ?? atRule)[
|
|
3093
|
+
location: options.source.getSourceLocation((range.at(-1) ?? atRule)[LOCSTA]),
|
|
2968
3094
|
message: "expected ')' at end of @scope block",
|
|
2969
3095
|
});
|
|
2970
3096
|
success = false;
|
|
@@ -2990,7 +3116,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
2990
3116
|
errors.push({
|
|
2991
3117
|
action: "drop",
|
|
2992
3118
|
node: stream[index],
|
|
2993
|
-
location: options.source.getSourceLocation(stream[index]?.[
|
|
3119
|
+
location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
|
|
2994
3120
|
message: "expected 'to' at end of @scope block",
|
|
2995
3121
|
});
|
|
2996
3122
|
success = false;
|
|
@@ -3003,7 +3129,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3003
3129
|
errors.push({
|
|
3004
3130
|
action: "drop",
|
|
3005
3131
|
node: stream[index],
|
|
3006
|
-
location: options.source.getSourceLocation(stream[index]?.[
|
|
3132
|
+
location: options.source.getSourceLocation(stream[index]?.[LOCSTA]),
|
|
3007
3133
|
message: "expected 'to' at end of @scope block",
|
|
3008
3134
|
});
|
|
3009
3135
|
success = false;
|
|
@@ -3016,7 +3142,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3016
3142
|
errors.push({
|
|
3017
3143
|
action: "drop",
|
|
3018
3144
|
node: range.at(-1) ?? atRule,
|
|
3019
|
-
location: options.source.getSourceLocation((range.at(-1) ?? atRule)[
|
|
3145
|
+
location: options.source.getSourceLocation((range.at(-1) ?? atRule)[LOCSTA]),
|
|
3020
3146
|
message: "expected ')' at end of @scope block",
|
|
3021
3147
|
});
|
|
3022
3148
|
success = false;
|
|
@@ -3035,8 +3161,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3035
3161
|
}
|
|
3036
3162
|
}
|
|
3037
3163
|
}
|
|
3038
|
-
|
|
3039
|
-
atRule[LOC].end = stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end;
|
|
3164
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3040
3165
|
atRule[TOKENS] = stream.slice();
|
|
3041
3166
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3042
3167
|
atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
|
|
@@ -3049,7 +3174,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3049
3174
|
}
|
|
3050
3175
|
case "page": {
|
|
3051
3176
|
trimArray(stream);
|
|
3052
|
-
atRule[
|
|
3177
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3053
3178
|
atRule[TOKENS] = stream.slice();
|
|
3054
3179
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3055
3180
|
atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
|
|
@@ -3080,7 +3205,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3080
3205
|
errors.push({
|
|
3081
3206
|
action: "drop",
|
|
3082
3207
|
node: atRule,
|
|
3083
|
-
location: options.source.getSourceLocation(atRule[
|
|
3208
|
+
location: options.source.getSourceLocation(atRule[LOCSTA]),
|
|
3084
3209
|
message: "node is allowed only in @page rule",
|
|
3085
3210
|
});
|
|
3086
3211
|
}
|
|
@@ -3093,14 +3218,14 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3093
3218
|
errors.push({
|
|
3094
3219
|
action: "drop",
|
|
3095
3220
|
node: stream[i],
|
|
3096
|
-
location: options.source.getSourceLocation(stream[i][
|
|
3221
|
+
location: options.source.getSourceLocation(stream[i][LOCSTA]),
|
|
3097
3222
|
message: "expected whitespace or comment",
|
|
3098
3223
|
});
|
|
3099
3224
|
break;
|
|
3100
3225
|
}
|
|
3101
3226
|
}
|
|
3102
3227
|
}
|
|
3103
|
-
atRule[
|
|
3228
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3104
3229
|
atRule[TOKENS] = stream.slice();
|
|
3105
3230
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3106
3231
|
atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
|
|
@@ -3122,7 +3247,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3122
3247
|
});
|
|
3123
3248
|
stream.splice(index, 0, {
|
|
3124
3249
|
typ: EnumToken.ColonTokenType,
|
|
3125
|
-
[
|
|
3250
|
+
[LOCSRCID]: stream[index][LOCSRCID],
|
|
3251
|
+
[LOCSTA]: stream[index][LOCSTA],
|
|
3252
|
+
[LOCEND]: stream[index][LOCEND],
|
|
3126
3253
|
});
|
|
3127
3254
|
isVarDeclaration = true;
|
|
3128
3255
|
break;
|
|
@@ -3144,14 +3271,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3144
3271
|
atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3145
3272
|
atRule[ERRORS] = success ? [] : [errors[errors.length - 1]];
|
|
3146
3273
|
if (!result.success) {
|
|
3147
|
-
|
|
3274
|
+
for (const error of result.errors) {
|
|
3275
|
+
errors.push(error);
|
|
3276
|
+
}
|
|
3148
3277
|
return {
|
|
3149
3278
|
typ: EnumToken.AtRuleNodeType,
|
|
3150
3279
|
val: renderTokens(stream, options),
|
|
3151
|
-
[
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
},
|
|
3280
|
+
[LOCSRCID]: atRule[LOCSRCID],
|
|
3281
|
+
[LOCSTA]: atRule[LOCSTA],
|
|
3282
|
+
[LOCEND]: stream.at(-1)?.[LOCEND] ?? atRule[LOCEND],
|
|
3155
3283
|
[TOKENS]: stream,
|
|
3156
3284
|
[STATE]: EnumAstNodeStatus.Invalid,
|
|
3157
3285
|
[ERRORS]: result.errors,
|
|
@@ -3166,10 +3294,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3166
3294
|
typ: EnumToken.CssVariableImportTokenType,
|
|
3167
3295
|
nam: nam.val,
|
|
3168
3296
|
val: value,
|
|
3169
|
-
[
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
},
|
|
3297
|
+
[LOCSRCID]: atRule[LOCSRCID],
|
|
3298
|
+
[LOCSTA]: atRule[LOCSTA],
|
|
3299
|
+
[LOCEND]: stream.at(-1)?.[LOCEND] ?? atRule[LOCEND],
|
|
3173
3300
|
[TOKENS]: stream,
|
|
3174
3301
|
[STATE]: EnumAstNodeStatus.Validated,
|
|
3175
3302
|
[ERRORS]: [],
|
|
@@ -3180,19 +3307,15 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3180
3307
|
typ: EnumToken.CssVariableTokenType,
|
|
3181
3308
|
nam: nam.val,
|
|
3182
3309
|
val: value,
|
|
3183
|
-
[
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
},
|
|
3310
|
+
[LOCSRCID]: atRule[LOCSRCID],
|
|
3311
|
+
[LOCSTA]: atRule[LOCSTA],
|
|
3312
|
+
[LOCEND]: stream.at(-1)?.[LOCEND] ?? atRule[LOCEND],
|
|
3187
3313
|
[TOKENS]: stream,
|
|
3188
3314
|
[STATE]: EnumAstNodeStatus.Validated,
|
|
3189
3315
|
[ERRORS]: [],
|
|
3190
3316
|
};
|
|
3191
3317
|
}
|
|
3192
|
-
atRule[
|
|
3193
|
-
...atRule[LOC],
|
|
3194
|
-
end: stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end,
|
|
3195
|
-
};
|
|
3318
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3196
3319
|
atRule[STATE] = EnumAstNodeStatus.Validated;
|
|
3197
3320
|
atRule[ERRORS] = [];
|
|
3198
3321
|
// @ts-expect-error
|
|
@@ -3212,13 +3335,17 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3212
3335
|
// check or and and
|
|
3213
3336
|
result = matchGenericSyntax(stream, options);
|
|
3214
3337
|
if (result.errors.length > 0) {
|
|
3215
|
-
|
|
3338
|
+
for (const error of result.errors) {
|
|
3339
|
+
errors.push(error);
|
|
3340
|
+
}
|
|
3216
3341
|
}
|
|
3217
3342
|
}
|
|
3218
3343
|
else {
|
|
3219
3344
|
result = matchAtRuleSyntax(atRule, stream, options);
|
|
3220
3345
|
if (result.errors.length > 0) {
|
|
3221
|
-
|
|
3346
|
+
for (const error of result.errors) {
|
|
3347
|
+
errors.push(error);
|
|
3348
|
+
}
|
|
3222
3349
|
}
|
|
3223
3350
|
if (result.success) {
|
|
3224
3351
|
let i = 0;
|
|
@@ -3230,7 +3357,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3230
3357
|
}
|
|
3231
3358
|
if (stream[i].typ === EnumToken.EndParensTokenType && stack.length > 0) {
|
|
3232
3359
|
const index = stream.indexOf(stack[stack.length - 1]);
|
|
3233
|
-
stream[index][
|
|
3360
|
+
stream[index][LOCEND] = stream[i][LOCEND];
|
|
3234
3361
|
Object.assign(stream[index], {
|
|
3235
3362
|
typ: tokensfuncDefMap.get(stream[index].typ),
|
|
3236
3363
|
chi: stream.splice(index + 1, i - index - 1),
|
|
@@ -3238,15 +3365,11 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3238
3365
|
i = index;
|
|
3239
3366
|
stream.splice(index + 1, 1);
|
|
3240
3367
|
stack.pop();
|
|
3241
|
-
// continue;
|
|
3242
3368
|
}
|
|
3243
3369
|
}
|
|
3244
3370
|
}
|
|
3245
3371
|
}
|
|
3246
|
-
atRule[
|
|
3247
|
-
...atRule[LOC],
|
|
3248
|
-
end: stream.at(-1)?.[LOC]?.end ?? atRule[LOC].end,
|
|
3249
|
-
};
|
|
3372
|
+
atRule[LOCEND] = stream.at(-1)?.[LOCEND] ?? atRule[LOCEND];
|
|
3250
3373
|
atRule[TOKENS] = stream.slice();
|
|
3251
3374
|
atRule[STATE] = result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
|
|
3252
3375
|
atRule[ERRORS] = result.errors;
|
|
@@ -3270,17 +3393,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
3270
3393
|
* console.log(declarations);
|
|
3271
3394
|
* ```
|
|
3272
3395
|
*/
|
|
3273
|
-
|
|
3396
|
+
function parseDeclarations(declaration) {
|
|
3274
3397
|
const stream = `.x{${declaration}}`;
|
|
3275
|
-
|
|
3398
|
+
const result = doParseSync(new Tokenizer({
|
|
3276
3399
|
stream,
|
|
3277
3400
|
offset: 0,
|
|
3278
3401
|
position: 0,
|
|
3279
3402
|
source: new SourceFile(stream, [], ""),
|
|
3280
3403
|
currentPosition: 0,
|
|
3281
|
-
}), { setParent: false, minify: false, validation: false })
|
|
3282
|
-
|
|
3283
|
-
|
|
3404
|
+
}), { setParent: false, minify: false, validation: false });
|
|
3405
|
+
// .then((result) => {
|
|
3406
|
+
return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType);
|
|
3407
|
+
// });
|
|
3284
3408
|
}
|
|
3285
3409
|
/**
|
|
3286
3410
|
* Parse css string and return an array of tokens
|
|
@@ -3305,18 +3429,57 @@ async function parseDeclarations(declaration) {
|
|
|
3305
3429
|
* ```
|
|
3306
3430
|
*/
|
|
3307
3431
|
function parseString(src, options = { parseColor: true }, errors) {
|
|
3308
|
-
const parseInfo = {
|
|
3432
|
+
// const parseInfo: ParseInfo = {
|
|
3433
|
+
// stream: src,
|
|
3434
|
+
// offset: 0,
|
|
3435
|
+
// time: 0,
|
|
3436
|
+
// source: new SourceFile(src, [], ""),
|
|
3437
|
+
// position: 0,
|
|
3438
|
+
// currentPosition: 0,
|
|
3439
|
+
// };
|
|
3440
|
+
const tokenizer = new Tokenizer({
|
|
3309
3441
|
stream: src,
|
|
3442
|
+
buffer: "",
|
|
3443
|
+
src: options?.src ?? "",
|
|
3310
3444
|
offset: 0,
|
|
3311
3445
|
time: 0,
|
|
3312
|
-
source: new SourceFile(src, [], ""),
|
|
3446
|
+
source: new SourceFile(src, [], options?.src ?? ""),
|
|
3313
3447
|
position: 0,
|
|
3314
3448
|
currentPosition: 0,
|
|
3315
|
-
};
|
|
3316
|
-
const tokenResults = tokenize(parseInfo);
|
|
3449
|
+
});
|
|
3317
3450
|
const mapped = [];
|
|
3318
|
-
|
|
3319
|
-
|
|
3451
|
+
let token;
|
|
3452
|
+
while (!tokenizer.done()) {
|
|
3453
|
+
tokenizer.next();
|
|
3454
|
+
if (tokenizer.unit != null) {
|
|
3455
|
+
token = {
|
|
3456
|
+
typ: tokenizer.typ,
|
|
3457
|
+
val: tokenizer.val,
|
|
3458
|
+
unit: tokenizer.unit,
|
|
3459
|
+
};
|
|
3460
|
+
}
|
|
3461
|
+
else if (tokenizer.val === null) {
|
|
3462
|
+
token = {
|
|
3463
|
+
typ: tokenizer.typ,
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
else if (tokenizer.kin != null) {
|
|
3467
|
+
token = {
|
|
3468
|
+
typ: tokenizer.typ,
|
|
3469
|
+
val: tokenizer.val,
|
|
3470
|
+
kin: tokenizer.kin,
|
|
3471
|
+
};
|
|
3472
|
+
}
|
|
3473
|
+
else {
|
|
3474
|
+
token = {
|
|
3475
|
+
typ: tokenizer.typ,
|
|
3476
|
+
val: tokenizer.val,
|
|
3477
|
+
};
|
|
3478
|
+
}
|
|
3479
|
+
token[LOCSRCID] = tokenizer.source.id;
|
|
3480
|
+
token[LOCEND] = tokenizer.end;
|
|
3481
|
+
token[LOCSTA] = tokenizer.sta;
|
|
3482
|
+
mapped.push(token);
|
|
3320
3483
|
}
|
|
3321
3484
|
const result = parseTokens(mapped, options, errors);
|
|
3322
3485
|
// remove EOF token
|
|
@@ -3362,7 +3525,7 @@ function parseTokens(tokens, options, errors) {
|
|
|
3362
3525
|
val: (tokens[i - 1].typ === EnumToken.ColonTokenType ? ":" : "::") +
|
|
3363
3526
|
tokens[i].val,
|
|
3364
3527
|
});
|
|
3365
|
-
t[
|
|
3528
|
+
t[LOCEND] = tokens[i][LOCEND];
|
|
3366
3529
|
tokens.splice(i--, 1);
|
|
3367
3530
|
}
|
|
3368
3531
|
}
|
|
@@ -3381,7 +3544,7 @@ function parseTokens(tokens, options, errors) {
|
|
|
3381
3544
|
action: "drop",
|
|
3382
3545
|
message: `Unbalanced token ')'`,
|
|
3383
3546
|
node,
|
|
3384
|
-
location: options.source.getSourceLocation(node[
|
|
3547
|
+
location: options.source.getSourceLocation(node[LOCSTA]),
|
|
3385
3548
|
});
|
|
3386
3549
|
// return [];
|
|
3387
3550
|
continue;
|
|
@@ -3409,13 +3572,13 @@ function parseTokens(tokens, options, errors) {
|
|
|
3409
3572
|
action: "drop",
|
|
3410
3573
|
message: `Unbalanced token ']'`,
|
|
3411
3574
|
node,
|
|
3412
|
-
location: options.source.getSourceLocation(node[
|
|
3575
|
+
location: options.source.getSourceLocation(node[LOCSTA]),
|
|
3413
3576
|
});
|
|
3414
3577
|
continue;
|
|
3415
3578
|
}
|
|
3416
3579
|
index = tokens.indexOf(stack.at(-1));
|
|
3417
3580
|
const attr = stack.at(-1);
|
|
3418
|
-
attr[
|
|
3581
|
+
attr[LOCEND] = t[LOCEND];
|
|
3419
3582
|
tokens.splice(i, 1);
|
|
3420
3583
|
Object.assign(attr, {
|
|
3421
3584
|
typ: EnumToken.AttrTokenType,
|
|
@@ -3531,9 +3694,8 @@ function parseTokens(tokens, options, errors) {
|
|
|
3531
3694
|
action: "drop",
|
|
3532
3695
|
message: `Unbalanced token. Expecting ${node.typ === EnumToken.AttrStartTokenType ? "']'" : ")"}'`,
|
|
3533
3696
|
node,
|
|
3534
|
-
location: options.source.getSourceLocation(node[
|
|
3697
|
+
location: options.source.getSourceLocation(node[LOCSTA]),
|
|
3535
3698
|
});
|
|
3536
|
-
// return [];
|
|
3537
3699
|
}
|
|
3538
3700
|
return tokens;
|
|
3539
3701
|
}
|