@tbela99/css-parser 2.3.0 → 2.3.2
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 +43 -0
- package/README.md +66 -21
- package/architecture.png +0 -0
- package/dist/ast/arena-node.js +32 -3
- package/dist/ast/arena.js +88 -10
- package/dist/ast/cache.js +1 -1
- package/dist/ast/features/calc.js +1 -1
- package/dist/ast/features/if.js +1 -1
- package/dist/ast/features/index.js +1 -1
- package/dist/ast/features/inlinecssvariables.js +1 -1
- package/dist/ast/features/mixin.js +1 -1
- package/dist/ast/features/prefix.js +1 -1
- package/dist/ast/features/shorthand.js +1 -1
- package/dist/ast/features/transform.js +1 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/math/expression.js +1 -1
- package/dist/ast/math/math.js +1 -1
- package/dist/ast/minify.js +131 -36
- package/dist/ast/mixins/custom-function.js +1 -1
- package/dist/ast/mixins/utils.js +1 -1
- package/dist/ast/mixins/variables.js +1 -1
- package/dist/ast/strings.js +26 -1
- package/dist/ast/transform/compute.js +6 -2
- package/dist/ast/transform/matrix.js +1 -1
- package/dist/ast/transform/minify.js +1 -1
- package/dist/ast/transform/perspective.js +1 -1
- package/dist/ast/transform/rotate.js +1 -1
- package/dist/ast/transform/scale.js +1 -1
- package/dist/ast/transform/skew.js +1 -1
- package/dist/ast/transform/translate.js +1 -1
- package/dist/ast/transform/utils.js +1 -1
- package/dist/ast/types.js +22 -2
- package/dist/ast/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +1 -1
- package/dist/fs/resolve.js +1 -1
- package/dist/index-umd-web.js +1099 -295
- package/dist/index.d.ts +612 -688
- package/dist/node.js +14 -8
- package/dist/parser/declaration/list.js +8 -5
- package/dist/parser/declaration/map.js +1 -1
- package/dist/parser/declaration/set.js +1 -1
- package/dist/parser/input.js +62 -4
- package/dist/parser/linesmap.js +1 -1
- package/dist/parser/parse.js +121 -13
- package/dist/parser/source.js +1 -1
- package/dist/parser/tokenize.js +161 -19
- package/dist/parser/utils/angle.js +1 -1
- package/dist/parser/utils/at-rule-container.js +1 -1
- package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/parser/utils/at-rule-generic.js +1 -1
- package/dist/parser/utils/at-rule-import.js +1 -1
- package/dist/parser/utils/at-rule-media.js +42 -2
- package/dist/parser/utils/at-rule-support.js +1 -1
- package/dist/parser/utils/at-rule-when-else.js +1 -1
- package/dist/parser/utils/at-rule.js +1 -1
- package/dist/parser/utils/base64.js +1 -1
- package/dist/parser/utils/cache.js +1 -1
- package/dist/parser/utils/canonical.js +1 -1
- package/dist/parser/utils/codes.js +1 -1
- package/dist/parser/utils/config.js +1 -1
- package/dist/parser/utils/declaration.js +1 -1
- package/dist/parser/utils/eq.js +1 -1
- package/dist/parser/utils/hash.js +1 -1
- package/dist/parser/utils/selector.js +98 -6
- package/dist/parser/utils/text.js +1 -1
- package/dist/parser/utils/token.js +1 -1
- package/dist/parser/utils/type.js +1 -1
- package/dist/printer/lib/codec.js +1 -1
- package/dist/printer/render.js +5 -7
- package/dist/printer/result.js +18 -3
- package/dist/printer/sourcemap.js +1 -1
- package/dist/printer/writer.js +1 -1
- package/dist/syntax/color/a98rgb.js +1 -1
- package/dist/syntax/color/alpha.js +1 -1
- package/dist/syntax/color/cmyk.js +1 -1
- package/dist/syntax/color/color-mix.js +1 -1
- package/dist/syntax/color/color.js +1 -1
- package/dist/syntax/color/hex.js +1 -1
- package/dist/syntax/color/hsl.js +12 -4
- package/dist/syntax/color/hwb.js +9 -3
- package/dist/syntax/color/lab.js +1 -1
- package/dist/syntax/color/lch.js +1 -1
- package/dist/syntax/color/oklab.js +1 -1
- package/dist/syntax/color/oklch.js +2 -2
- package/dist/syntax/color/p3.js +1 -1
- package/dist/syntax/color/prophotorgb.js +1 -1
- package/dist/syntax/color/rec2020.js +1 -1
- package/dist/syntax/color/relative-color.js +1 -1
- package/dist/syntax/color/rgb.js +1 -1
- package/dist/syntax/color/srgb.js +3 -2
- package/dist/syntax/color/utils/color-type.js +1 -1
- package/dist/syntax/color/utils/colorspace.js +1 -1
- package/dist/syntax/color/utils/components.js +1 -1
- package/dist/syntax/color/utils/distance.js +1 -1
- package/dist/syntax/color/utils/make-color.js +1 -1
- package/dist/syntax/color/utils/matrix.js +1 -1
- package/dist/syntax/color/xyz.js +1 -1
- package/dist/syntax/color/xyzd50.js +1 -1
- package/dist/syntax/constants.js +2 -2
- package/dist/syntax/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +1 -1
- package/dist/validation/compiled/builtins.js +1 -1
- package/dist/validation/compiled/runtime.js +1 -1
- package/dist/validation/compiled/syntaxes.js +1 -1
- package/dist/validation/config.js +1 -1
- package/dist/validation/first.js +1 -1
- package/dist/validation/match.js +77 -4
- package/dist/validation/parser/parse.js +1 -1
- package/dist/validation/parser/typedef.js +4 -1
- package/dist/validation/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +13 -6
- package/package.json +15 -6
package/dist/ast/arena.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, EnumAstNodeStatus, ColorType } from './types.js';
|
|
@@ -271,6 +271,10 @@ class Arena {
|
|
|
271
271
|
* the high word holds the 24 high bits of the start position and the source
|
|
272
272
|
*/
|
|
273
273
|
spans32;
|
|
274
|
+
/**
|
|
275
|
+
* create an empty arena
|
|
276
|
+
* @param size initial number of nodes the columns can hold. the columns grow when they are full
|
|
277
|
+
*/
|
|
274
278
|
constructor(size = 4096) {
|
|
275
279
|
this.dataTypes = new Uint8Array(size);
|
|
276
280
|
this.capacity = size;
|
|
@@ -335,6 +339,9 @@ class Arena {
|
|
|
335
339
|
arena.importProperties(properties, transferables);
|
|
336
340
|
return arena;
|
|
337
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Allocate a node or a token: a released id is reused, the columns grow when the arena is full. Returns the new id
|
|
344
|
+
*/
|
|
338
345
|
allocate() {
|
|
339
346
|
let id = this.freeList;
|
|
340
347
|
if (id !== 0) {
|
|
@@ -362,7 +369,9 @@ class Arena {
|
|
|
362
369
|
this.unit[id] = 0;
|
|
363
370
|
this.flags[id] = 0;
|
|
364
371
|
this.colorType[id] = 0;
|
|
365
|
-
|
|
372
|
+
// the 32 bits view: no bigint
|
|
373
|
+
this.spans32[id << 1] = 0;
|
|
374
|
+
this.spans32[(id << 1) + 1] = 0;
|
|
366
375
|
if (this.errors.size > 0) {
|
|
367
376
|
this.errors.delete(id);
|
|
368
377
|
}
|
|
@@ -405,6 +414,14 @@ class Arena {
|
|
|
405
414
|
setSourceText(source, text, codes = null) {
|
|
406
415
|
this.stringTable.setText(source, text, codes);
|
|
407
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* code unit of the text of a source, NaN after its end. no string is created
|
|
419
|
+
* @param source source index (see {@link getSourceId})
|
|
420
|
+
* @param offset
|
|
421
|
+
*/
|
|
422
|
+
sourceCodeAt(source, offset) {
|
|
423
|
+
return this.stringTable.sourceCodeAt(source, offset);
|
|
424
|
+
}
|
|
408
425
|
/**
|
|
409
426
|
* drop the code units of a source set by {@link setSourceText}: the source is no longer tokenized
|
|
410
427
|
* @param source source index
|
|
@@ -491,6 +508,7 @@ class Arena {
|
|
|
491
508
|
* @param id
|
|
492
509
|
* @param flag
|
|
493
510
|
* @param compute computes the property from the string
|
|
511
|
+
* @ignore
|
|
494
512
|
*/
|
|
495
513
|
stringFlag(id, flag, compute) {
|
|
496
514
|
return this.stringTable.flag(id, flag, compute);
|
|
@@ -500,6 +518,7 @@ class Arena {
|
|
|
500
518
|
* @param id
|
|
501
519
|
* @param flag
|
|
502
520
|
* @param compute computes the property from the string id
|
|
521
|
+
* @ignore
|
|
503
522
|
*/
|
|
504
523
|
stringFlagId(id, flag, compute) {
|
|
505
524
|
return this.stringTable.flagId(id, flag, compute);
|
|
@@ -509,6 +528,7 @@ class Arena {
|
|
|
509
528
|
* @param id
|
|
510
529
|
* @param slot
|
|
511
530
|
* @param compute computes the value from the string id
|
|
531
|
+
* @ignore
|
|
512
532
|
*/
|
|
513
533
|
stringDerived(id, slot, compute) {
|
|
514
534
|
return this.stringTable.derived(id, slot, compute);
|
|
@@ -546,6 +566,7 @@ class Arena {
|
|
|
546
566
|
return this.stringTable.epoch;
|
|
547
567
|
}
|
|
548
568
|
/**
|
|
569
|
+
* Type of a node or a token, see {@link EnumToken}
|
|
549
570
|
*
|
|
550
571
|
* @param id
|
|
551
572
|
*/
|
|
@@ -560,6 +581,7 @@ class Arena {
|
|
|
560
581
|
return id == null ? null : this.dataTypes[id];
|
|
561
582
|
}
|
|
562
583
|
/**
|
|
584
|
+
* Set the type of a node or a token, see {@link EnumToken}
|
|
563
585
|
*
|
|
564
586
|
* @param id
|
|
565
587
|
* @param type
|
|
@@ -568,6 +590,7 @@ class Arena {
|
|
|
568
590
|
this.dataTypes[id] = type;
|
|
569
591
|
}
|
|
570
592
|
/**
|
|
593
|
+
* Set the name of a node or a token: `nameId` is a string table id, see {@link AstArena.internString}
|
|
571
594
|
*
|
|
572
595
|
* @param id
|
|
573
596
|
* @param nameId
|
|
@@ -576,6 +599,7 @@ class Arena {
|
|
|
576
599
|
this.name[id] = nameId;
|
|
577
600
|
}
|
|
578
601
|
/**
|
|
602
|
+
* Name of a node or a token: the name of an at-rule, a declaration, a function, ...
|
|
579
603
|
*
|
|
580
604
|
* @param id
|
|
581
605
|
*/
|
|
@@ -583,6 +607,7 @@ class Arena {
|
|
|
583
607
|
return this.resolveString(this.name[id]) ?? null;
|
|
584
608
|
}
|
|
585
609
|
/**
|
|
610
|
+
* Set the value of a node or a token: `valueId` is a string table id, see {@link AstArena.internString}
|
|
586
611
|
*
|
|
587
612
|
* @param id
|
|
588
613
|
* @param valueId
|
|
@@ -591,6 +616,7 @@ class Arena {
|
|
|
591
616
|
this.stringValue[id] = valueId;
|
|
592
617
|
}
|
|
593
618
|
/**
|
|
619
|
+
* Value of a node or a token: the value of an identifier, a string, a hash, ...
|
|
594
620
|
*
|
|
595
621
|
* @param id
|
|
596
622
|
*/
|
|
@@ -598,6 +624,7 @@ class Arena {
|
|
|
598
624
|
return this.resolveString(this.stringValue[id]) ?? null;
|
|
599
625
|
}
|
|
600
626
|
/**
|
|
627
|
+
* Set the numeric value of a token
|
|
601
628
|
*
|
|
602
629
|
* @param id
|
|
603
630
|
* @param numericValue
|
|
@@ -606,6 +633,7 @@ class Arena {
|
|
|
606
633
|
this.numericValue[id] = numericValue;
|
|
607
634
|
}
|
|
608
635
|
/**
|
|
636
|
+
* Set the unit of a dimension token: `unit` is a string table id
|
|
609
637
|
*
|
|
610
638
|
* @param id
|
|
611
639
|
* @param unit
|
|
@@ -614,6 +642,7 @@ class Arena {
|
|
|
614
642
|
this.unit[id] = unit;
|
|
615
643
|
}
|
|
616
644
|
/**
|
|
645
|
+
* Unit of a dimension token
|
|
617
646
|
*
|
|
618
647
|
* @param id
|
|
619
648
|
*/
|
|
@@ -621,6 +650,7 @@ class Arena {
|
|
|
621
650
|
return this.resolveString(this.unit[id]) ?? null;
|
|
622
651
|
}
|
|
623
652
|
/**
|
|
653
|
+
* Numeric value of a token: number, dimension, percentage, ...
|
|
624
654
|
*
|
|
625
655
|
* @param id
|
|
626
656
|
*/
|
|
@@ -628,6 +658,8 @@ class Arena {
|
|
|
628
658
|
return this.numericValue[id];
|
|
629
659
|
}
|
|
630
660
|
/**
|
|
661
|
+
* Set the parent id of a node. The node is not moved: use {@link AstArena.appendChild} or {@link
|
|
662
|
+
* AstArena.insertBefore} to move it
|
|
631
663
|
*
|
|
632
664
|
* @param id
|
|
633
665
|
* @param parentId
|
|
@@ -710,6 +742,7 @@ class Arena {
|
|
|
710
742
|
}
|
|
711
743
|
}
|
|
712
744
|
/**
|
|
745
|
+
* Last child of a node. 0 when the node has no children
|
|
713
746
|
*
|
|
714
747
|
* @param id
|
|
715
748
|
*/
|
|
@@ -792,6 +825,7 @@ class Arena {
|
|
|
792
825
|
}
|
|
793
826
|
}
|
|
794
827
|
/**
|
|
828
|
+
* Set the color type of a color token, see {@link ColorType}
|
|
795
829
|
*
|
|
796
830
|
* @param id
|
|
797
831
|
* @param colorType
|
|
@@ -800,6 +834,7 @@ class Arena {
|
|
|
800
834
|
this.colorType[id] = colorType;
|
|
801
835
|
}
|
|
802
836
|
/**
|
|
837
|
+
* Color type of a color token, see {@link ColorType}
|
|
803
838
|
*
|
|
804
839
|
* @param id
|
|
805
840
|
*/
|
|
@@ -807,6 +842,7 @@ class Arena {
|
|
|
807
842
|
return this.colorType[id];
|
|
808
843
|
}
|
|
809
844
|
/**
|
|
845
|
+
* Replace the flags of a node, see {@link EnumAstNodeStatus}
|
|
810
846
|
*
|
|
811
847
|
* @param id
|
|
812
848
|
* @param flags
|
|
@@ -815,6 +851,7 @@ class Arena {
|
|
|
815
851
|
this.flags[id] = flags;
|
|
816
852
|
}
|
|
817
853
|
/**
|
|
854
|
+
* Flags of a node, see {@link EnumAstNodeStatus}
|
|
818
855
|
*
|
|
819
856
|
* @param id
|
|
820
857
|
*/
|
|
@@ -822,6 +859,7 @@ class Arena {
|
|
|
822
859
|
return this.flags[id];
|
|
823
860
|
}
|
|
824
861
|
/**
|
|
862
|
+
* `true` when a node has all the given flags, see {@link EnumAstNodeStatus}
|
|
825
863
|
*
|
|
826
864
|
* @param id
|
|
827
865
|
* @param flag
|
|
@@ -830,6 +868,7 @@ class Arena {
|
|
|
830
868
|
return (this.flags[id] & flag) === flag;
|
|
831
869
|
}
|
|
832
870
|
/**
|
|
871
|
+
* The child of a node at a position (0 based). null when the position is out of range
|
|
833
872
|
*
|
|
834
873
|
* @param id
|
|
835
874
|
* @param index
|
|
@@ -951,6 +990,7 @@ class Arena {
|
|
|
951
990
|
this.appendTokenList(this.fieldList(id, field), tokens);
|
|
952
991
|
}
|
|
953
992
|
/**
|
|
993
|
+
* Replace the tokens of the left hand side of a structured token
|
|
954
994
|
*
|
|
955
995
|
* @param id
|
|
956
996
|
* @param children
|
|
@@ -960,6 +1000,7 @@ class Arena {
|
|
|
960
1000
|
this.setTokenList(this.fieldList(id, TokenField.L), children);
|
|
961
1001
|
}
|
|
962
1002
|
/**
|
|
1003
|
+
* Tokens of the left hand side of a structured token (numerator of a fraction, ...). null when it is not set
|
|
963
1004
|
*
|
|
964
1005
|
* @param id
|
|
965
1006
|
*/
|
|
@@ -967,15 +1008,17 @@ class Arena {
|
|
|
967
1008
|
return this.getChildAt(id, TokenField.L) == null ? null : this.fieldTokens(id, TokenField.L);
|
|
968
1009
|
}
|
|
969
1010
|
/**
|
|
1011
|
+
* Replace the tokens of the right hand side of a structured token. null removes them
|
|
970
1012
|
*
|
|
971
|
-
* @param id
|
|
972
|
-
* @param rightId
|
|
1013
|
+
* @param id the structured token
|
|
1014
|
+
* @param rightId the tokens, or null
|
|
973
1015
|
*/
|
|
974
1016
|
setRight(id, ...rightId) {
|
|
975
1017
|
// inlined: this.setField(id, TokenField.R, ...(rightId == null || rightId[0] == null ? [] : (rightId as number[])))
|
|
976
1018
|
this.setTokenList(this.fieldList(id, TokenField.R), rightId == null || rightId[0] == null ? [] : rightId);
|
|
977
1019
|
}
|
|
978
1020
|
/**
|
|
1021
|
+
* Tokens of the right hand side of a structured token (denominator of a fraction, ...). null when it is not set
|
|
979
1022
|
*
|
|
980
1023
|
* @param id
|
|
981
1024
|
*/
|
|
@@ -983,6 +1026,7 @@ class Arena {
|
|
|
983
1026
|
return this.getChildAt(id, TokenField.R) == null ? null : this.fieldTokens(id, TokenField.R);
|
|
984
1027
|
}
|
|
985
1028
|
/**
|
|
1029
|
+
* Set the operator token of a structured token
|
|
986
1030
|
*
|
|
987
1031
|
* @param id
|
|
988
1032
|
* @param opId
|
|
@@ -992,6 +1036,7 @@ class Arena {
|
|
|
992
1036
|
this.setTokenList(this.fieldList(id, TokenField.Op), [opId]);
|
|
993
1037
|
}
|
|
994
1038
|
/**
|
|
1039
|
+
* Operator token of a structured token: the operator of a binary expression, ...
|
|
995
1040
|
*
|
|
996
1041
|
* @param id
|
|
997
1042
|
*/
|
|
@@ -999,6 +1044,7 @@ class Arena {
|
|
|
999
1044
|
return this.field(id, TokenField.Op);
|
|
1000
1045
|
}
|
|
1001
1046
|
/**
|
|
1047
|
+
* Set the second operator token of a structured token: the second operator of a media range query
|
|
1002
1048
|
*
|
|
1003
1049
|
* @param id
|
|
1004
1050
|
* @param op2Id
|
|
@@ -1008,6 +1054,7 @@ class Arena {
|
|
|
1008
1054
|
this.setTokenList(this.fieldList(id, TokenField.Op2), [op2Id]);
|
|
1009
1055
|
}
|
|
1010
1056
|
/**
|
|
1057
|
+
* Second operator token of a structured token: the second operator of a media range query
|
|
1011
1058
|
*
|
|
1012
1059
|
* @param id
|
|
1013
1060
|
*/
|
|
@@ -1015,6 +1062,7 @@ class Arena {
|
|
|
1015
1062
|
return this.field(id, TokenField.Op2);
|
|
1016
1063
|
}
|
|
1017
1064
|
/**
|
|
1065
|
+
* Set the location of a node or a token: the id of its source file and its start and end offsets
|
|
1018
1066
|
*
|
|
1019
1067
|
* @param id
|
|
1020
1068
|
* @param sourceId
|
|
@@ -1043,6 +1091,7 @@ class Arena {
|
|
|
1043
1091
|
this.spans32[t + 1] = this.spans32[s + 1];
|
|
1044
1092
|
}
|
|
1045
1093
|
/**
|
|
1094
|
+
* Id of the source file of a node or a token, see {@link getSpanStart} and {@link getSpanEnd}
|
|
1046
1095
|
*
|
|
1047
1096
|
* @param id
|
|
1048
1097
|
*/
|
|
@@ -1053,6 +1102,7 @@ class Arena {
|
|
|
1053
1102
|
return Number((this.spans[id] >> 56n) & 0xffn);
|
|
1054
1103
|
}
|
|
1055
1104
|
/**
|
|
1105
|
+
* Start offset of a node or a token in its source file
|
|
1056
1106
|
*
|
|
1057
1107
|
* @param id
|
|
1058
1108
|
*/
|
|
@@ -1065,6 +1115,7 @@ class Arena {
|
|
|
1065
1115
|
}
|
|
1066
1116
|
// ---- spans ---------------------------------------------------------------------
|
|
1067
1117
|
/**
|
|
1118
|
+
* Set the start offset of a node or a token in its source file
|
|
1068
1119
|
*
|
|
1069
1120
|
* @param id
|
|
1070
1121
|
* @param start
|
|
@@ -1073,6 +1124,7 @@ class Arena {
|
|
|
1073
1124
|
this.setSpan(id, this.getSourceId(id), start, this.getSpanEnd(id));
|
|
1074
1125
|
}
|
|
1075
1126
|
/**
|
|
1127
|
+
* End offset of a node or a token in its source file
|
|
1076
1128
|
*
|
|
1077
1129
|
* @param id
|
|
1078
1130
|
*/
|
|
@@ -1083,6 +1135,7 @@ class Arena {
|
|
|
1083
1135
|
return Number(this.spans[id] & 0xfffffffn);
|
|
1084
1136
|
}
|
|
1085
1137
|
/**
|
|
1138
|
+
* Set the end offset of a node or a token in its source file
|
|
1086
1139
|
*
|
|
1087
1140
|
* @param id
|
|
1088
1141
|
* @param end
|
|
@@ -1091,6 +1144,7 @@ class Arena {
|
|
|
1091
1144
|
this.setSpan(id, this.getSourceId(id), this.getSpanStart(id), end);
|
|
1092
1145
|
}
|
|
1093
1146
|
/**
|
|
1147
|
+
* Parent of a node. 0 when the node has no parent
|
|
1094
1148
|
*
|
|
1095
1149
|
* @param id
|
|
1096
1150
|
*/
|
|
@@ -1098,6 +1152,7 @@ class Arena {
|
|
|
1098
1152
|
return this.parents[id];
|
|
1099
1153
|
}
|
|
1100
1154
|
/**
|
|
1155
|
+
* The string of a string table id. The string is created the first time it is read
|
|
1101
1156
|
*
|
|
1102
1157
|
* @param id
|
|
1103
1158
|
*/
|
|
@@ -1440,6 +1495,7 @@ class Arena {
|
|
|
1440
1495
|
return result;
|
|
1441
1496
|
}
|
|
1442
1497
|
/**
|
|
1498
|
+
* The first child of a node for which the predicate returns `true`. null when there is none
|
|
1443
1499
|
*
|
|
1444
1500
|
* @param id
|
|
1445
1501
|
* @param predicate
|
|
@@ -1535,6 +1591,7 @@ class Arena {
|
|
|
1535
1591
|
return count;
|
|
1536
1592
|
}
|
|
1537
1593
|
/**
|
|
1594
|
+
* Replace the children of a node
|
|
1538
1595
|
*
|
|
1539
1596
|
* @param id
|
|
1540
1597
|
* @param children
|
|
@@ -1561,6 +1618,7 @@ class Arena {
|
|
|
1561
1618
|
this.appendChildList(id, children);
|
|
1562
1619
|
}
|
|
1563
1620
|
/**
|
|
1621
|
+
* Replace the tokens of a node or a token
|
|
1564
1622
|
*
|
|
1565
1623
|
* @param id
|
|
1566
1624
|
* @param children
|
|
@@ -1610,6 +1668,7 @@ class Arena {
|
|
|
1610
1668
|
}
|
|
1611
1669
|
}
|
|
1612
1670
|
/**
|
|
1671
|
+
* Append children to a node
|
|
1613
1672
|
*
|
|
1614
1673
|
* @param id
|
|
1615
1674
|
* @param children
|
|
@@ -1648,6 +1707,7 @@ class Arena {
|
|
|
1648
1707
|
}
|
|
1649
1708
|
}
|
|
1650
1709
|
/**
|
|
1710
|
+
* Append tokens to a node or a token
|
|
1651
1711
|
*
|
|
1652
1712
|
* @param id
|
|
1653
1713
|
* @param children
|
|
@@ -1752,6 +1812,8 @@ class Arena {
|
|
|
1752
1812
|
}
|
|
1753
1813
|
}
|
|
1754
1814
|
/**
|
|
1815
|
+
* Compare the name (`"nam"`) or the value (`"val"`) of a node with a string, ignoring the case. The string of the
|
|
1816
|
+
* node is not created
|
|
1755
1817
|
*
|
|
1756
1818
|
* @param node
|
|
1757
1819
|
* @param key
|
|
@@ -1762,6 +1824,8 @@ class Arena {
|
|
|
1762
1824
|
return this.stringTable.equalsIgnoreCase(key === "nam" ? this.name[node] : this.stringValue[node], string);
|
|
1763
1825
|
}
|
|
1764
1826
|
/**
|
|
1827
|
+
* `true` when the name (`"nam"`) or the value (`"val"`) of a node starts with a string. The string of the node is
|
|
1828
|
+
* not created
|
|
1765
1829
|
*
|
|
1766
1830
|
* @param node
|
|
1767
1831
|
* @param key
|
|
@@ -1772,6 +1836,7 @@ class Arena {
|
|
|
1772
1836
|
return this.stringTable.startsWith(key === "nam" ? this.name[node] : this.stringValue[node], string);
|
|
1773
1837
|
}
|
|
1774
1838
|
/**
|
|
1839
|
+
* Grow the columns of the arena so they hold `newSize` ids. The columns are never shrunk
|
|
1775
1840
|
*
|
|
1776
1841
|
* @param newSize
|
|
1777
1842
|
*/
|
|
@@ -2039,6 +2104,7 @@ class Arena {
|
|
|
2039
2104
|
return this.compact(errors);
|
|
2040
2105
|
}
|
|
2041
2106
|
/**
|
|
2107
|
+
* Set the validation errors of a node. null or an empty list removes them
|
|
2042
2108
|
*
|
|
2043
2109
|
* @param id
|
|
2044
2110
|
* @param errors
|
|
@@ -2053,6 +2119,7 @@ class Arena {
|
|
|
2053
2119
|
}
|
|
2054
2120
|
}
|
|
2055
2121
|
/**
|
|
2122
|
+
* Validation errors of a node. null when the node has no errors
|
|
2056
2123
|
*
|
|
2057
2124
|
* @param id
|
|
2058
2125
|
*/
|
|
@@ -2163,8 +2230,8 @@ class AstArena extends Arena {
|
|
|
2163
2230
|
*/
|
|
2164
2231
|
inputLengths = [];
|
|
2165
2232
|
/**
|
|
2166
|
-
*
|
|
2167
|
-
* @param size
|
|
2233
|
+
* create an arena that holds an empty stylesheet
|
|
2234
|
+
* @param size initial number of nodes the columns can hold. the columns grow when they are full
|
|
2168
2235
|
*/
|
|
2169
2236
|
constructor(size = 4096) {
|
|
2170
2237
|
super(size);
|
|
@@ -2173,7 +2240,10 @@ class AstArena extends Arena {
|
|
|
2173
2240
|
this.flags[this.root] = EnumAstNodeStatus.HasChildren;
|
|
2174
2241
|
}
|
|
2175
2242
|
/**
|
|
2176
|
-
*
|
|
2243
|
+
* release nodes: detach them and drop their data (interned strings, errors) and their minification caches. node
|
|
2244
|
+
* ids are never reused: the memory is reclaimed by {@link trim}
|
|
2245
|
+
* @param id the node to release. every marked node (and its descendants) is released when omitted
|
|
2246
|
+
* @param deep release the children and the tokens too
|
|
2177
2247
|
*/
|
|
2178
2248
|
release(id, deep = false) {
|
|
2179
2249
|
super.release(id, deep);
|
|
@@ -2191,7 +2261,11 @@ class AstArena extends Arena {
|
|
|
2191
2261
|
}
|
|
2192
2262
|
}
|
|
2193
2263
|
/**
|
|
2194
|
-
*
|
|
2264
|
+
* drop the nodes that are not reachable from the root and renumber the remaining nodes in document order.
|
|
2265
|
+
* the node ids change: ids obtained before the call (from visitors for instance) are no longer valid.
|
|
2266
|
+
* the unused strings and the minification caches are dropped too
|
|
2267
|
+
* @param errors error descriptions whose `node` is remapped
|
|
2268
|
+
* @returns mapping of the old ids to the new ids (0 when the node was dropped)
|
|
2195
2269
|
*/
|
|
2196
2270
|
compact(errors) {
|
|
2197
2271
|
const mapping = super.compact(errors);
|
|
@@ -3129,7 +3203,7 @@ class AstArena extends Arena {
|
|
|
3129
3203
|
return tokens.reduce((acc, curr) => acc + renderValue(this, curr), "");
|
|
3130
3204
|
}
|
|
3131
3205
|
/**
|
|
3132
|
-
*
|
|
3206
|
+
* structured-cloneable properties of the arena, the sources and the minification caches included
|
|
3133
3207
|
*/
|
|
3134
3208
|
exportProperties() {
|
|
3135
3209
|
return {
|
|
@@ -3142,7 +3216,10 @@ class AstArena extends Arena {
|
|
|
3142
3216
|
};
|
|
3143
3217
|
}
|
|
3144
3218
|
/**
|
|
3145
|
-
*
|
|
3219
|
+
* initialize the arena from exported properties and column buffers, the sources and the minification caches
|
|
3220
|
+
* included
|
|
3221
|
+
* @param properties
|
|
3222
|
+
* @param transferables
|
|
3146
3223
|
*/
|
|
3147
3224
|
importProperties(properties, transferables) {
|
|
3148
3225
|
super.importProperties(properties, transferables);
|
|
@@ -3550,6 +3627,7 @@ class AstArena extends Arena {
|
|
|
3550
3627
|
}
|
|
3551
3628
|
}
|
|
3552
3629
|
/**
|
|
3630
|
+
* Replace the nesting selectors (`&`) of a compound selector with a selector
|
|
3553
3631
|
*
|
|
3554
3632
|
* @param selector
|
|
3555
3633
|
* @param replace
|
package/dist/ast/cache.js
CHANGED
package/dist/ast/features/if.js
CHANGED