@tbela99/css-parser 2.3.1 → 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 +38 -0
- package/README.md +56 -26
- 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 +1084 -293
- package/dist/index.d.ts +597 -686
- 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 +3 -1
- 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/index-umd-web.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
|
(function (global, factory) {
|
|
@@ -1014,6 +1014,26 @@
|
|
|
1014
1014
|
*/
|
|
1015
1015
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
1016
1016
|
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
1017
|
+
/**
|
|
1018
|
+
* Merge of the adjacent rules, see {@link ParserOptions.mergeRules}. `true` is a shortcut for
|
|
1019
|
+
* {@link MergeRulesEnum.All}, `false` for {@link MergeRulesEnum.None}
|
|
1020
|
+
*/
|
|
1021
|
+
exports.MergeRulesEnum = void 0;
|
|
1022
|
+
(function (MergeRulesEnum) {
|
|
1023
|
+
/**
|
|
1024
|
+
* the rules are not merged
|
|
1025
|
+
*/
|
|
1026
|
+
MergeRulesEnum[MergeRulesEnum["None"] = 0] = "None";
|
|
1027
|
+
/**
|
|
1028
|
+
* only the rules that have the same declarations are merged, the size of the output is not computed:
|
|
1029
|
+
* `.a{color:red}.b{color:red}` is merged into `.a,.b{color:red}`
|
|
1030
|
+
*/
|
|
1031
|
+
MergeRulesEnum[MergeRulesEnum["Identical"] = 1] = "Identical";
|
|
1032
|
+
/**
|
|
1033
|
+
* the rules that share declarations are merged when the output is smaller
|
|
1034
|
+
*/
|
|
1035
|
+
MergeRulesEnum[MergeRulesEnum["All"] = 2] = "All";
|
|
1036
|
+
})(exports.MergeRulesEnum || (exports.MergeRulesEnum = {}));
|
|
1017
1037
|
|
|
1018
1038
|
/**
|
|
1019
1039
|
* push the direct value tokens of a token onto a stack, from the linked lists: the token list, then the fields (the
|
|
@@ -1419,8 +1439,9 @@
|
|
|
1419
1439
|
*/
|
|
1420
1440
|
[ARENAID];
|
|
1421
1441
|
/**
|
|
1422
|
-
*
|
|
1423
|
-
* @param
|
|
1442
|
+
* create a view of a node of the arena. the view reads and writes the arena: it holds no data
|
|
1443
|
+
* @param arena the arena that holds the node
|
|
1444
|
+
* @param id the node or token id
|
|
1424
1445
|
*/
|
|
1425
1446
|
constructor(arena, id) {
|
|
1426
1447
|
this[ARENA] = arena;
|
|
@@ -1432,6 +1453,9 @@
|
|
|
1432
1453
|
get typ() {
|
|
1433
1454
|
return this[ARENA].dataTypes[this[ARENAID]];
|
|
1434
1455
|
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Set the node or token type
|
|
1458
|
+
*/
|
|
1435
1459
|
set typ(typ) {
|
|
1436
1460
|
this[ARENA].dataTypes[this[ARENAID]] = typ;
|
|
1437
1461
|
}
|
|
@@ -1450,6 +1474,7 @@
|
|
|
1450
1474
|
return arena.name[id] === 0 ? undefined : arena.resolveString(arena.name[id]);
|
|
1451
1475
|
}
|
|
1452
1476
|
/**
|
|
1477
|
+
* Set the at-rule / declaration name, token name. undefined for the other nodes
|
|
1453
1478
|
*
|
|
1454
1479
|
* @param nam
|
|
1455
1480
|
*/
|
|
@@ -1468,6 +1493,7 @@
|
|
|
1468
1493
|
: undefined;
|
|
1469
1494
|
}
|
|
1470
1495
|
/**
|
|
1496
|
+
* Set the rule selector. undefined for the other nodes
|
|
1471
1497
|
*
|
|
1472
1498
|
* @param sel
|
|
1473
1499
|
*/
|
|
@@ -1516,6 +1542,7 @@
|
|
|
1516
1542
|
: undefined;
|
|
1517
1543
|
}
|
|
1518
1544
|
/**
|
|
1545
|
+
* Set the value, see the getter: a string, a number, a token or a list of tokens depending on the type of the node
|
|
1519
1546
|
*
|
|
1520
1547
|
* @param val
|
|
1521
1548
|
*/
|
|
@@ -1570,6 +1597,8 @@
|
|
|
1570
1597
|
return listViews(arena, arena.firstToken[id]);
|
|
1571
1598
|
}
|
|
1572
1599
|
/**
|
|
1600
|
+
* Set the children: the child nodes of a stylesheet, a rule or an at-rule with a block, the tokens of a function
|
|
1601
|
+
* token (arguments), a parentheses token, ... undefined when the node has no children
|
|
1573
1602
|
*
|
|
1574
1603
|
* @param chi
|
|
1575
1604
|
*/
|
|
@@ -1607,6 +1636,7 @@
|
|
|
1607
1636
|
: listViews(arena, arena.firstToken[id]);
|
|
1608
1637
|
}
|
|
1609
1638
|
/**
|
|
1639
|
+
* Set the prelude tokens of an at-rule, selector tokens of a rule. null when the node has no prelude tokens
|
|
1610
1640
|
*
|
|
1611
1641
|
* @param tokens
|
|
1612
1642
|
*/
|
|
@@ -1625,6 +1655,7 @@
|
|
|
1625
1655
|
: arena.resolveString(arena.unit[id]);
|
|
1626
1656
|
}
|
|
1627
1657
|
/**
|
|
1658
|
+
* Set the unit of a dimension, calendar (`cal`) of a color, attribute (`attr`) of a match expression
|
|
1628
1659
|
*
|
|
1629
1660
|
* @param unit
|
|
1630
1661
|
*/
|
|
@@ -1641,6 +1672,9 @@
|
|
|
1641
1672
|
? undefined
|
|
1642
1673
|
: arena.resolveString(arena.unit[id]);
|
|
1643
1674
|
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Set the color space of a color
|
|
1677
|
+
*/
|
|
1644
1678
|
set cal(cal) {
|
|
1645
1679
|
this[ARENA].setUnitString(this[ARENAID], cal ?? null);
|
|
1646
1680
|
}
|
|
@@ -1654,6 +1688,9 @@
|
|
|
1654
1688
|
? undefined
|
|
1655
1689
|
: arena.resolveString(arena.unit[id]);
|
|
1656
1690
|
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Set the attribute of a match expression
|
|
1693
|
+
*/
|
|
1657
1694
|
set attr(attr) {
|
|
1658
1695
|
this[ARENA].setUnitString(this[ARENAID], attr ?? null);
|
|
1659
1696
|
}
|
|
@@ -1667,6 +1704,9 @@
|
|
|
1667
1704
|
? undefined
|
|
1668
1705
|
: arena.colorType[id];
|
|
1669
1706
|
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Set the color type of a color token
|
|
1709
|
+
*/
|
|
1670
1710
|
set kin(kin) {
|
|
1671
1711
|
this[ARENA].colorType[this[ARENAID]] = kin ?? exports.ColorType.NONE;
|
|
1672
1712
|
}
|
|
@@ -1679,6 +1719,7 @@
|
|
|
1679
1719
|
return arena.dataTypes[id] === exports.EnumToken.UnaryExpressionTokenType ? arena.numericValue[id] : undefined;
|
|
1680
1720
|
}
|
|
1681
1721
|
/**
|
|
1722
|
+
* Set the sign of a unary expression
|
|
1682
1723
|
*
|
|
1683
1724
|
* @param sign
|
|
1684
1725
|
*/
|
|
@@ -1696,6 +1737,7 @@
|
|
|
1696
1737
|
: this.getField("op");
|
|
1697
1738
|
}
|
|
1698
1739
|
/**
|
|
1740
|
+
* Set the operator: the operator of a binary expression, the operator tokens of a structured token
|
|
1699
1741
|
*
|
|
1700
1742
|
* @param op
|
|
1701
1743
|
*/
|
|
@@ -1716,6 +1758,7 @@
|
|
|
1716
1758
|
return this.getField("op1");
|
|
1717
1759
|
}
|
|
1718
1760
|
/**
|
|
1761
|
+
* Set the first operator of a media range query
|
|
1719
1762
|
*
|
|
1720
1763
|
* @param op
|
|
1721
1764
|
*/
|
|
@@ -1729,6 +1772,7 @@
|
|
|
1729
1772
|
return this.getField("op2");
|
|
1730
1773
|
}
|
|
1731
1774
|
/**
|
|
1775
|
+
* Set the second operator of a media range query
|
|
1732
1776
|
*
|
|
1733
1777
|
* @param op
|
|
1734
1778
|
*/
|
|
@@ -1747,6 +1791,7 @@
|
|
|
1747
1791
|
return this.getField("l");
|
|
1748
1792
|
}
|
|
1749
1793
|
/**
|
|
1794
|
+
* Set the left hand side of a structured token, numerator of a fraction
|
|
1750
1795
|
*
|
|
1751
1796
|
* @param l
|
|
1752
1797
|
*/
|
|
@@ -1776,6 +1821,7 @@
|
|
|
1776
1821
|
return this.getField("r");
|
|
1777
1822
|
}
|
|
1778
1823
|
/**
|
|
1824
|
+
* Set the right hand side of a structured token, denominator of a fraction
|
|
1779
1825
|
*
|
|
1780
1826
|
* @param r
|
|
1781
1827
|
*/
|
|
@@ -1802,6 +1848,7 @@
|
|
|
1802
1848
|
return loc == null ? null : Object.freeze(loc);
|
|
1803
1849
|
}
|
|
1804
1850
|
/**
|
|
1851
|
+
* Set the source location. null when the node has no location
|
|
1805
1852
|
*
|
|
1806
1853
|
* @param loc
|
|
1807
1854
|
*/
|
|
@@ -1815,6 +1862,7 @@
|
|
|
1815
1862
|
return this[ARENA].flags[this[ARENAID]] & exports.EnumAstNodeStatus.StateMask;
|
|
1816
1863
|
}
|
|
1817
1864
|
/**
|
|
1865
|
+
* Set the validation state
|
|
1818
1866
|
*
|
|
1819
1867
|
* @param state
|
|
1820
1868
|
*/
|
|
@@ -1830,6 +1878,7 @@
|
|
|
1830
1878
|
return errors == null ? null : Object.freeze(errors.slice());
|
|
1831
1879
|
}
|
|
1832
1880
|
/**
|
|
1881
|
+
* Set the validation errors. null when the node has no errors
|
|
1833
1882
|
*
|
|
1834
1883
|
* @param errors
|
|
1835
1884
|
*/
|
|
@@ -8472,7 +8521,7 @@
|
|
|
8472
8521
|
};
|
|
8473
8522
|
|
|
8474
8523
|
/**
|
|
8475
|
-
*
|
|
8524
|
+
* key of the position of a validation token in the syntax, see {@link ValidationToken}
|
|
8476
8525
|
*/
|
|
8477
8526
|
const LOC = Symbol.for("loc");
|
|
8478
8527
|
/**
|
|
@@ -9458,7 +9507,7 @@
|
|
|
9458
9507
|
}
|
|
9459
9508
|
function hwb2oklchvalues(arena, token) {
|
|
9460
9509
|
const values = hwb2oklabvalues(arena, token);
|
|
9461
|
-
return labvalues2lchvalues(values[0], values[1], values[2], values[3]);
|
|
9510
|
+
return values == null ? null : labvalues2lchvalues(values[0], values[1], values[2], values[3]);
|
|
9462
9511
|
}
|
|
9463
9512
|
function cmyk2oklchvalues(arena, token) {
|
|
9464
9513
|
const values = cmyk2srgbvalues(arena, token);
|
|
@@ -10037,11 +10086,17 @@
|
|
|
10037
10086
|
return arena.createColor("hwb", exports.ColorType.HWB, chi);
|
|
10038
10087
|
}
|
|
10039
10088
|
function rgb2hwbvalues(arena, token) {
|
|
10040
|
-
const
|
|
10089
|
+
const components = getColorComponents(arena, token);
|
|
10090
|
+
// the components cannot be computed: var(), ...
|
|
10091
|
+
if (components == null) {
|
|
10092
|
+
return null;
|
|
10093
|
+
}
|
|
10094
|
+
const values = components.map((t, index) => {
|
|
10041
10095
|
if (index === 3) {
|
|
10042
10096
|
return getNumber(arena, t);
|
|
10043
10097
|
}
|
|
10044
|
-
|
|
10098
|
+
// the components are from 0 to 255: 100% is 255
|
|
10099
|
+
return ((arena.dataTypes[t] === exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, t)) / 255;
|
|
10045
10100
|
});
|
|
10046
10101
|
// @ts-ignore
|
|
10047
10102
|
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
@@ -10252,8 +10307,9 @@
|
|
|
10252
10307
|
}
|
|
10253
10308
|
function hwb2srgbvalues(arena, token) {
|
|
10254
10309
|
const { h, w, b, a } = hwbvalues(arena, token) ?? {};
|
|
10310
|
+
// the components cannot be computed: var(), ...
|
|
10255
10311
|
if (h == null || w == null || b == null) {
|
|
10256
|
-
return
|
|
10312
|
+
return null;
|
|
10257
10313
|
}
|
|
10258
10314
|
const rgb = hwb2srgb(h, w, b);
|
|
10259
10315
|
if (a != null && a !== 1) {
|
|
@@ -10861,6 +10917,14 @@
|
|
|
10861
10917
|
}
|
|
10862
10918
|
return arena.createColor("hsl", exports.ColorType.HSL, chi);
|
|
10863
10919
|
}
|
|
10920
|
+
/**
|
|
10921
|
+
* value of a red, green or blue component of an `rgb()` color, from 0 to 255: `100%` is 255
|
|
10922
|
+
* @param arena
|
|
10923
|
+
* @param token
|
|
10924
|
+
*/
|
|
10925
|
+
function rgbChannel(arena, token) {
|
|
10926
|
+
return (arena.dataTypes[token] === exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, token);
|
|
10927
|
+
}
|
|
10864
10928
|
function rgb2hslvalues(arena, token) {
|
|
10865
10929
|
const chi = getColorComponents(arena, token);
|
|
10866
10930
|
if (chi == null || chi.length < 3) {
|
|
@@ -10869,15 +10933,15 @@
|
|
|
10869
10933
|
// @ts-ignore
|
|
10870
10934
|
let t = chi[0];
|
|
10871
10935
|
// @ts-ignore
|
|
10872
|
-
let r =
|
|
10936
|
+
let r = rgbChannel(arena, t);
|
|
10873
10937
|
// @ts-ignore
|
|
10874
10938
|
t = chi[1];
|
|
10875
10939
|
// @ts-ignore
|
|
10876
|
-
let g =
|
|
10940
|
+
let g = rgbChannel(arena, t);
|
|
10877
10941
|
// @ts-ignore
|
|
10878
10942
|
t = chi[2];
|
|
10879
10943
|
// @ts-ignore
|
|
10880
|
-
let b =
|
|
10944
|
+
let b = rgbChannel(arena, t);
|
|
10881
10945
|
// @ts-ignore
|
|
10882
10946
|
let a = null;
|
|
10883
10947
|
if (chi.length === 4) {
|
|
@@ -12851,7 +12915,10 @@
|
|
|
12851
12915
|
return arena.createColor("device-cmyk", exports.ColorType.DEVICE_CMYK, chi);
|
|
12852
12916
|
}
|
|
12853
12917
|
|
|
12854
|
-
|
|
12918
|
+
/**
|
|
12919
|
+
* type of a validation token: a node of the parsed value definition syntax, see {@link parseSyntax}
|
|
12920
|
+
*/
|
|
12921
|
+
exports.ValidationTokenEnum = void 0;
|
|
12855
12922
|
(function (ValidationTokenEnum) {
|
|
12856
12923
|
ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
|
|
12857
12924
|
ValidationTokenEnum[ValidationTokenEnum["Keyword"] = 1] = "Keyword";
|
|
@@ -12926,7 +12993,7 @@
|
|
|
12926
12993
|
ValidationTokenEnum[ValidationTokenEnum["Dimension"] = 45] = "Dimension";
|
|
12927
12994
|
ValidationTokenEnum[ValidationTokenEnum["DisallowWhitespace"] = 46] = "DisallowWhitespace";
|
|
12928
12995
|
ValidationTokenEnum[ValidationTokenEnum["Colon"] = 47] = "Colon";
|
|
12929
|
-
})(ValidationTokenEnum || (ValidationTokenEnum = {}));
|
|
12996
|
+
})(exports.ValidationTokenEnum || (exports.ValidationTokenEnum = {}));
|
|
12930
12997
|
/**
|
|
12931
12998
|
* Keys of the validation config object
|
|
12932
12999
|
*/
|
|
@@ -12961,37 +13028,37 @@
|
|
|
12961
13028
|
})(MediaFeatureType || (MediaFeatureType = {}));
|
|
12962
13029
|
|
|
12963
13030
|
const SymbolsMapTokens = {
|
|
12964
|
-
"&&": ValidationTokenEnum.Ampersand,
|
|
12965
|
-
"|": ValidationTokenEnum.Pipe,
|
|
12966
|
-
"† ": ValidationTokenEnum.DisallowWhitespace,
|
|
12967
|
-
"||": ValidationTokenEnum.Column,
|
|
12968
|
-
"*": ValidationTokenEnum.Star,
|
|
12969
|
-
",": ValidationTokenEnum.Comma,
|
|
12970
|
-
"/": ValidationTokenEnum.Separator,
|
|
12971
|
-
"+": ValidationTokenEnum.Plus,
|
|
12972
|
-
";": ValidationTokenEnum.SemiColon,
|
|
12973
|
-
"(": ValidationTokenEnum.OpenParenthesis,
|
|
12974
|
-
")": ValidationTokenEnum.CloseParenthesis,
|
|
12975
|
-
"[": ValidationTokenEnum.OpenBracket,
|
|
12976
|
-
"]": ValidationTokenEnum.CloseBracket,
|
|
12977
|
-
"{": ValidationTokenEnum.OpenCurlyBrace,
|
|
12978
|
-
"}": ValidationTokenEnum.CloseCurlyBrace,
|
|
12979
|
-
"?": ValidationTokenEnum.QuestionMark,
|
|
12980
|
-
"!": ValidationTokenEnum.Exclamation,
|
|
12981
|
-
"#": ValidationTokenEnum.HashMark,
|
|
12982
|
-
"<": ValidationTokenEnum.LessThan,
|
|
12983
|
-
">": ValidationTokenEnum.GreaterThan,
|
|
12984
|
-
" ": ValidationTokenEnum.Whitespace,
|
|
12985
|
-
"\t": ValidationTokenEnum.Whitespace,
|
|
12986
|
-
"\r": ValidationTokenEnum.Whitespace,
|
|
12987
|
-
"\n": ValidationTokenEnum.Whitespace,
|
|
12988
|
-
"\f": ValidationTokenEnum.Whitespace,
|
|
13031
|
+
"&&": exports.ValidationTokenEnum.Ampersand,
|
|
13032
|
+
"|": exports.ValidationTokenEnum.Pipe,
|
|
13033
|
+
"† ": exports.ValidationTokenEnum.DisallowWhitespace,
|
|
13034
|
+
"||": exports.ValidationTokenEnum.Column,
|
|
13035
|
+
"*": exports.ValidationTokenEnum.Star,
|
|
13036
|
+
",": exports.ValidationTokenEnum.Comma,
|
|
13037
|
+
"/": exports.ValidationTokenEnum.Separator,
|
|
13038
|
+
"+": exports.ValidationTokenEnum.Plus,
|
|
13039
|
+
";": exports.ValidationTokenEnum.SemiColon,
|
|
13040
|
+
"(": exports.ValidationTokenEnum.OpenParenthesis,
|
|
13041
|
+
")": exports.ValidationTokenEnum.CloseParenthesis,
|
|
13042
|
+
"[": exports.ValidationTokenEnum.OpenBracket,
|
|
13043
|
+
"]": exports.ValidationTokenEnum.CloseBracket,
|
|
13044
|
+
"{": exports.ValidationTokenEnum.OpenCurlyBrace,
|
|
13045
|
+
"}": exports.ValidationTokenEnum.CloseCurlyBrace,
|
|
13046
|
+
"?": exports.ValidationTokenEnum.QuestionMark,
|
|
13047
|
+
"!": exports.ValidationTokenEnum.Exclamation,
|
|
13048
|
+
"#": exports.ValidationTokenEnum.HashMark,
|
|
13049
|
+
"<": exports.ValidationTokenEnum.LessThan,
|
|
13050
|
+
">": exports.ValidationTokenEnum.GreaterThan,
|
|
13051
|
+
" ": exports.ValidationTokenEnum.Whitespace,
|
|
13052
|
+
"\t": exports.ValidationTokenEnum.Whitespace,
|
|
13053
|
+
"\r": exports.ValidationTokenEnum.Whitespace,
|
|
13054
|
+
"\n": exports.ValidationTokenEnum.Whitespace,
|
|
13055
|
+
"\f": exports.ValidationTokenEnum.Whitespace,
|
|
12989
13056
|
// '∞'
|
|
12990
|
-
"\u221e": ValidationTokenEnum.InfinityToken,
|
|
13057
|
+
"\u221e": exports.ValidationTokenEnum.InfinityToken,
|
|
12991
13058
|
};
|
|
12992
13059
|
const makeBinaryOp = new Map([
|
|
12993
|
-
[ValidationTokenEnum.Column, ValidationTokenEnum.ColumnToken],
|
|
12994
|
-
[ValidationTokenEnum.Ampersand, ValidationTokenEnum.AmpersandToken],
|
|
13060
|
+
[exports.ValidationTokenEnum.Column, exports.ValidationTokenEnum.ColumnToken],
|
|
13061
|
+
[exports.ValidationTokenEnum.Ampersand, exports.ValidationTokenEnum.AmpersandToken],
|
|
12995
13062
|
]);
|
|
12996
13063
|
/**
|
|
12997
13064
|
* single character symbols, by character code
|
|
@@ -13078,7 +13145,7 @@
|
|
|
13078
13145
|
function getTokenType(token, loc) {
|
|
13079
13146
|
if (token === "<an+b>") {
|
|
13080
13147
|
return {
|
|
13081
|
-
typ: ValidationTokenEnum.PropertyType,
|
|
13148
|
+
typ: exports.ValidationTokenEnum.PropertyType,
|
|
13082
13149
|
val: token.slice(1, -1),
|
|
13083
13150
|
[LOC]: loc,
|
|
13084
13151
|
};
|
|
@@ -13087,7 +13154,7 @@
|
|
|
13087
13154
|
// " or '
|
|
13088
13155
|
if (first === 34 || first === 39) {
|
|
13089
13156
|
return {
|
|
13090
|
-
typ: ValidationTokenEnum.StringToken,
|
|
13157
|
+
typ: exports.ValidationTokenEnum.StringToken,
|
|
13091
13158
|
val: token,
|
|
13092
13159
|
[LOC]: loc,
|
|
13093
13160
|
};
|
|
@@ -13095,7 +13162,7 @@
|
|
|
13095
13162
|
// integer, optionally negative: range bounds such as `<integer [-∞,-1]>`
|
|
13096
13163
|
if (isDigits(token) || (first === 45 && isDigits(token.slice(1)))) {
|
|
13097
13164
|
return {
|
|
13098
|
-
typ: ValidationTokenEnum.Number,
|
|
13165
|
+
typ: exports.ValidationTokenEnum.Number,
|
|
13099
13166
|
val: Number(token),
|
|
13100
13167
|
[LOC]: loc,
|
|
13101
13168
|
};
|
|
@@ -13104,7 +13171,7 @@
|
|
|
13104
13171
|
if (dimension) {
|
|
13105
13172
|
// @ts-expect-error
|
|
13106
13173
|
return {
|
|
13107
|
-
typ: ValidationTokenEnum.Dimension,
|
|
13174
|
+
typ: exports.ValidationTokenEnum.Dimension,
|
|
13108
13175
|
unit: exports.EnumToken[dimension.typ],
|
|
13109
13176
|
val: dimension.val,
|
|
13110
13177
|
unitText: dimension.unit,
|
|
@@ -13113,7 +13180,7 @@
|
|
|
13113
13180
|
}
|
|
13114
13181
|
if (isPseudo(token)) {
|
|
13115
13182
|
return {
|
|
13116
|
-
typ: ValidationTokenEnum.PseudoClassToken,
|
|
13183
|
+
typ: exports.ValidationTokenEnum.PseudoClassToken,
|
|
13117
13184
|
val: token,
|
|
13118
13185
|
[LOC]: loc,
|
|
13119
13186
|
};
|
|
@@ -13121,31 +13188,31 @@
|
|
|
13121
13188
|
// @
|
|
13122
13189
|
if (first === 64 && isIdent(token.slice(1))) {
|
|
13123
13190
|
return {
|
|
13124
|
-
typ: ValidationTokenEnum.AtRule,
|
|
13191
|
+
typ: exports.ValidationTokenEnum.AtRule,
|
|
13125
13192
|
val: token.slice(1),
|
|
13126
13193
|
[LOC]: loc,
|
|
13127
13194
|
};
|
|
13128
13195
|
}
|
|
13129
13196
|
return {
|
|
13130
|
-
typ: ValidationTokenEnum.Keyword,
|
|
13197
|
+
typ: exports.ValidationTokenEnum.Keyword,
|
|
13131
13198
|
val: token,
|
|
13132
13199
|
[LOC]: loc,
|
|
13133
13200
|
};
|
|
13134
13201
|
}
|
|
13135
13202
|
function trimSyntaxArray(tokens) {
|
|
13136
|
-
while (tokens[0]?.typ === ValidationTokenEnum.Whitespace) {
|
|
13203
|
+
while (tokens[0]?.typ === exports.ValidationTokenEnum.Whitespace) {
|
|
13137
13204
|
tokens.shift();
|
|
13138
13205
|
}
|
|
13139
|
-
while (tokens[tokens.length - 1]?.typ === ValidationTokenEnum.Whitespace) {
|
|
13206
|
+
while (tokens[tokens.length - 1]?.typ === exports.ValidationTokenEnum.Whitespace) {
|
|
13140
13207
|
tokens.pop();
|
|
13141
13208
|
}
|
|
13142
13209
|
let i = 0;
|
|
13143
13210
|
for (; i < tokens.length; i++) {
|
|
13144
|
-
if (tokens[i].typ === ValidationTokenEnum.Comma) {
|
|
13145
|
-
if (i + 1 < tokens.length && tokens[i + 1].typ === ValidationTokenEnum.Whitespace) {
|
|
13211
|
+
if (tokens[i].typ === exports.ValidationTokenEnum.Comma) {
|
|
13212
|
+
if (i + 1 < tokens.length && tokens[i + 1].typ === exports.ValidationTokenEnum.Whitespace) {
|
|
13146
13213
|
tokens.splice(i + 1, 1);
|
|
13147
13214
|
}
|
|
13148
|
-
if (i > 0 && tokens[i - 1].typ === ValidationTokenEnum.Whitespace) {
|
|
13215
|
+
if (i > 0 && tokens[i - 1].typ === exports.ValidationTokenEnum.Whitespace) {
|
|
13149
13216
|
tokens.splice(--i, 1);
|
|
13150
13217
|
}
|
|
13151
13218
|
}
|
|
@@ -13256,9 +13323,9 @@
|
|
|
13256
13323
|
}
|
|
13257
13324
|
type = symbolTypes.get(code) ?? null;
|
|
13258
13325
|
if (type != null) {
|
|
13259
|
-
if (type === ValidationTokenEnum.Whitespace) {
|
|
13326
|
+
if (type === exports.ValidationTokenEnum.Whitespace) {
|
|
13260
13327
|
let k = i;
|
|
13261
|
-
while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === ValidationTokenEnum.Whitespace) {
|
|
13328
|
+
while (k + 1 < length && symbolTypes.get(syntax.charCodeAt(k + 1)) === exports.ValidationTokenEnum.Whitespace) {
|
|
13262
13329
|
k++;
|
|
13263
13330
|
}
|
|
13264
13331
|
if (k !== i) {
|
|
@@ -13288,7 +13355,7 @@
|
|
|
13288
13355
|
clear();
|
|
13289
13356
|
}
|
|
13290
13357
|
tokens.push({
|
|
13291
|
-
typ: ValidationTokenEnum.Colon,
|
|
13358
|
+
typ: exports.ValidationTokenEnum.Colon,
|
|
13292
13359
|
[LOC]: loc,
|
|
13293
13360
|
});
|
|
13294
13361
|
break;
|
|
@@ -13321,7 +13388,7 @@
|
|
|
13321
13388
|
tokens.push(getTokenType(buffer(), startToken()));
|
|
13322
13389
|
}
|
|
13323
13390
|
tokens.push({
|
|
13324
|
-
typ: ValidationTokenEnum.EOF,
|
|
13391
|
+
typ: exports.ValidationTokenEnum.EOF,
|
|
13325
13392
|
[LOC]: { ind: posInd, lin: posLin, col: posCol },
|
|
13326
13393
|
});
|
|
13327
13394
|
position.ind = posInd;
|
|
@@ -13347,30 +13414,30 @@
|
|
|
13347
13414
|
for (const token of iterator) {
|
|
13348
13415
|
tokens.push(token);
|
|
13349
13416
|
switch (token.typ) {
|
|
13350
|
-
case ValidationTokenEnum.EOF:
|
|
13351
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
13417
|
+
case exports.ValidationTokenEnum.EOF:
|
|
13418
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
|
|
13352
13419
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13353
13420
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13354
13421
|
stack.pop();
|
|
13355
13422
|
}
|
|
13356
|
-
else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
|
|
13423
|
+
else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
|
|
13357
13424
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13358
13425
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
13359
13426
|
stack.pop();
|
|
13360
13427
|
}
|
|
13361
|
-
else if (stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
|
|
13428
|
+
else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.ColumnToken) {
|
|
13362
13429
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13363
13430
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13364
13431
|
stack.pop();
|
|
13365
13432
|
}
|
|
13366
13433
|
tokens.pop();
|
|
13367
13434
|
break;
|
|
13368
|
-
case ValidationTokenEnum.Pipe:
|
|
13435
|
+
case exports.ValidationTokenEnum.Pipe:
|
|
13369
13436
|
{
|
|
13370
|
-
while (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken ||
|
|
13371
|
-
stack.at(-1)?.typ === ValidationTokenEnum.ColumnToken) {
|
|
13437
|
+
while (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken ||
|
|
13438
|
+
stack.at(-1)?.typ === exports.ValidationTokenEnum.ColumnToken) {
|
|
13372
13439
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13373
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
|
|
13440
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
|
|
13374
13441
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
13375
13442
|
}
|
|
13376
13443
|
else {
|
|
@@ -13379,9 +13446,9 @@
|
|
|
13379
13446
|
stack.pop();
|
|
13380
13447
|
}
|
|
13381
13448
|
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
13382
|
-
if (stack.at(-1)?.typ !== ValidationTokenEnum.PipeToken) {
|
|
13449
|
+
if (stack.at(-1)?.typ !== exports.ValidationTokenEnum.PipeToken) {
|
|
13383
13450
|
stack.push(Object.assign(token, {
|
|
13384
|
-
typ: ValidationTokenEnum.PipeToken,
|
|
13451
|
+
typ: exports.ValidationTokenEnum.PipeToken,
|
|
13385
13452
|
chi: [trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2))],
|
|
13386
13453
|
}));
|
|
13387
13454
|
break;
|
|
@@ -13390,11 +13457,11 @@
|
|
|
13390
13457
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
|
|
13391
13458
|
}
|
|
13392
13459
|
break;
|
|
13393
|
-
case ValidationTokenEnum.Ampersand:
|
|
13460
|
+
case exports.ValidationTokenEnum.Ampersand:
|
|
13394
13461
|
{
|
|
13395
13462
|
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
13396
13463
|
if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
|
|
13397
|
-
if (token.typ === ValidationTokenEnum.Ampersand) {
|
|
13464
|
+
if (token.typ === exports.ValidationTokenEnum.Ampersand) {
|
|
13398
13465
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
13399
13466
|
stack.pop();
|
|
13400
13467
|
stack.push(Object.assign(token, {
|
|
@@ -13426,7 +13493,7 @@
|
|
|
13426
13493
|
}
|
|
13427
13494
|
}
|
|
13428
13495
|
break;
|
|
13429
|
-
case ValidationTokenEnum.Column:
|
|
13496
|
+
case exports.ValidationTokenEnum.Column:
|
|
13430
13497
|
{
|
|
13431
13498
|
let index = stack.length === 0 ? -1 : tokens.lastIndexOf(stack.at(-1));
|
|
13432
13499
|
if (stack.at(-1)?.typ === makeBinaryOp.get(token.typ)) {
|
|
@@ -13449,18 +13516,18 @@
|
|
|
13449
13516
|
}
|
|
13450
13517
|
}
|
|
13451
13518
|
break;
|
|
13452
|
-
case ValidationTokenEnum.OpenParenthesis:
|
|
13453
|
-
if (tokens.at(-2)?.typ === ValidationTokenEnum.Keyword) {
|
|
13519
|
+
case exports.ValidationTokenEnum.OpenParenthesis:
|
|
13520
|
+
if (tokens.at(-2)?.typ === exports.ValidationTokenEnum.Keyword) {
|
|
13454
13521
|
stack.push(Object.assign(tokens.at(-2), {
|
|
13455
|
-
typ: ValidationTokenEnum.Function,
|
|
13522
|
+
typ: exports.ValidationTokenEnum.Function,
|
|
13456
13523
|
chi: [],
|
|
13457
13524
|
}));
|
|
13458
13525
|
tokens.pop();
|
|
13459
13526
|
break;
|
|
13460
13527
|
}
|
|
13461
|
-
if (tokens.at(-2)?.typ === ValidationTokenEnum.PseudoClassToken) {
|
|
13528
|
+
if (tokens.at(-2)?.typ === exports.ValidationTokenEnum.PseudoClassToken) {
|
|
13462
13529
|
stack.push(Object.assign(tokens.at(-2), {
|
|
13463
|
-
typ: ValidationTokenEnum.PseudoClassFunctionToken,
|
|
13530
|
+
typ: exports.ValidationTokenEnum.PseudoClassFunctionToken,
|
|
13464
13531
|
chi: [],
|
|
13465
13532
|
}));
|
|
13466
13533
|
tokens.pop();
|
|
@@ -13468,14 +13535,14 @@
|
|
|
13468
13535
|
}
|
|
13469
13536
|
stack.push(token);
|
|
13470
13537
|
break;
|
|
13471
|
-
case ValidationTokenEnum.CloseParenthesis:
|
|
13472
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
13538
|
+
case exports.ValidationTokenEnum.CloseParenthesis:
|
|
13539
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
|
|
13473
13540
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13474
13541
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13475
13542
|
stack.pop();
|
|
13476
13543
|
}
|
|
13477
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.OpenParenthesis ||
|
|
13478
|
-
(stack.at(-1)?.typ === ValidationTokenEnum.PropertyType &&
|
|
13544
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.OpenParenthesis ||
|
|
13545
|
+
(stack.at(-1)?.typ === exports.ValidationTokenEnum.PropertyType &&
|
|
13479
13546
|
stack.at(-1).val === "function-token")) {
|
|
13480
13547
|
stack.pop();
|
|
13481
13548
|
}
|
|
@@ -13486,13 +13553,13 @@
|
|
|
13486
13553
|
// );
|
|
13487
13554
|
// stack.pop();
|
|
13488
13555
|
// }
|
|
13489
|
-
else if (stack.at(-1)?.typ === ValidationTokenEnum.AmpersandToken) {
|
|
13556
|
+
else if (stack.at(-1)?.typ === exports.ValidationTokenEnum.AmpersandToken) {
|
|
13490
13557
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13491
13558
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
13492
13559
|
stack.pop();
|
|
13493
13560
|
}
|
|
13494
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.Function ||
|
|
13495
|
-
stack.at(-1)?.typ === ValidationTokenEnum.PseudoClassFunctionToken) {
|
|
13561
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.Function ||
|
|
13562
|
+
stack.at(-1)?.typ === exports.ValidationTokenEnum.PseudoClassFunctionToken) {
|
|
13496
13563
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13497
13564
|
tokens.pop();
|
|
13498
13565
|
stack.at(-1).chi =
|
|
@@ -13500,11 +13567,11 @@
|
|
|
13500
13567
|
stack.pop();
|
|
13501
13568
|
}
|
|
13502
13569
|
break;
|
|
13503
|
-
case ValidationTokenEnum.GreaterThan:
|
|
13504
|
-
if (tokens[tokens.length - 3]?.typ === ValidationTokenEnum.LessThan) {
|
|
13505
|
-
if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.Keyword) {
|
|
13570
|
+
case exports.ValidationTokenEnum.GreaterThan:
|
|
13571
|
+
if (tokens[tokens.length - 3]?.typ === exports.ValidationTokenEnum.LessThan) {
|
|
13572
|
+
if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.Keyword) {
|
|
13506
13573
|
Object.assign(tokens[tokens.length - 3], {
|
|
13507
|
-
typ: ValidationTokenEnum.PropertyType,
|
|
13574
|
+
typ: exports.ValidationTokenEnum.PropertyType,
|
|
13508
13575
|
val: tokens[tokens.length - 2].val,
|
|
13509
13576
|
});
|
|
13510
13577
|
if ("range" in tokens[tokens.length - 2]) {
|
|
@@ -13516,40 +13583,40 @@
|
|
|
13516
13583
|
stack.push(tokens.at(-1));
|
|
13517
13584
|
}
|
|
13518
13585
|
}
|
|
13519
|
-
else if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.StringToken) {
|
|
13586
|
+
else if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.StringToken) {
|
|
13520
13587
|
Object.assign(tokens[tokens.length - 3], {
|
|
13521
|
-
typ: ValidationTokenEnum.DeclarationType,
|
|
13588
|
+
typ: exports.ValidationTokenEnum.DeclarationType,
|
|
13522
13589
|
val: tokens[tokens.length - 2].val.slice(1, -1),
|
|
13523
13590
|
});
|
|
13524
13591
|
tokens.splice(tokens.length - 2, 2);
|
|
13525
13592
|
}
|
|
13526
|
-
else if (tokens[tokens.length - 2]?.typ === ValidationTokenEnum.Function) {
|
|
13593
|
+
else if (tokens[tokens.length - 2]?.typ === exports.ValidationTokenEnum.Function) {
|
|
13527
13594
|
Object.assign(tokens[tokens.length - 3], {
|
|
13528
|
-
typ: ValidationTokenEnum.FunctionDefinition,
|
|
13595
|
+
typ: exports.ValidationTokenEnum.FunctionDefinition,
|
|
13529
13596
|
val: tokens[tokens.length - 2].val,
|
|
13530
13597
|
});
|
|
13531
13598
|
tokens.splice(tokens.length - 2, 2);
|
|
13532
13599
|
}
|
|
13533
13600
|
}
|
|
13534
13601
|
break;
|
|
13535
|
-
case ValidationTokenEnum.OpenBracket:
|
|
13602
|
+
case exports.ValidationTokenEnum.OpenBracket:
|
|
13536
13603
|
stack.push(token);
|
|
13537
13604
|
break;
|
|
13538
|
-
case ValidationTokenEnum.CloseBracket:
|
|
13605
|
+
case exports.ValidationTokenEnum.CloseBracket:
|
|
13539
13606
|
while (true) {
|
|
13540
|
-
if (stack.at(-1).typ === ValidationTokenEnum.AmpersandToken) {
|
|
13607
|
+
if (stack.at(-1).typ === exports.ValidationTokenEnum.AmpersandToken) {
|
|
13541
13608
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13542
13609
|
stack.at(-1).r = trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2));
|
|
13543
13610
|
stack.pop();
|
|
13544
13611
|
continue;
|
|
13545
13612
|
}
|
|
13546
|
-
else if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
|
|
13613
|
+
else if (stack.at(-1).typ === exports.ValidationTokenEnum.ColumnToken) {
|
|
13547
13614
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13548
13615
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13549
13616
|
stack.pop();
|
|
13550
13617
|
continue;
|
|
13551
13618
|
}
|
|
13552
|
-
if (stack.at(-1).typ === ValidationTokenEnum.PipeToken) {
|
|
13619
|
+
if (stack.at(-1).typ === exports.ValidationTokenEnum.PipeToken) {
|
|
13553
13620
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13554
13621
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13555
13622
|
stack.pop();
|
|
@@ -13565,24 +13632,24 @@
|
|
|
13565
13632
|
{
|
|
13566
13633
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13567
13634
|
// the lower bound of a range may be '-∞': <integer [-∞,-1]>
|
|
13568
|
-
const isNegativeInfinity = tokens[index + 1]?.typ === ValidationTokenEnum.Keyword &&
|
|
13635
|
+
const isNegativeInfinity = tokens[index + 1]?.typ === exports.ValidationTokenEnum.Keyword &&
|
|
13569
13636
|
tokens[index + 1].val === "-" &&
|
|
13570
|
-
tokens[index + 2]?.typ === ValidationTokenEnum.InfinityToken;
|
|
13637
|
+
tokens[index + 2]?.typ === exports.ValidationTokenEnum.InfinityToken;
|
|
13571
13638
|
if (isNegativeInfinity &&
|
|
13572
|
-
(tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
|
|
13573
|
-
tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
|
|
13574
|
-
tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
|
|
13575
|
-
tokens[index + 3]?.typ === ValidationTokenEnum.Comma &&
|
|
13576
|
-
(tokens[index + 4]?.typ === ValidationTokenEnum.Number ||
|
|
13577
|
-
tokens[index + 4]?.typ === ValidationTokenEnum.Dimension ||
|
|
13578
|
-
tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken) &&
|
|
13579
|
-
tokens[index + 5]?.typ === ValidationTokenEnum.CloseBracket) {
|
|
13639
|
+
(tokens[index - 2]?.typ === exports.ValidationTokenEnum.Keyword ||
|
|
13640
|
+
tokens[index - 2]?.typ === exports.ValidationTokenEnum.StringToken) &&
|
|
13641
|
+
tokens[index - 1]?.typ === exports.ValidationTokenEnum.Whitespace &&
|
|
13642
|
+
tokens[index + 3]?.typ === exports.ValidationTokenEnum.Comma &&
|
|
13643
|
+
(tokens[index + 4]?.typ === exports.ValidationTokenEnum.Number ||
|
|
13644
|
+
tokens[index + 4]?.typ === exports.ValidationTokenEnum.Dimension ||
|
|
13645
|
+
tokens[index + 4]?.typ === exports.ValidationTokenEnum.InfinityToken) &&
|
|
13646
|
+
tokens[index + 5]?.typ === exports.ValidationTokenEnum.CloseBracket) {
|
|
13580
13647
|
stack.pop();
|
|
13581
13648
|
// a null bound is unbounded
|
|
13582
13649
|
Object.assign(tokens[index - 2], {
|
|
13583
13650
|
range: {
|
|
13584
13651
|
min: null,
|
|
13585
|
-
max: tokens[index + 4]?.typ === ValidationTokenEnum.InfinityToken
|
|
13652
|
+
max: tokens[index + 4]?.typ === exports.ValidationTokenEnum.InfinityToken
|
|
13586
13653
|
? null
|
|
13587
13654
|
: tokens[index + 4],
|
|
13588
13655
|
},
|
|
@@ -13590,11 +13657,11 @@
|
|
|
13590
13657
|
tokens.splice(index - 1, 8);
|
|
13591
13658
|
break;
|
|
13592
13659
|
}
|
|
13593
|
-
if ((tokens[index - 2]?.typ === ValidationTokenEnum.Keyword ||
|
|
13594
|
-
tokens[index - 2]?.typ === ValidationTokenEnum.StringToken) &&
|
|
13595
|
-
tokens[index - 1]?.typ === ValidationTokenEnum.Whitespace &&
|
|
13596
|
-
(tokens[index + 1]?.typ === ValidationTokenEnum.Number ||
|
|
13597
|
-
tokens[index + 1]?.typ === ValidationTokenEnum.Dimension)) {
|
|
13660
|
+
if ((tokens[index - 2]?.typ === exports.ValidationTokenEnum.Keyword ||
|
|
13661
|
+
tokens[index - 2]?.typ === exports.ValidationTokenEnum.StringToken) &&
|
|
13662
|
+
tokens[index - 1]?.typ === exports.ValidationTokenEnum.Whitespace &&
|
|
13663
|
+
(tokens[index + 1]?.typ === exports.ValidationTokenEnum.Number ||
|
|
13664
|
+
tokens[index + 1]?.typ === exports.ValidationTokenEnum.Dimension)) {
|
|
13598
13665
|
// if (tokens[index + 2]?.typ === ValidationTokenEnum.CloseBracket) {
|
|
13599
13666
|
// stack.pop();
|
|
13600
13667
|
// Object.assign(tokens[index - 2], {
|
|
@@ -13606,10 +13673,10 @@
|
|
|
13606
13673
|
// tokens.splice(index - 1, 5);
|
|
13607
13674
|
// break;
|
|
13608
13675
|
// }
|
|
13609
|
-
if (tokens[index + 2]?.typ === ValidationTokenEnum.Comma &&
|
|
13676
|
+
if (tokens[index + 2]?.typ === exports.ValidationTokenEnum.Comma &&
|
|
13610
13677
|
(tokens[index + 3]?.typ === tokens[index + 1]?.typ ||
|
|
13611
|
-
tokens[index + 3]?.typ === ValidationTokenEnum.InfinityToken) &&
|
|
13612
|
-
tokens[index + 4]?.typ === ValidationTokenEnum.CloseBracket) {
|
|
13678
|
+
tokens[index + 3]?.typ === exports.ValidationTokenEnum.InfinityToken) &&
|
|
13679
|
+
tokens[index + 4]?.typ === exports.ValidationTokenEnum.CloseBracket) {
|
|
13613
13680
|
stack.pop();
|
|
13614
13681
|
Object.assign(tokens[index - 2], {
|
|
13615
13682
|
range: {
|
|
@@ -13628,17 +13695,17 @@
|
|
|
13628
13695
|
startIndex = tokens.lastIndexOf(currentToken);
|
|
13629
13696
|
endIndex = tokens.indexOf(token);
|
|
13630
13697
|
Object.assign(currentToken, {
|
|
13631
|
-
typ: ValidationTokenEnum.Bracket,
|
|
13698
|
+
typ: exports.ValidationTokenEnum.Bracket,
|
|
13632
13699
|
chi: trimSyntaxArray(tokens.slice(startIndex + 1, endIndex)),
|
|
13633
13700
|
});
|
|
13634
13701
|
tokens.splice(startIndex + 1, tokens.length);
|
|
13635
13702
|
break;
|
|
13636
13703
|
// {
|
|
13637
|
-
case ValidationTokenEnum.OpenCurlyBrace:
|
|
13704
|
+
case exports.ValidationTokenEnum.OpenCurlyBrace:
|
|
13638
13705
|
stack.push(token);
|
|
13639
13706
|
break;
|
|
13640
13707
|
// }
|
|
13641
|
-
case ValidationTokenEnum.CloseCurlyBrace:
|
|
13708
|
+
case exports.ValidationTokenEnum.CloseCurlyBrace:
|
|
13642
13709
|
while (true) {
|
|
13643
13710
|
// if ((stack.at(-1) as ValidationToken).typ == ValidationTokenEnum.AmpersandToken) {
|
|
13644
13711
|
// let index: number = tokens.lastIndexOf(stack.at(-1) as ValidationToken);
|
|
@@ -13648,13 +13715,13 @@
|
|
|
13648
13715
|
// stack.pop();
|
|
13649
13716
|
// continue;
|
|
13650
13717
|
// } else
|
|
13651
|
-
if (stack.at(-1).typ === ValidationTokenEnum.ColumnToken) {
|
|
13718
|
+
if (stack.at(-1).typ === exports.ValidationTokenEnum.ColumnToken) {
|
|
13652
13719
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13653
13720
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13654
13721
|
stack.pop();
|
|
13655
13722
|
continue;
|
|
13656
13723
|
}
|
|
13657
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
13724
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
|
|
13658
13725
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13659
13726
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 2)));
|
|
13660
13727
|
stack.pop();
|
|
@@ -13669,7 +13736,7 @@
|
|
|
13669
13736
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13670
13737
|
const slice = tokens.slice(index + 1, -1);
|
|
13671
13738
|
if (slice.length === 1 || slice.length === 3) {
|
|
13672
|
-
if (slice[0].typ === ValidationTokenEnum.Number) {
|
|
13739
|
+
if (slice[0].typ === exports.ValidationTokenEnum.Number) {
|
|
13673
13740
|
Object.assign(tokens[index - 1], {
|
|
13674
13741
|
match: {
|
|
13675
13742
|
min: slice[0],
|
|
@@ -13691,7 +13758,7 @@
|
|
|
13691
13758
|
Object.assign(tokens[index - 1], {
|
|
13692
13759
|
match: {
|
|
13693
13760
|
min: slice[0],
|
|
13694
|
-
max: slice[2].typ === ValidationTokenEnum.InfinityToken
|
|
13761
|
+
max: slice[2].typ === exports.ValidationTokenEnum.InfinityToken
|
|
13695
13762
|
? Number.POSITIVE_INFINITY
|
|
13696
13763
|
: slice[2],
|
|
13697
13764
|
},
|
|
@@ -13705,11 +13772,11 @@
|
|
|
13705
13772
|
}
|
|
13706
13773
|
stack.pop();
|
|
13707
13774
|
break;
|
|
13708
|
-
case ValidationTokenEnum.Star:
|
|
13775
|
+
case exports.ValidationTokenEnum.Star:
|
|
13709
13776
|
tokens.pop();
|
|
13710
13777
|
tokens.at(-1).isRepeatable = true;
|
|
13711
13778
|
break;
|
|
13712
|
-
case ValidationTokenEnum.QuestionMark:
|
|
13779
|
+
case exports.ValidationTokenEnum.QuestionMark:
|
|
13713
13780
|
tokens.pop();
|
|
13714
13781
|
// if the previous token is a comma, we wrap them in a virtual group and mark the group as optional
|
|
13715
13782
|
{
|
|
@@ -13719,14 +13786,14 @@
|
|
|
13719
13786
|
// sliceIndex = tokens.length - 2;
|
|
13720
13787
|
// } else
|
|
13721
13788
|
// {
|
|
13722
|
-
isGroup = tokens.at(-3)?.typ === ValidationTokenEnum.Comma;
|
|
13789
|
+
isGroup = tokens.at(-3)?.typ === exports.ValidationTokenEnum.Comma;
|
|
13723
13790
|
if (isGroup) {
|
|
13724
13791
|
sliceIndex = tokens.length - 3;
|
|
13725
13792
|
}
|
|
13726
13793
|
// }
|
|
13727
13794
|
if (isGroup) {
|
|
13728
13795
|
tokens.splice(sliceIndex, tokens.length - sliceIndex, {
|
|
13729
|
-
typ: ValidationTokenEnum.OptionalGroupToken,
|
|
13796
|
+
typ: exports.ValidationTokenEnum.OptionalGroupToken,
|
|
13730
13797
|
chi: trimSyntaxArray(tokens.slice(sliceIndex)),
|
|
13731
13798
|
isOptional: true,
|
|
13732
13799
|
});
|
|
@@ -13736,15 +13803,15 @@
|
|
|
13736
13803
|
}
|
|
13737
13804
|
}
|
|
13738
13805
|
break;
|
|
13739
|
-
case ValidationTokenEnum.Comma:
|
|
13806
|
+
case exports.ValidationTokenEnum.Comma:
|
|
13740
13807
|
{
|
|
13741
13808
|
let sliceIndex = -1;
|
|
13742
13809
|
// if (tokens.at(-2)?.isOptional && tokens.at(-2)!.typ !== ValidationTokenEnum.OptionalGroupToken) {
|
|
13743
13810
|
// sliceIndex = tokens.length - 2;
|
|
13744
13811
|
// } else
|
|
13745
|
-
if (tokens.at(-2).typ === ValidationTokenEnum.Whitespace &&
|
|
13812
|
+
if (tokens.at(-2).typ === exports.ValidationTokenEnum.Whitespace &&
|
|
13746
13813
|
tokens.at(-3)?.isOptional &&
|
|
13747
|
-
tokens.at(-3).typ !== ValidationTokenEnum.OptionalGroupToken) {
|
|
13814
|
+
tokens.at(-3).typ !== exports.ValidationTokenEnum.OptionalGroupToken) {
|
|
13748
13815
|
sliceIndex = tokens.length - 3;
|
|
13749
13816
|
}
|
|
13750
13817
|
if (sliceIndex !== -1) {
|
|
@@ -13752,7 +13819,7 @@
|
|
|
13752
13819
|
tokens.pop();
|
|
13753
13820
|
}
|
|
13754
13821
|
tokens.splice(sliceIndex, tokens.length - sliceIndex, {
|
|
13755
|
-
typ: ValidationTokenEnum.OptionalGroupToken,
|
|
13822
|
+
typ: exports.ValidationTokenEnum.OptionalGroupToken,
|
|
13756
13823
|
chi: trimSyntaxArray(tokens.slice(sliceIndex).map((t) => {
|
|
13757
13824
|
delete t.isOptional;
|
|
13758
13825
|
return t;
|
|
@@ -13762,22 +13829,22 @@
|
|
|
13762
13829
|
}
|
|
13763
13830
|
}
|
|
13764
13831
|
break;
|
|
13765
|
-
case ValidationTokenEnum.HashMark:
|
|
13832
|
+
case exports.ValidationTokenEnum.HashMark:
|
|
13766
13833
|
tokens.pop();
|
|
13767
13834
|
tokens.at(-1).isList = true;
|
|
13768
13835
|
break;
|
|
13769
|
-
case ValidationTokenEnum.Exclamation:
|
|
13836
|
+
case exports.ValidationTokenEnum.Exclamation:
|
|
13770
13837
|
tokens.pop();
|
|
13771
13838
|
tokens.at(-1).isMandatatoryGroup = true;
|
|
13772
13839
|
break;
|
|
13773
|
-
case ValidationTokenEnum.Plus:
|
|
13840
|
+
case exports.ValidationTokenEnum.Plus:
|
|
13774
13841
|
tokens.pop();
|
|
13775
13842
|
tokens.at(-1).isRepeatableAtLeastOnce = true;
|
|
13776
13843
|
break;
|
|
13777
13844
|
}
|
|
13778
13845
|
}
|
|
13779
13846
|
if (stack.length > 0) {
|
|
13780
|
-
if (stack.at(-1)?.typ === ValidationTokenEnum.PipeToken) {
|
|
13847
|
+
if (stack.at(-1)?.typ === exports.ValidationTokenEnum.PipeToken) {
|
|
13781
13848
|
let index = tokens.lastIndexOf(stack.at(-1));
|
|
13782
13849
|
stack.at(-1).chi.push(trimSyntaxArray(tokens.splice(index + 1, tokens.length - index - 1)));
|
|
13783
13850
|
stack.pop();
|
|
@@ -13977,8 +14044,8 @@
|
|
|
13977
14044
|
let blockEnd = -1;
|
|
13978
14045
|
let i;
|
|
13979
14046
|
for (i = 0; i < syntaxRules.length; i++) {
|
|
13980
|
-
if (syntaxRules[i].typ === ValidationTokenEnum.OpenCurlyBrace ||
|
|
13981
|
-
syntaxRules[i].typ === ValidationTokenEnum.SemiColon) {
|
|
14047
|
+
if (syntaxRules[i].typ === exports.ValidationTokenEnum.OpenCurlyBrace ||
|
|
14048
|
+
syntaxRules[i].typ === exports.ValidationTokenEnum.SemiColon) {
|
|
13982
14049
|
blockStart = i;
|
|
13983
14050
|
break;
|
|
13984
14051
|
}
|
|
@@ -13986,7 +14053,7 @@
|
|
|
13986
14053
|
if (blockStart !== -1) {
|
|
13987
14054
|
i = syntaxRules.length;
|
|
13988
14055
|
while (i--) {
|
|
13989
|
-
if (syntaxRules[i].typ === ValidationTokenEnum.CloseCurlyBrace) {
|
|
14056
|
+
if (syntaxRules[i].typ === exports.ValidationTokenEnum.CloseCurlyBrace) {
|
|
13990
14057
|
blockEnd = i;
|
|
13991
14058
|
break;
|
|
13992
14059
|
}
|
|
@@ -14007,14 +14074,14 @@
|
|
|
14007
14074
|
let optionalBody = false;
|
|
14008
14075
|
if (block == null || block.length === 0) {
|
|
14009
14076
|
let k = prelude.length - 1;
|
|
14010
|
-
if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
|
|
14077
|
+
if (exports.ValidationTokenEnum.SemiColon === prelude[k].typ) {
|
|
14011
14078
|
k--;
|
|
14012
14079
|
}
|
|
14013
|
-
if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
|
|
14080
|
+
if (k >= 0 && exports.ValidationTokenEnum.Bracket === prelude[k].typ) {
|
|
14014
14081
|
if (prelude[k].chi[0].typ ===
|
|
14015
|
-
ValidationTokenEnum.OpenCurlyBrace &&
|
|
14082
|
+
exports.ValidationTokenEnum.OpenCurlyBrace &&
|
|
14016
14083
|
prelude[k].chi.at(-1).typ ===
|
|
14017
|
-
ValidationTokenEnum.CloseCurlyBrace) {
|
|
14084
|
+
exports.ValidationTokenEnum.CloseCurlyBrace) {
|
|
14018
14085
|
block = prelude[k].chi.slice(1, -1);
|
|
14019
14086
|
optionalBody = prelude[k].isOptional ?? false;
|
|
14020
14087
|
}
|
|
@@ -14041,7 +14108,7 @@
|
|
|
14041
14108
|
* @param syntax
|
|
14042
14109
|
*/
|
|
14043
14110
|
function isNullable(syntax) {
|
|
14044
|
-
if (syntax.typ === ValidationTokenEnum.Whitespace) {
|
|
14111
|
+
if (syntax.typ === exports.ValidationTokenEnum.Whitespace) {
|
|
14045
14112
|
return true;
|
|
14046
14113
|
}
|
|
14047
14114
|
// `[ <a>? <b>? ]!`: at least one token
|
|
@@ -14054,13 +14121,13 @@
|
|
|
14054
14121
|
let nullable = nullableSyntaxes.get(syntax);
|
|
14055
14122
|
if (nullable == null) {
|
|
14056
14123
|
switch (syntax.typ) {
|
|
14057
|
-
case ValidationTokenEnum.Bracket:
|
|
14124
|
+
case exports.ValidationTokenEnum.Bracket:
|
|
14058
14125
|
nullable = syntax.chi.every(isNullable);
|
|
14059
14126
|
break;
|
|
14060
|
-
case ValidationTokenEnum.PipeToken:
|
|
14127
|
+
case exports.ValidationTokenEnum.PipeToken:
|
|
14061
14128
|
nullable = syntax.chi.some((syntaxes) => syntaxes.every(isNullable));
|
|
14062
14129
|
break;
|
|
14063
|
-
case ValidationTokenEnum.AmpersandToken:
|
|
14130
|
+
case exports.ValidationTokenEnum.AmpersandToken:
|
|
14064
14131
|
nullable =
|
|
14065
14132
|
syntax.l.every(isNullable) &&
|
|
14066
14133
|
syntax.r.every(isNullable);
|
|
@@ -14299,71 +14366,71 @@
|
|
|
14299
14366
|
let nullable = false;
|
|
14300
14367
|
let first;
|
|
14301
14368
|
switch (syntax.typ) {
|
|
14302
|
-
case ValidationTokenEnum.Whitespace:
|
|
14369
|
+
case exports.ValidationTokenEnum.Whitespace:
|
|
14303
14370
|
nullable = true;
|
|
14304
14371
|
break;
|
|
14305
|
-
case ValidationTokenEnum.Keyword:
|
|
14372
|
+
case exports.ValidationTokenEnum.Keyword:
|
|
14306
14373
|
set.keywords.add(lowercase(syntax.val));
|
|
14307
14374
|
break;
|
|
14308
|
-
case ValidationTokenEnum.Comma:
|
|
14375
|
+
case exports.ValidationTokenEnum.Comma:
|
|
14309
14376
|
set.types.add(exports.EnumToken.CommaTokenType);
|
|
14310
14377
|
break;
|
|
14311
|
-
case ValidationTokenEnum.Colon:
|
|
14378
|
+
case exports.ValidationTokenEnum.Colon:
|
|
14312
14379
|
set.types.add(exports.EnumToken.ColonTokenType);
|
|
14313
14380
|
break;
|
|
14314
|
-
case ValidationTokenEnum.Separator:
|
|
14381
|
+
case exports.ValidationTokenEnum.Separator:
|
|
14315
14382
|
set.types.add(exports.EnumToken.LiteralTokenType);
|
|
14316
14383
|
break;
|
|
14317
|
-
case ValidationTokenEnum.OpenParenthesis:
|
|
14384
|
+
case exports.ValidationTokenEnum.OpenParenthesis:
|
|
14318
14385
|
set.types.add(exports.EnumToken.StartParensTokenType);
|
|
14319
14386
|
break;
|
|
14320
|
-
case ValidationTokenEnum.CloseParenthesis:
|
|
14387
|
+
case exports.ValidationTokenEnum.CloseParenthesis:
|
|
14321
14388
|
set.types.add(exports.EnumToken.EndParensTokenType);
|
|
14322
14389
|
break;
|
|
14323
|
-
case ValidationTokenEnum.OpenCurlyBrace:
|
|
14390
|
+
case exports.ValidationTokenEnum.OpenCurlyBrace:
|
|
14324
14391
|
set.types.add(exports.EnumToken.BlockStartTokenType);
|
|
14325
14392
|
break;
|
|
14326
|
-
case ValidationTokenEnum.Number:
|
|
14393
|
+
case exports.ValidationTokenEnum.Number:
|
|
14327
14394
|
set.types.add(exports.EnumToken.NumberTokenType);
|
|
14328
14395
|
break;
|
|
14329
|
-
case ValidationTokenEnum.Dimension:
|
|
14396
|
+
case exports.ValidationTokenEnum.Dimension:
|
|
14330
14397
|
set.types.add(exports.EnumToken[syntax.unit]);
|
|
14331
14398
|
break;
|
|
14332
|
-
case ValidationTokenEnum.StringToken:
|
|
14399
|
+
case exports.ValidationTokenEnum.StringToken:
|
|
14333
14400
|
// `'+'`, `'-'`, `'/'`
|
|
14334
14401
|
set.types.add(exports.EnumToken.Add);
|
|
14335
14402
|
set.types.add(exports.EnumToken.Sub);
|
|
14336
14403
|
set.types.add(exports.EnumToken.LiteralTokenType);
|
|
14337
14404
|
set.types.add(exports.EnumToken.Plus);
|
|
14338
14405
|
break;
|
|
14339
|
-
case ValidationTokenEnum.Function:
|
|
14340
|
-
case ValidationTokenEnum.FunctionDefinition:
|
|
14406
|
+
case exports.ValidationTokenEnum.Function:
|
|
14407
|
+
case exports.ValidationTokenEnum.FunctionDefinition:
|
|
14341
14408
|
set.functions.add(lowercase(syntax.val));
|
|
14342
14409
|
break;
|
|
14343
|
-
case ValidationTokenEnum.Bracket:
|
|
14410
|
+
case exports.ValidationTokenEnum.Bracket:
|
|
14344
14411
|
first = firstOfSequence(syntax.chi);
|
|
14345
14412
|
merge(set, first);
|
|
14346
14413
|
nullable = first.nullable;
|
|
14347
14414
|
break;
|
|
14348
|
-
case ValidationTokenEnum.OptionalGroupToken:
|
|
14415
|
+
case exports.ValidationTokenEnum.OptionalGroupToken:
|
|
14349
14416
|
// the group is skipped when it does not match
|
|
14350
14417
|
merge(set, firstOfSequence(syntax.chi));
|
|
14351
14418
|
nullable = true;
|
|
14352
14419
|
break;
|
|
14353
|
-
case ValidationTokenEnum.PipeToken:
|
|
14420
|
+
case exports.ValidationTokenEnum.PipeToken:
|
|
14354
14421
|
for (const syntaxes of syntax.chi) {
|
|
14355
14422
|
first = firstOfSequence(syntaxes);
|
|
14356
14423
|
merge(set, first);
|
|
14357
14424
|
nullable ||= first.nullable;
|
|
14358
14425
|
}
|
|
14359
14426
|
break;
|
|
14360
|
-
case ValidationTokenEnum.ColumnToken:
|
|
14427
|
+
case exports.ValidationTokenEnum.ColumnToken:
|
|
14361
14428
|
// one or more operands, in any order: at least one token
|
|
14362
14429
|
for (const syntaxes of syntax.chi) {
|
|
14363
14430
|
merge(set, firstOfSequence(syntaxes));
|
|
14364
14431
|
}
|
|
14365
14432
|
break;
|
|
14366
|
-
case ValidationTokenEnum.AmpersandToken:
|
|
14433
|
+
case exports.ValidationTokenEnum.AmpersandToken:
|
|
14367
14434
|
// all the operands, in any order
|
|
14368
14435
|
nullable = true;
|
|
14369
14436
|
for (const syntaxes of [syntax.l, syntax.r]) {
|
|
@@ -14372,12 +14439,12 @@
|
|
|
14372
14439
|
nullable &&= first.nullable;
|
|
14373
14440
|
}
|
|
14374
14441
|
break;
|
|
14375
|
-
case ValidationTokenEnum.DeclarationType:
|
|
14442
|
+
case exports.ValidationTokenEnum.DeclarationType:
|
|
14376
14443
|
first = firstOfSequence(getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntax.val));
|
|
14377
14444
|
merge(set, first);
|
|
14378
14445
|
nullable = first.nullable;
|
|
14379
14446
|
break;
|
|
14380
|
-
case ValidationTokenEnum.PropertyType: {
|
|
14447
|
+
case exports.ValidationTokenEnum.PropertyType: {
|
|
14381
14448
|
const name = syntax.val;
|
|
14382
14449
|
if (builtinTypes.has(name)) {
|
|
14383
14450
|
const types = builtinTypes.get(name);
|
|
@@ -16528,7 +16595,7 @@
|
|
|
16528
16595
|
return interpreted;
|
|
16529
16596
|
}
|
|
16530
16597
|
const property = {
|
|
16531
|
-
typ: ValidationTokenEnum.PropertyType,
|
|
16598
|
+
typ: exports.ValidationTokenEnum.PropertyType,
|
|
16532
16599
|
val: name,
|
|
16533
16600
|
};
|
|
16534
16601
|
const fast = numericTypes[name] ?? null;
|
|
@@ -17015,6 +17082,71 @@
|
|
|
17015
17082
|
}
|
|
17016
17083
|
return tokens;
|
|
17017
17084
|
}
|
|
17085
|
+
/**
|
|
17086
|
+
* true if the token is a simple selector without arguments: a type (`a`), an id (`#a`), a class (`.a`), a
|
|
17087
|
+
* pseudo-class (`:hover`) or a pseudo-element (`::before`)
|
|
17088
|
+
* @param type
|
|
17089
|
+
*/
|
|
17090
|
+
function isSimpleSelectorToken(type) {
|
|
17091
|
+
return (type === exports.EnumToken.ClassSelectorTokenType ||
|
|
17092
|
+
type === exports.EnumToken.IdenTokenType ||
|
|
17093
|
+
type === exports.EnumToken.PseudoElementTokenType ||
|
|
17094
|
+
type === exports.EnumToken.PseudoClassTokenType ||
|
|
17095
|
+
type === exports.EnumToken.HashTokenType);
|
|
17096
|
+
}
|
|
17097
|
+
/**
|
|
17098
|
+
* match a selector made of simple selectors (see {@link isSimpleSelectorToken}), separated by whitespace (the
|
|
17099
|
+
* descendant combinator) and by commas: `.a:hover`, `.a .b`, `.a, #b`. such a selector is valid: the whitespace
|
|
17100
|
+
* around the commas is removed, the tokens are the tokens produced by {@link matchSelectorSyntax}. the tokens of
|
|
17101
|
+
* another selector are not changed
|
|
17102
|
+
* @param arena
|
|
17103
|
+
* @param tokens
|
|
17104
|
+
* @returns true if the selector is made of simple selectors
|
|
17105
|
+
*/
|
|
17106
|
+
function matchSimpleSelector(arena, tokens) {
|
|
17107
|
+
const length = tokens.length;
|
|
17108
|
+
// a simple selector is expected: at the start of the selector and after a comma
|
|
17109
|
+
let expected = true;
|
|
17110
|
+
let commaWhitespace = false;
|
|
17111
|
+
for (let i = 0; i < length; i++) {
|
|
17112
|
+
const type = arena.dataTypes[tokens[i]];
|
|
17113
|
+
if (isSimpleSelectorToken(type)) {
|
|
17114
|
+
expected = false;
|
|
17115
|
+
continue;
|
|
17116
|
+
}
|
|
17117
|
+
if (type === exports.EnumToken.WhitespaceTokenType) {
|
|
17118
|
+
// leading whitespace
|
|
17119
|
+
if (i === 0) {
|
|
17120
|
+
return false;
|
|
17121
|
+
}
|
|
17122
|
+
// whitespace after a comma or before a comma
|
|
17123
|
+
if (expected || arena.dataTypes[tokens[i + 1]] === exports.EnumToken.CommaTokenType) {
|
|
17124
|
+
commaWhitespace = true;
|
|
17125
|
+
}
|
|
17126
|
+
continue;
|
|
17127
|
+
}
|
|
17128
|
+
if (type !== exports.EnumToken.CommaTokenType || expected) {
|
|
17129
|
+
return false;
|
|
17130
|
+
}
|
|
17131
|
+
expected = true;
|
|
17132
|
+
}
|
|
17133
|
+
if (expected) {
|
|
17134
|
+
return false;
|
|
17135
|
+
}
|
|
17136
|
+
if (commaWhitespace) {
|
|
17137
|
+
let write = 0;
|
|
17138
|
+
for (let i = 0; i < length; i++) {
|
|
17139
|
+
if (arena.dataTypes[tokens[i]] === exports.EnumToken.WhitespaceTokenType &&
|
|
17140
|
+
(arena.dataTypes[tokens[i - 1]] === exports.EnumToken.CommaTokenType ||
|
|
17141
|
+
arena.dataTypes[tokens[i + 1]] === exports.EnumToken.CommaTokenType)) {
|
|
17142
|
+
continue;
|
|
17143
|
+
}
|
|
17144
|
+
tokens[write++] = tokens[i];
|
|
17145
|
+
}
|
|
17146
|
+
tokens.length = write;
|
|
17147
|
+
}
|
|
17148
|
+
return true;
|
|
17149
|
+
}
|
|
17018
17150
|
/**
|
|
17019
17151
|
*
|
|
17020
17152
|
* @param featureName
|
|
@@ -18210,9 +18342,9 @@
|
|
|
18210
18342
|
*/
|
|
18211
18343
|
function countItemCommas(syntax) {
|
|
18212
18344
|
let count = 0;
|
|
18213
|
-
if (syntax.typ === ValidationTokenEnum.Bracket) {
|
|
18345
|
+
if (syntax.typ === exports.ValidationTokenEnum.Bracket) {
|
|
18214
18346
|
for (const token of syntax.chi) {
|
|
18215
|
-
if (token.typ === ValidationTokenEnum.Comma) {
|
|
18347
|
+
if (token.typ === exports.ValidationTokenEnum.Comma) {
|
|
18216
18348
|
count++;
|
|
18217
18349
|
}
|
|
18218
18350
|
}
|
|
@@ -18374,7 +18506,7 @@
|
|
|
18374
18506
|
if (arena.hasFraction(token) || arena.numericValue[token] !== syntax.val) {
|
|
18375
18507
|
return false;
|
|
18376
18508
|
}
|
|
18377
|
-
if (syntax.typ === ValidationTokenEnum.Number) {
|
|
18509
|
+
if (syntax.typ === exports.ValidationTokenEnum.Number) {
|
|
18378
18510
|
return arena.dataTypes[token] === exports.EnumToken.NumberTokenType;
|
|
18379
18511
|
}
|
|
18380
18512
|
const type = exports.EnumToken[syntax.unit];
|
|
@@ -18398,7 +18530,7 @@
|
|
|
18398
18530
|
const range = syntax.range;
|
|
18399
18531
|
// a null lower bound is -∞
|
|
18400
18532
|
let success = !arena.hasFraction(token) && (range.min == null || arena.numericValue[token] >= range.min.val);
|
|
18401
|
-
if (range.min?.typ === ValidationTokenEnum.Dimension) {
|
|
18533
|
+
if (range.min?.typ === exports.ValidationTokenEnum.Dimension) {
|
|
18402
18534
|
success =
|
|
18403
18535
|
arena.dataTypes[token] ===
|
|
18404
18536
|
exports.EnumToken[
|
|
@@ -18416,8 +18548,12 @@
|
|
|
18416
18548
|
* @param token
|
|
18417
18549
|
*/
|
|
18418
18550
|
function functionSyntax(arena, token) {
|
|
18551
|
+
const previousSyntaxArena = syntaxArena;
|
|
18419
18552
|
syntaxArena = arena;
|
|
18420
|
-
|
|
18553
|
+
const syntax = arena.stringDerived(arena.stringValue[token], 0 /* StringDerived.FunctionSyntax */, computeFunctionSyntax);
|
|
18554
|
+
// the arena is not kept after the parse: the previous arena is restored (a nested call)
|
|
18555
|
+
syntaxArena = previousSyntaxArena;
|
|
18556
|
+
return syntax;
|
|
18421
18557
|
}
|
|
18422
18558
|
/**
|
|
18423
18559
|
* the arena of the function names read by {@link computeFunctionSyntax} and {@link computeSelectorFunctionSyntax}:
|
|
@@ -18444,8 +18580,12 @@
|
|
|
18444
18580
|
* @param token
|
|
18445
18581
|
*/
|
|
18446
18582
|
function selectorFunctionSyntax(arena, token) {
|
|
18583
|
+
const previousSyntaxArena = syntaxArena;
|
|
18447
18584
|
syntaxArena = arena;
|
|
18448
|
-
|
|
18585
|
+
const syntax = arena.stringDerived(arena.stringValue[token], 1 /* StringDerived.SelectorFunctionSyntax */, computeSelectorFunctionSyntax);
|
|
18586
|
+
// the arena is not kept after the parse: the previous arena is restored (a nested call)
|
|
18587
|
+
syntaxArena = previousSyntaxArena;
|
|
18588
|
+
return syntax;
|
|
18449
18589
|
}
|
|
18450
18590
|
/**
|
|
18451
18591
|
* the wildcard functions being matched with a syntax, see {@link matchWildCardFunction}
|
|
@@ -18472,12 +18612,12 @@
|
|
|
18472
18612
|
let errors = noErrors;
|
|
18473
18613
|
const candidates = [];
|
|
18474
18614
|
// the function is a part of the syntax. a keyword, a comma, ... is matched by the function
|
|
18475
|
-
if (syntaxes[index].typ !== ValidationTokenEnum.Keyword &&
|
|
18476
|
-
syntaxes[index].typ !== ValidationTokenEnum.Comma &&
|
|
18477
|
-
syntaxes[index].typ !== ValidationTokenEnum.Separator &&
|
|
18478
|
-
syntaxes[index].typ !== ValidationTokenEnum.StringToken &&
|
|
18479
|
-
syntaxes[index].typ !== ValidationTokenEnum.OpenParenthesis &&
|
|
18480
|
-
syntaxes[index].typ !== ValidationTokenEnum.CloseParenthesis) {
|
|
18615
|
+
if (syntaxes[index].typ !== exports.ValidationTokenEnum.Keyword &&
|
|
18616
|
+
syntaxes[index].typ !== exports.ValidationTokenEnum.Comma &&
|
|
18617
|
+
syntaxes[index].typ !== exports.ValidationTokenEnum.Separator &&
|
|
18618
|
+
syntaxes[index].typ !== exports.ValidationTokenEnum.StringToken &&
|
|
18619
|
+
syntaxes[index].typ !== exports.ValidationTokenEnum.OpenParenthesis &&
|
|
18620
|
+
syntaxes[index].typ !== exports.ValidationTokenEnum.CloseParenthesis) {
|
|
18481
18621
|
const previous = wildCardProbes.get(token);
|
|
18482
18622
|
let probe;
|
|
18483
18623
|
wildCardProbes.set(token, syntaxes[index]);
|
|
@@ -18576,7 +18716,7 @@
|
|
|
18576
18716
|
return setMatch(out, true, true, context.peek(), context, null, noErrors);
|
|
18577
18717
|
}
|
|
18578
18718
|
while (++i < syntaxes.length) {
|
|
18579
|
-
if (syntaxes[i].typ === ValidationTokenEnum.Whitespace) {
|
|
18719
|
+
if (syntaxes[i].typ === exports.ValidationTokenEnum.Whitespace) {
|
|
18580
18720
|
continue;
|
|
18581
18721
|
}
|
|
18582
18722
|
isOptional =
|
|
@@ -18695,7 +18835,7 @@
|
|
|
18695
18835
|
success = false;
|
|
18696
18836
|
try {
|
|
18697
18837
|
switch (syntaxes[i].typ) {
|
|
18698
|
-
case ValidationTokenEnum.Colon:
|
|
18838
|
+
case exports.ValidationTokenEnum.Colon:
|
|
18699
18839
|
// `<ident-token> : <declaration-value>?`
|
|
18700
18840
|
if (arena.dataTypes[token] === exports.EnumToken.ColonTokenType) {
|
|
18701
18841
|
success = true;
|
|
@@ -18706,7 +18846,7 @@
|
|
|
18706
18846
|
break;
|
|
18707
18847
|
}
|
|
18708
18848
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18709
|
-
case ValidationTokenEnum.Comma:
|
|
18849
|
+
case exports.ValidationTokenEnum.Comma:
|
|
18710
18850
|
if (arena.dataTypes[token] === exports.EnumToken.CommaTokenType) {
|
|
18711
18851
|
success = true;
|
|
18712
18852
|
visitedSyntaxes[visit] = null;
|
|
@@ -18714,7 +18854,7 @@
|
|
|
18714
18854
|
break;
|
|
18715
18855
|
}
|
|
18716
18856
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18717
|
-
case ValidationTokenEnum.Keyword:
|
|
18857
|
+
case exports.ValidationTokenEnum.Keyword:
|
|
18718
18858
|
if (arena.dataTypes[token] === exports.EnumToken.IdenTokenType &&
|
|
18719
18859
|
lowercase(arena.resolveString(arena.stringValue[token])) ===
|
|
18720
18860
|
lowercase(syntaxes[i].val)) {
|
|
@@ -18727,7 +18867,7 @@
|
|
|
18727
18867
|
break;
|
|
18728
18868
|
}
|
|
18729
18869
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18730
|
-
case ValidationTokenEnum.DeclarationType:
|
|
18870
|
+
case exports.ValidationTokenEnum.DeclarationType:
|
|
18731
18871
|
result = matchSyntax(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, syntaxes[i].val), context, options, out);
|
|
18732
18872
|
if (result.success) {
|
|
18733
18873
|
success = true;
|
|
@@ -18746,7 +18886,7 @@
|
|
|
18746
18886
|
break;
|
|
18747
18887
|
}
|
|
18748
18888
|
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
18749
|
-
case ValidationTokenEnum.OptionalGroupToken: {
|
|
18889
|
+
case exports.ValidationTokenEnum.OptionalGroupToken: {
|
|
18750
18890
|
const chi = syntaxes[i].chi;
|
|
18751
18891
|
// `<bg-layer>#? , <final-bg-layer>` (the group of the optional list, the comma is the list separator) is
|
|
18752
18892
|
// matched as `[ <bg-layer> , ]* <final-bg-layer>`: the last item is left to the next syntax
|
|
@@ -18754,7 +18894,7 @@
|
|
|
18754
18894
|
const { isList, isOptional, match, ...item } = chi[0];
|
|
18755
18895
|
const group = [
|
|
18756
18896
|
item,
|
|
18757
|
-
{ typ: ValidationTokenEnum.Comma },
|
|
18897
|
+
{ typ: exports.ValidationTokenEnum.Comma },
|
|
18758
18898
|
];
|
|
18759
18899
|
while (context.peek() != null) {
|
|
18760
18900
|
const tmp = matchSyntax(arena, group, context.slice(), options);
|
|
@@ -18781,7 +18921,7 @@
|
|
|
18781
18921
|
}
|
|
18782
18922
|
break;
|
|
18783
18923
|
}
|
|
18784
|
-
case ValidationTokenEnum.StringToken:
|
|
18924
|
+
case exports.ValidationTokenEnum.StringToken:
|
|
18785
18925
|
if (arena.dataTypes[token] === exports.EnumToken.Add) {
|
|
18786
18926
|
success = syntaxes[i].val.slice(1, -1) === "+";
|
|
18787
18927
|
}
|
|
@@ -18804,7 +18944,7 @@
|
|
|
18804
18944
|
break;
|
|
18805
18945
|
}
|
|
18806
18946
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18807
|
-
case ValidationTokenEnum.PropertyType:
|
|
18947
|
+
case exports.ValidationTokenEnum.PropertyType:
|
|
18808
18948
|
result = matchProperty(arena, syntaxes[i], context, options);
|
|
18809
18949
|
if (!result.success) {
|
|
18810
18950
|
if (isOptional) {
|
|
@@ -18825,7 +18965,7 @@
|
|
|
18825
18965
|
context.update(result.context.current());
|
|
18826
18966
|
}
|
|
18827
18967
|
break;
|
|
18828
|
-
case ValidationTokenEnum.PipeToken:
|
|
18968
|
+
case exports.ValidationTokenEnum.PipeToken:
|
|
18829
18969
|
{
|
|
18830
18970
|
// each alternative is matched in the same scratch result, the best match is copied
|
|
18831
18971
|
const scratch = createMatch();
|
|
@@ -18871,7 +19011,7 @@
|
|
|
18871
19011
|
syntax: syntaxes[i],
|
|
18872
19012
|
},
|
|
18873
19013
|
]);
|
|
18874
|
-
case ValidationTokenEnum.Bracket:
|
|
19014
|
+
case exports.ValidationTokenEnum.Bracket:
|
|
18875
19015
|
result = matchSyntax(arena, syntaxes[i].chi, context.slice(), options, out);
|
|
18876
19016
|
if (result.success) {
|
|
18877
19017
|
success = true;
|
|
@@ -18889,7 +19029,7 @@
|
|
|
18889
19029
|
break;
|
|
18890
19030
|
}
|
|
18891
19031
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18892
|
-
case ValidationTokenEnum.ColumnToken:
|
|
19032
|
+
case exports.ValidationTokenEnum.ColumnToken:
|
|
18893
19033
|
result = matchColumnSyntax(arena, syntaxes[i], context.slice(), options);
|
|
18894
19034
|
if (result.success) {
|
|
18895
19035
|
success = true;
|
|
@@ -18904,7 +19044,7 @@
|
|
|
18904
19044
|
break;
|
|
18905
19045
|
}
|
|
18906
19046
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18907
|
-
case ValidationTokenEnum.AmpersandToken:
|
|
19047
|
+
case exports.ValidationTokenEnum.AmpersandToken:
|
|
18908
19048
|
result = matchAmpersandSyntax(arena, syntaxes[i], context.slice(), options);
|
|
18909
19049
|
if (result.success) {
|
|
18910
19050
|
success = true;
|
|
@@ -18919,7 +19059,7 @@
|
|
|
18919
19059
|
break;
|
|
18920
19060
|
}
|
|
18921
19061
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18922
|
-
case ValidationTokenEnum.Function:
|
|
19062
|
+
case exports.ValidationTokenEnum.Function:
|
|
18923
19063
|
if ((!isFunctionDefType(arena.dataTypes[token]) &&
|
|
18924
19064
|
!funcLike.includes(arena.dataTypes[token]) &&
|
|
18925
19065
|
!funcTypes.includes(arena.dataTypes[token])) ||
|
|
@@ -18951,8 +19091,8 @@
|
|
|
18951
19091
|
}
|
|
18952
19092
|
}
|
|
18953
19093
|
return setMatch(out, false, true, token, context, syntaxes[i], result.errors);
|
|
18954
|
-
case ValidationTokenEnum.Number:
|
|
18955
|
-
case ValidationTokenEnum.Dimension:
|
|
19094
|
+
case exports.ValidationTokenEnum.Number:
|
|
19095
|
+
case exports.ValidationTokenEnum.Dimension:
|
|
18956
19096
|
// a literal number or dimension: `-moz-force-broken-image-icon: 0 | 1`,
|
|
18957
19097
|
// `glyph-orientation-vertical: auto | 0deg | 90deg | 0 | 90`
|
|
18958
19098
|
if (isLiteralNumber(arena, token, syntaxes[i])) {
|
|
@@ -18965,7 +19105,7 @@
|
|
|
18965
19105
|
break;
|
|
18966
19106
|
}
|
|
18967
19107
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18968
|
-
case ValidationTokenEnum.Separator:
|
|
19108
|
+
case exports.ValidationTokenEnum.Separator:
|
|
18969
19109
|
if (arena.dataTypes[token] === exports.EnumToken.LiteralTokenType &&
|
|
18970
19110
|
arena.resolveString(arena.stringValue[token]) === "/") {
|
|
18971
19111
|
visitedSyntaxes[visit] = null;
|
|
@@ -18973,7 +19113,7 @@
|
|
|
18973
19113
|
break;
|
|
18974
19114
|
}
|
|
18975
19115
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
18976
|
-
case ValidationTokenEnum.FunctionDefinition:
|
|
19116
|
+
case exports.ValidationTokenEnum.FunctionDefinition:
|
|
18977
19117
|
if (arena.resolveString(arena.stringValue[token]) &&
|
|
18978
19118
|
equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), syntaxes[i].val)) {
|
|
18979
19119
|
if (isFunctionDefType(arena.dataTypes[token])) {
|
|
@@ -18997,21 +19137,21 @@
|
|
|
18997
19137
|
}
|
|
18998
19138
|
}
|
|
18999
19139
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
19000
|
-
case ValidationTokenEnum.OpenParenthesis:
|
|
19140
|
+
case exports.ValidationTokenEnum.OpenParenthesis:
|
|
19001
19141
|
if (arena.dataTypes[token] === exports.EnumToken.StartParensTokenType) {
|
|
19002
19142
|
visitedSyntaxes[visit] = null;
|
|
19003
19143
|
context.next();
|
|
19004
19144
|
break;
|
|
19005
19145
|
}
|
|
19006
19146
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
19007
|
-
case ValidationTokenEnum.OpenCurlyBrace:
|
|
19147
|
+
case exports.ValidationTokenEnum.OpenCurlyBrace:
|
|
19008
19148
|
if (arena.dataTypes[token] === exports.EnumToken.BlockStartTokenType) {
|
|
19009
19149
|
visitedSyntaxes[visit] = null;
|
|
19010
19150
|
context.next();
|
|
19011
19151
|
break;
|
|
19012
19152
|
}
|
|
19013
19153
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
19014
|
-
case ValidationTokenEnum.CloseParenthesis:
|
|
19154
|
+
case exports.ValidationTokenEnum.CloseParenthesis:
|
|
19015
19155
|
if (arena.dataTypes[token] === exports.EnumToken.EndParensTokenType) {
|
|
19016
19156
|
visitedSyntaxes[visit] = null;
|
|
19017
19157
|
context.next();
|
|
@@ -19019,7 +19159,7 @@
|
|
|
19019
19159
|
}
|
|
19020
19160
|
return setMatch(out, false, true, token, context, syntaxes[i], noErrors);
|
|
19021
19161
|
default:
|
|
19022
|
-
throw new Error(`Unexpected syntax ${ValidationTokenEnum[syntaxes[i].typ]}`);
|
|
19162
|
+
throw new Error(`Unexpected syntax ${exports.ValidationTokenEnum[syntaxes[i].typ]}`);
|
|
19023
19163
|
}
|
|
19024
19164
|
}
|
|
19025
19165
|
finally {
|
|
@@ -19157,9 +19297,9 @@
|
|
|
19157
19297
|
*/
|
|
19158
19298
|
function ampersandOperands(syntax, operands = []) {
|
|
19159
19299
|
for (const side of [syntax.l, syntax.r]) {
|
|
19160
|
-
const tokens = side.filter((token) => token.typ !== ValidationTokenEnum.Whitespace);
|
|
19300
|
+
const tokens = side.filter((token) => token.typ !== exports.ValidationTokenEnum.Whitespace);
|
|
19161
19301
|
if (tokens.length === 1 &&
|
|
19162
|
-
tokens[0].typ === ValidationTokenEnum.AmpersandToken &&
|
|
19302
|
+
tokens[0].typ === exports.ValidationTokenEnum.AmpersandToken &&
|
|
19163
19303
|
!tokens[0].isOptional &&
|
|
19164
19304
|
!tokens[0].isRepeatable &&
|
|
19165
19305
|
!tokens[0].isRepeatableAtLeastOnce &&
|
|
@@ -22144,6 +22284,7 @@
|
|
|
22144
22284
|
*/
|
|
22145
22285
|
#codeLength;
|
|
22146
22286
|
/**
|
|
22287
|
+
* create a render result
|
|
22147
22288
|
* @param write rendered css, encoded as UTF-8
|
|
22148
22289
|
* @param errors
|
|
22149
22290
|
* @param stats
|
|
@@ -22208,6 +22349,7 @@
|
|
|
22208
22349
|
*/
|
|
22209
22350
|
arena;
|
|
22210
22351
|
/**
|
|
22352
|
+
* create a transform result from the parse result and the render result
|
|
22211
22353
|
* @param parseResult
|
|
22212
22354
|
* @param renderResult
|
|
22213
22355
|
* @param stats
|
|
@@ -23945,7 +24087,8 @@
|
|
|
23945
24087
|
key === "0 0" ||
|
|
23946
24088
|
key === "top left" ||
|
|
23947
24089
|
key === "left top") {
|
|
23948
|
-
|
|
24090
|
+
// a single value is centered vertically: both values are kept
|
|
24091
|
+
positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 0), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 0));
|
|
23949
24092
|
}
|
|
23950
24093
|
else if (key === "50% 0%" ||
|
|
23951
24094
|
key === "50% 0" ||
|
|
@@ -23969,7 +24112,7 @@
|
|
|
23969
24112
|
key === "0% 100%" ||
|
|
23970
24113
|
key === "left bottom" ||
|
|
23971
24114
|
key === "bottom left") {
|
|
23972
|
-
positions.splice(0, positions.length, arena.createToken(exports.EnumToken.
|
|
24115
|
+
positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 0), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 100));
|
|
23973
24116
|
}
|
|
23974
24117
|
else if (key === "50% 100%" ||
|
|
23975
24118
|
key === "center bottom" ||
|
|
@@ -23979,10 +24122,7 @@
|
|
|
23979
24122
|
else if (key === "100% 100%" ||
|
|
23980
24123
|
key === "right bottom" ||
|
|
23981
24124
|
key === "bottom right") {
|
|
23982
|
-
positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 100));
|
|
23983
|
-
}
|
|
23984
|
-
else if (position1 === position2) {
|
|
23985
|
-
positions.splice(0, positions.length, positions[k]);
|
|
24125
|
+
positions.splice(0, positions.length, arena.createToken(exports.EnumToken.PercentageTokenType, 100), arena.createToken(exports.EnumToken.WhitespaceTokenType), arena.createToken(exports.EnumToken.PercentageTokenType, 100));
|
|
23986
24126
|
}
|
|
23987
24127
|
}
|
|
23988
24128
|
}
|
|
@@ -30415,7 +30555,8 @@
|
|
|
30415
30555
|
*/
|
|
30416
30556
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
30417
30557
|
/**
|
|
30418
|
-
* declarations
|
|
30558
|
+
* declarations, by property name
|
|
30559
|
+
* @ignore
|
|
30419
30560
|
*/
|
|
30420
30561
|
declarations;
|
|
30421
30562
|
/**
|
|
@@ -30432,8 +30573,8 @@
|
|
|
30432
30573
|
*/
|
|
30433
30574
|
descriptors;
|
|
30434
30575
|
/**
|
|
30435
|
-
*
|
|
30436
|
-
* @param arena
|
|
30576
|
+
* create an empty declaration list
|
|
30577
|
+
* @param arena the arena the declarations are stored in
|
|
30437
30578
|
* @param options
|
|
30438
30579
|
* @param memo keys shared by the lists that use the same arena
|
|
30439
30580
|
* @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
|
|
@@ -30612,6 +30753,8 @@
|
|
|
30612
30753
|
return this;
|
|
30613
30754
|
}
|
|
30614
30755
|
/**
|
|
30756
|
+
* Normalize the values of a declaration with the mapping of its property: the values are reordered by the patterns
|
|
30757
|
+
* of the mapping, the keywords are replaced by their mapped value
|
|
30615
30758
|
*
|
|
30616
30759
|
* @param declaration
|
|
30617
30760
|
* @param mapping
|
|
@@ -30676,7 +30819,7 @@
|
|
|
30676
30819
|
}
|
|
30677
30820
|
}
|
|
30678
30821
|
/**
|
|
30679
|
-
*
|
|
30822
|
+
* iterate over the declarations, the shorthands are expanded into their declarations
|
|
30680
30823
|
* @returns
|
|
30681
30824
|
*/
|
|
30682
30825
|
[Symbol.iterator]() {
|
|
@@ -31986,8 +32129,12 @@
|
|
|
31986
32129
|
* @param id interned string id
|
|
31987
32130
|
*/
|
|
31988
32131
|
function transformKind(arena, id) {
|
|
32132
|
+
const previousKindArena = kindArena;
|
|
31989
32133
|
kindArena = arena;
|
|
31990
|
-
|
|
32134
|
+
const kind = arena.stringDerived(id, 2 /* StringDerived.TransformKind */, computeTransformKind);
|
|
32135
|
+
// the arena is not kept after the transformation: the previous arena is restored (a nested call)
|
|
32136
|
+
kindArena = previousKindArena;
|
|
32137
|
+
return kind;
|
|
31991
32138
|
}
|
|
31992
32139
|
/**
|
|
31993
32140
|
* numeric arguments of a transform function (the first 16 arguments), reused
|
|
@@ -33059,6 +33206,10 @@
|
|
|
33059
33206
|
*/
|
|
33060
33207
|
StringDerived[StringDerived["AtRuleAcceptsRules"] = 3] = "AtRuleAcceptsRules";
|
|
33061
33208
|
})(StringDerived || (StringDerived = {}));
|
|
33209
|
+
/**
|
|
33210
|
+
* code units of a short string, see {@link fromCodes}
|
|
33211
|
+
*/
|
|
33212
|
+
const shortCodes = [];
|
|
33062
33213
|
/**
|
|
33063
33214
|
* string of a range of code units
|
|
33064
33215
|
* @param codes
|
|
@@ -33066,6 +33217,15 @@
|
|
|
33066
33217
|
* @param end
|
|
33067
33218
|
*/
|
|
33068
33219
|
function fromCodes(codes, start, end) {
|
|
33220
|
+
const length = end - start;
|
|
33221
|
+
// a short string: the code units are copied to an array, a subarray is slower to create
|
|
33222
|
+
if (length <= 256) {
|
|
33223
|
+
shortCodes.length = length;
|
|
33224
|
+
for (let i = 0; i < length; i++) {
|
|
33225
|
+
shortCodes[i] = codes[start + i];
|
|
33226
|
+
}
|
|
33227
|
+
return String.fromCharCode.apply(null, shortCodes);
|
|
33228
|
+
}
|
|
33069
33229
|
let result = "";
|
|
33070
33230
|
// String.fromCharCode() with a limited number of arguments
|
|
33071
33231
|
while (start < end) {
|
|
@@ -33237,6 +33397,18 @@
|
|
|
33237
33397
|
this.texts[source] = text;
|
|
33238
33398
|
this.codes[source] = codes ?? undefined;
|
|
33239
33399
|
}
|
|
33400
|
+
/**
|
|
33401
|
+
* code unit of the text of a source, NaN after its end
|
|
33402
|
+
* @param source source index
|
|
33403
|
+
* @param offset
|
|
33404
|
+
*/
|
|
33405
|
+
sourceCodeAt(source, offset) {
|
|
33406
|
+
const text = this.texts[source];
|
|
33407
|
+
if (text !== undefined && offset < text.length) {
|
|
33408
|
+
return text.charCodeAt(offset);
|
|
33409
|
+
}
|
|
33410
|
+
return this.codes[source]?.[offset] ?? NaN;
|
|
33411
|
+
}
|
|
33240
33412
|
/**
|
|
33241
33413
|
* drop the code units of a source: the source is no longer tokenized, see {@link setText}
|
|
33242
33414
|
* @param source
|
|
@@ -34145,6 +34317,22 @@
|
|
|
34145
34317
|
*
|
|
34146
34318
|
* @private
|
|
34147
34319
|
*/
|
|
34320
|
+
/**
|
|
34321
|
+
* Merge the adjacent rules without minifying the ast: `minify: false` with {@link ParserOptions.mergeRules}. The style
|
|
34322
|
+
* rules that have the same selector, the keyframes rules that have the same selector, the at-rules that have the same
|
|
34323
|
+
* name and prelude (not `@font-face`) and, depending on `mergeRules`, the rules that share declarations are merged. Of
|
|
34324
|
+
* the `@keyframes` that have the same name, the last one is kept. The other minifications are not applied
|
|
34325
|
+
* @param arena
|
|
34326
|
+
* @param ast
|
|
34327
|
+
* @param options
|
|
34328
|
+
*
|
|
34329
|
+
* @private
|
|
34330
|
+
*/
|
|
34331
|
+
function mergeRules(arena, ast, options) {
|
|
34332
|
+
return doMinify(arena, ast, { ...options, nestingRules: false, optimizeSelectors: false }, true, undefined, false, {
|
|
34333
|
+
mergeOnly: true,
|
|
34334
|
+
});
|
|
34335
|
+
}
|
|
34148
34336
|
function doMinify(arena, ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
34149
34337
|
if (!("nodes" in context)) {
|
|
34150
34338
|
context.nodes = new Set();
|
|
@@ -34195,7 +34383,7 @@
|
|
|
34195
34383
|
}
|
|
34196
34384
|
// there is no early return: the result that precedes the conditional rules is moved after them.
|
|
34197
34385
|
// the conditional rules are never removed
|
|
34198
|
-
if (equalsIgnoreCase(nam, "function")) {
|
|
34386
|
+
if (!context.mergeOnly && equalsIgnoreCase(nam, "function")) {
|
|
34199
34387
|
moveResult(arena, node);
|
|
34200
34388
|
}
|
|
34201
34389
|
}
|
|
@@ -34222,7 +34410,8 @@
|
|
|
34222
34410
|
cursor = arena.nextSibling[previous];
|
|
34223
34411
|
continue;
|
|
34224
34412
|
}
|
|
34225
|
-
|
|
34413
|
+
// merge only (see mergeRules()): the declarations are not removed
|
|
34414
|
+
let k = context.mergeOnly ? 0 : arena.firstChild[node];
|
|
34226
34415
|
while (k !== 0) {
|
|
34227
34416
|
const next = arena.nextSibling[k];
|
|
34228
34417
|
if (arena.dataTypes[k] === exports.EnumToken.DeclarationNodeType) {
|
|
@@ -34255,7 +34444,8 @@
|
|
|
34255
34444
|
(index + 3 < arr.length || arena.dataTypes[arr[index + 2]] === exports.EnumToken.WhitespaceTokenType))
|
|
34256
34445
|
? ""
|
|
34257
34446
|
: renderValue(arena, curr));
|
|
34258
|
-
if (
|
|
34447
|
+
if (context.mergeOnly) ;
|
|
34448
|
+
else if (nam === "apply") {
|
|
34259
34449
|
// `@apply --mixin()` is equivalent to `@apply --mixin`
|
|
34260
34450
|
minifyApplyPrelude(arena, node);
|
|
34261
34451
|
}
|
|
@@ -34297,9 +34487,11 @@
|
|
|
34297
34487
|
arena.stringValue[node] = arena.internString(trimArray(arena, tokens).reduce(renderPrelude, ""));
|
|
34298
34488
|
}
|
|
34299
34489
|
}
|
|
34300
|
-
|
|
34490
|
+
if (arena.dataTypes[ast] === nodeType &&
|
|
34301
34491
|
arena.name[ast] === arena.name[node] &&
|
|
34302
|
-
arena.stringValue[ast] === arena.stringValue[node]
|
|
34492
|
+
arena.stringValue[ast] === arena.stringValue[node] &&
|
|
34493
|
+
// the at-rules handled above are not replaced when the ast is minified
|
|
34494
|
+
(context.mergeOnly || (nam !== "apply" && nam !== "media" && !(nam === "import" && tokens != null)))) {
|
|
34303
34495
|
// the node is replaced by its children
|
|
34304
34496
|
cursor = arena.firstChild[node] || arena.nextSibling[node];
|
|
34305
34497
|
arena.moveChildren(node, ast, node);
|
|
@@ -34331,8 +34523,9 @@
|
|
|
34331
34523
|
}
|
|
34332
34524
|
else if (nodeType === exports.EnumToken.RuleNodeType) {
|
|
34333
34525
|
// a single selector that does not end with a combinator is not reduced (see isSimpleSelector()): the
|
|
34334
|
-
// selector is not read
|
|
34335
|
-
if (
|
|
34526
|
+
// selector is not read. the nesting reads the reduced selectors: optimizeSelectors only applies without it
|
|
34527
|
+
if ((options.optimizeSelectors !== false || options.nestingRules) &&
|
|
34528
|
+
!isSimpleSelector(arena, arena.name[node])) {
|
|
34336
34529
|
reduceRuleSelector(arena, node);
|
|
34337
34530
|
}
|
|
34338
34531
|
let wrapper = null;
|
|
@@ -34498,7 +34691,9 @@
|
|
|
34498
34691
|
cursor = arena.nextSibling[node];
|
|
34499
34692
|
continue;
|
|
34500
34693
|
}
|
|
34501
|
-
else if (
|
|
34694
|
+
else if (options.mergeRules !== false &&
|
|
34695
|
+
options.mergeRules !== exports.MergeRulesEnum.None &&
|
|
34696
|
+
nodeType === previousType &&
|
|
34502
34697
|
[exports.EnumToken.KeyframesRuleNodeType, exports.EnumToken.RuleNodeType].includes(nodeType)) {
|
|
34503
34698
|
const intersect = diff(arena, previous, node, options, context);
|
|
34504
34699
|
if (intersect != null) {
|
|
@@ -34541,6 +34736,7 @@
|
|
|
34541
34736
|
}
|
|
34542
34737
|
}
|
|
34543
34738
|
if (!nestingContent &&
|
|
34739
|
+
!context.mergeOnly &&
|
|
34544
34740
|
previous != null &&
|
|
34545
34741
|
arena.dataTypes[previous] === exports.EnumToken.RuleNodeType &&
|
|
34546
34742
|
arena.stringIndexOf(arena.name[previous], 0x26) !== -1) {
|
|
@@ -34558,6 +34754,7 @@
|
|
|
34558
34754
|
}
|
|
34559
34755
|
}
|
|
34560
34756
|
if (!nestingContent &&
|
|
34757
|
+
!context.mergeOnly &&
|
|
34561
34758
|
node != null &&
|
|
34562
34759
|
arena.dataTypes[node] === exports.EnumToken.RuleNodeType &&
|
|
34563
34760
|
arena.stringIndexOf(arena.name[node], 0x26) !== -1) {
|
|
@@ -35151,24 +35348,38 @@
|
|
|
35151
35348
|
*
|
|
35152
35349
|
* @private
|
|
35153
35350
|
*/
|
|
35154
|
-
|
|
35155
|
-
|
|
35156
|
-
|
|
35157
|
-
|
|
35158
|
-
|
|
35159
|
-
|
|
35160
|
-
|
|
35161
|
-
|
|
35351
|
+
/**
|
|
35352
|
+
* the number of declarations of a rule: its children that are not comments
|
|
35353
|
+
* @param arena
|
|
35354
|
+
* @param node
|
|
35355
|
+
*/
|
|
35356
|
+
function declarationCount(arena, node) {
|
|
35357
|
+
let count = 0;
|
|
35358
|
+
for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
35359
|
+
if (arena.dataTypes[child] !== exports.EnumToken.CommentNodeType) {
|
|
35360
|
+
count++;
|
|
35361
|
+
}
|
|
35162
35362
|
}
|
|
35163
|
-
|
|
35164
|
-
|
|
35165
|
-
|
|
35166
|
-
|
|
35167
|
-
|
|
35168
|
-
|
|
35169
|
-
|
|
35170
|
-
|
|
35363
|
+
return count;
|
|
35364
|
+
}
|
|
35365
|
+
/**
|
|
35366
|
+
* clear the matched flag of the children of a rule
|
|
35367
|
+
* @param arena
|
|
35368
|
+
* @param node
|
|
35369
|
+
*/
|
|
35370
|
+
function clearMatched(arena, node) {
|
|
35371
|
+
for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
35372
|
+
arena.flags[child] &= ~exports.EnumAstNodeStatus.Matched;
|
|
35171
35373
|
}
|
|
35374
|
+
}
|
|
35375
|
+
/**
|
|
35376
|
+
* the selectors of both rules have the same vendor prefixes: the rules that do not are not merged (a browser drops a
|
|
35377
|
+
* selector list that contains a pseudo class with an unknown prefix)
|
|
35378
|
+
* @param arena
|
|
35379
|
+
* @param node1
|
|
35380
|
+
* @param node2
|
|
35381
|
+
*/
|
|
35382
|
+
function samePrefixes(arena, node1, node2) {
|
|
35172
35383
|
const raw1 = arena.raw.get(node1);
|
|
35173
35384
|
const raw2 = arena.raw.get(node2);
|
|
35174
35385
|
if (raw1 == null || raw2 == null) {
|
|
@@ -35177,11 +35388,11 @@
|
|
|
35177
35388
|
const prefixes1 = raw1 == null ? selectorPrefixes(arena, arena.name[node1]) : rawSelectorPrefixes(raw1);
|
|
35178
35389
|
const prefixes2 = raw2 == null ? selectorPrefixes(arena, arena.name[node2]) : rawSelectorPrefixes(raw2);
|
|
35179
35390
|
if (prefixes1.size !== prefixes2.size) {
|
|
35180
|
-
return
|
|
35391
|
+
return false;
|
|
35181
35392
|
}
|
|
35182
35393
|
for (const prefix of prefixes1) {
|
|
35183
35394
|
if (!prefixes2.has(prefix)) {
|
|
35184
|
-
return
|
|
35395
|
+
return false;
|
|
35185
35396
|
}
|
|
35186
35397
|
}
|
|
35187
35398
|
}
|
|
@@ -35223,14 +35434,39 @@
|
|
|
35223
35434
|
}
|
|
35224
35435
|
}
|
|
35225
35436
|
if (prefixes1.size !== prefixes2.size) {
|
|
35226
|
-
return
|
|
35437
|
+
return false;
|
|
35227
35438
|
}
|
|
35228
35439
|
for (const prefix of prefixes1) {
|
|
35229
35440
|
if (!prefixes2.has(prefix)) {
|
|
35230
|
-
return
|
|
35441
|
+
return false;
|
|
35231
35442
|
}
|
|
35232
35443
|
}
|
|
35233
35444
|
}
|
|
35445
|
+
return true;
|
|
35446
|
+
}
|
|
35447
|
+
function diff(arena, n1, n2, options, context) {
|
|
35448
|
+
// the declarations of a rule that applies a mixin are not moved: `@apply` inserts declarations at its position,
|
|
35449
|
+
// the declarations that follow it override them
|
|
35450
|
+
if (hasAtRuleStatement(arena, n1) || hasAtRuleStatement(arena, n2)) {
|
|
35451
|
+
return null;
|
|
35452
|
+
}
|
|
35453
|
+
// only the rules that have the same declarations are merged: the rules that have a different number of
|
|
35454
|
+
// declarations are not compared
|
|
35455
|
+
if (options.mergeRules === exports.MergeRulesEnum.Identical && declarationCount(arena, n1) !== declarationCount(arena, n2)) {
|
|
35456
|
+
return null;
|
|
35457
|
+
}
|
|
35458
|
+
if (!("cache" in options)) {
|
|
35459
|
+
options.cache = new Map();
|
|
35460
|
+
}
|
|
35461
|
+
let node1 = n1;
|
|
35462
|
+
let node2 = n2;
|
|
35463
|
+
let exchanged = false;
|
|
35464
|
+
if (arena.childCount(node1) > arena.childCount(node2)) {
|
|
35465
|
+
const t = node1;
|
|
35466
|
+
node1 = node2;
|
|
35467
|
+
node2 = t;
|
|
35468
|
+
exchanged = true;
|
|
35469
|
+
}
|
|
35234
35470
|
// match the declarations of both rules, from the last to the first
|
|
35235
35471
|
let matches = 0;
|
|
35236
35472
|
for (let child1 = arena.lastChild[node1]; child1 !== 0; child1 = arena.previousSibling[child1]) {
|
|
@@ -35249,10 +35485,31 @@
|
|
|
35249
35485
|
break;
|
|
35250
35486
|
}
|
|
35251
35487
|
}
|
|
35488
|
+
// a declaration without a match: the rules are not identical
|
|
35489
|
+
if (options.mergeRules === exports.MergeRulesEnum.Identical && !(arena.flags[child1] & exports.EnumAstNodeStatus.Matched)) {
|
|
35490
|
+
clearMatched(arena, node1);
|
|
35491
|
+
clearMatched(arena, node2);
|
|
35492
|
+
return null;
|
|
35493
|
+
}
|
|
35252
35494
|
}
|
|
35253
35495
|
if (matches === 0 && (arena.firstChild[node1] !== 0 || arena.firstChild[node2] !== 0)) {
|
|
35254
35496
|
return null;
|
|
35255
35497
|
}
|
|
35498
|
+
// every declaration of both rules is matched: the merged rule replaces both rules, it is always smaller, the sizes
|
|
35499
|
+
// are not computed
|
|
35500
|
+
const identical = matches === declarationCount(arena, node1) && matches === declarationCount(arena, node2);
|
|
35501
|
+
if (!identical && options.mergeRules === exports.MergeRulesEnum.Identical) {
|
|
35502
|
+
// the rules are not merged: the matched declarations are released
|
|
35503
|
+
clearMatched(arena, node1);
|
|
35504
|
+
clearMatched(arena, node2);
|
|
35505
|
+
return null;
|
|
35506
|
+
}
|
|
35507
|
+
// the vendor prefixes are compared once the rules share declarations
|
|
35508
|
+
if (!samePrefixes(arena, node1, node2)) {
|
|
35509
|
+
clearMatched(arena, node1);
|
|
35510
|
+
clearMatched(arena, node2);
|
|
35511
|
+
return null;
|
|
35512
|
+
}
|
|
35256
35513
|
// the rules are rendered with the same options during the minification: the options are resolved once and
|
|
35257
35514
|
// identical values are rendered once
|
|
35258
35515
|
const renderer = (context.renderer ??= new NodeRenderer(options));
|
|
@@ -35267,7 +35524,7 @@
|
|
|
35267
35524
|
return arena.firstChild[node] === 0 ? 0 : size;
|
|
35268
35525
|
};
|
|
35269
35526
|
// size of the original nodes
|
|
35270
|
-
const size = renderedSize(n1, true) + renderedSize(n2, true);
|
|
35527
|
+
const size = identical ? 0 : renderedSize(n1, true) + renderedSize(n2, true);
|
|
35271
35528
|
// the shared declarations are moved into the result node
|
|
35272
35529
|
const result = arena.cloneNode(node1);
|
|
35273
35530
|
// the distinct selectors of both rules: built from the code units of the selectors when they are normalized
|
|
@@ -35309,7 +35566,9 @@
|
|
|
35309
35566
|
// the merge is kept when the output is smaller, or when it has the same size and removes a rule (an emptied rule is
|
|
35310
35567
|
// removed, its size is 0). the other rule keeps its selector, which is repeated in the merged selector: the merge of
|
|
35311
35568
|
// `html{margin:0}` and `body,div,...{margin:0;font:inherit}` is larger than the rules
|
|
35312
|
-
const mergedSize =
|
|
35569
|
+
const mergedSize = identical
|
|
35570
|
+
? 0
|
|
35571
|
+
: renderedSize(node1, false) + renderedSize(node2, false) + renderedSize(result, false);
|
|
35313
35572
|
if (size < mergedSize ||
|
|
35314
35573
|
(size === mergedSize && arena.firstChild[node1] !== 0 && arena.firstChild[node2] !== 0)) {
|
|
35315
35574
|
// restore the nodes: undo the moves in reverse order
|
|
@@ -35333,7 +35592,7 @@
|
|
|
35333
35592
|
if (arena.optimized.get(result) != null) {
|
|
35334
35593
|
arena.optimized.set(result, null);
|
|
35335
35594
|
}
|
|
35336
|
-
const optimized = optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
|
|
35595
|
+
const optimized = options.optimizeSelectors === false ? null : optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
|
|
35337
35596
|
if (optimized?.match) {
|
|
35338
35597
|
const sel = factorSelector(optimized);
|
|
35339
35598
|
if (sel != null && sel.length < arena.resolveString(arena.name[result]).length) {
|
|
@@ -35684,8 +35943,12 @@
|
|
|
35684
35943
|
* @param id selector string id
|
|
35685
35944
|
*/
|
|
35686
35945
|
function isSimpleSelector(arena, id) {
|
|
35946
|
+
const previousSelectorArena = selectorArena;
|
|
35687
35947
|
selectorArena = arena;
|
|
35688
|
-
|
|
35948
|
+
const simple = arena.stringFlagId(id, 1 /* StringFlag.SimpleSelector */, computeSimpleSelector);
|
|
35949
|
+
// the arena is not kept after the minification: the previous arena is restored (a nested call)
|
|
35950
|
+
selectorArena = previousSelectorArena;
|
|
35951
|
+
return simple;
|
|
35689
35952
|
}
|
|
35690
35953
|
/**
|
|
35691
35954
|
* the arena of the selector read by {@link computeSimpleSelector} and {@link hasVendorPrefix}: the functions passed to
|
|
@@ -35780,8 +36043,12 @@
|
|
|
35780
36043
|
*/
|
|
35781
36044
|
function selectorPrefixes(arena, id) {
|
|
35782
36045
|
// the selectors without `:-` are skipped: computed once per string id
|
|
36046
|
+
const previousSelectorArena = selectorArena;
|
|
35783
36047
|
selectorArena = arena;
|
|
35784
|
-
|
|
36048
|
+
const prefixed = arena.stringFlagId(id, 2 /* StringFlag.VendorPrefix */, hasVendorPrefix);
|
|
36049
|
+
// the arena is not kept after the minification: the previous arena is restored (a nested call)
|
|
36050
|
+
selectorArena = previousSelectorArena;
|
|
36051
|
+
if (!prefixed) {
|
|
35785
36052
|
return emptyPrefixes;
|
|
35786
36053
|
}
|
|
35787
36054
|
const prefixes = new Set();
|
|
@@ -36212,6 +36479,10 @@
|
|
|
36212
36479
|
* the high word holds the 24 high bits of the start position and the source
|
|
36213
36480
|
*/
|
|
36214
36481
|
spans32;
|
|
36482
|
+
/**
|
|
36483
|
+
* create an empty arena
|
|
36484
|
+
* @param size initial number of nodes the columns can hold. the columns grow when they are full
|
|
36485
|
+
*/
|
|
36215
36486
|
constructor(size = 4096) {
|
|
36216
36487
|
this.dataTypes = new Uint8Array(size);
|
|
36217
36488
|
this.capacity = size;
|
|
@@ -36276,6 +36547,9 @@
|
|
|
36276
36547
|
arena.importProperties(properties, transferables);
|
|
36277
36548
|
return arena;
|
|
36278
36549
|
}
|
|
36550
|
+
/**
|
|
36551
|
+
* Allocate a node or a token: a released id is reused, the columns grow when the arena is full. Returns the new id
|
|
36552
|
+
*/
|
|
36279
36553
|
allocate() {
|
|
36280
36554
|
let id = this.freeList;
|
|
36281
36555
|
if (id !== 0) {
|
|
@@ -36303,7 +36577,9 @@
|
|
|
36303
36577
|
this.unit[id] = 0;
|
|
36304
36578
|
this.flags[id] = 0;
|
|
36305
36579
|
this.colorType[id] = 0;
|
|
36306
|
-
|
|
36580
|
+
// the 32 bits view: no bigint
|
|
36581
|
+
this.spans32[id << 1] = 0;
|
|
36582
|
+
this.spans32[(id << 1) + 1] = 0;
|
|
36307
36583
|
if (this.errors.size > 0) {
|
|
36308
36584
|
this.errors.delete(id);
|
|
36309
36585
|
}
|
|
@@ -36346,6 +36622,14 @@
|
|
|
36346
36622
|
setSourceText(source, text, codes = null) {
|
|
36347
36623
|
this.stringTable.setText(source, text, codes);
|
|
36348
36624
|
}
|
|
36625
|
+
/**
|
|
36626
|
+
* code unit of the text of a source, NaN after its end. no string is created
|
|
36627
|
+
* @param source source index (see {@link getSourceId})
|
|
36628
|
+
* @param offset
|
|
36629
|
+
*/
|
|
36630
|
+
sourceCodeAt(source, offset) {
|
|
36631
|
+
return this.stringTable.sourceCodeAt(source, offset);
|
|
36632
|
+
}
|
|
36349
36633
|
/**
|
|
36350
36634
|
* drop the code units of a source set by {@link setSourceText}: the source is no longer tokenized
|
|
36351
36635
|
* @param source source index
|
|
@@ -36432,6 +36716,7 @@
|
|
|
36432
36716
|
* @param id
|
|
36433
36717
|
* @param flag
|
|
36434
36718
|
* @param compute computes the property from the string
|
|
36719
|
+
* @ignore
|
|
36435
36720
|
*/
|
|
36436
36721
|
stringFlag(id, flag, compute) {
|
|
36437
36722
|
return this.stringTable.flag(id, flag, compute);
|
|
@@ -36441,6 +36726,7 @@
|
|
|
36441
36726
|
* @param id
|
|
36442
36727
|
* @param flag
|
|
36443
36728
|
* @param compute computes the property from the string id
|
|
36729
|
+
* @ignore
|
|
36444
36730
|
*/
|
|
36445
36731
|
stringFlagId(id, flag, compute) {
|
|
36446
36732
|
return this.stringTable.flagId(id, flag, compute);
|
|
@@ -36450,6 +36736,7 @@
|
|
|
36450
36736
|
* @param id
|
|
36451
36737
|
* @param slot
|
|
36452
36738
|
* @param compute computes the value from the string id
|
|
36739
|
+
* @ignore
|
|
36453
36740
|
*/
|
|
36454
36741
|
stringDerived(id, slot, compute) {
|
|
36455
36742
|
return this.stringTable.derived(id, slot, compute);
|
|
@@ -36487,6 +36774,7 @@
|
|
|
36487
36774
|
return this.stringTable.epoch;
|
|
36488
36775
|
}
|
|
36489
36776
|
/**
|
|
36777
|
+
* Type of a node or a token, see {@link EnumToken}
|
|
36490
36778
|
*
|
|
36491
36779
|
* @param id
|
|
36492
36780
|
*/
|
|
@@ -36501,6 +36789,7 @@
|
|
|
36501
36789
|
return id == null ? null : this.dataTypes[id];
|
|
36502
36790
|
}
|
|
36503
36791
|
/**
|
|
36792
|
+
* Set the type of a node or a token, see {@link EnumToken}
|
|
36504
36793
|
*
|
|
36505
36794
|
* @param id
|
|
36506
36795
|
* @param type
|
|
@@ -36509,6 +36798,7 @@
|
|
|
36509
36798
|
this.dataTypes[id] = type;
|
|
36510
36799
|
}
|
|
36511
36800
|
/**
|
|
36801
|
+
* Set the name of a node or a token: `nameId` is a string table id, see {@link AstArena.internString}
|
|
36512
36802
|
*
|
|
36513
36803
|
* @param id
|
|
36514
36804
|
* @param nameId
|
|
@@ -36517,6 +36807,7 @@
|
|
|
36517
36807
|
this.name[id] = nameId;
|
|
36518
36808
|
}
|
|
36519
36809
|
/**
|
|
36810
|
+
* Name of a node or a token: the name of an at-rule, a declaration, a function, ...
|
|
36520
36811
|
*
|
|
36521
36812
|
* @param id
|
|
36522
36813
|
*/
|
|
@@ -36524,6 +36815,7 @@
|
|
|
36524
36815
|
return this.resolveString(this.name[id]) ?? null;
|
|
36525
36816
|
}
|
|
36526
36817
|
/**
|
|
36818
|
+
* Set the value of a node or a token: `valueId` is a string table id, see {@link AstArena.internString}
|
|
36527
36819
|
*
|
|
36528
36820
|
* @param id
|
|
36529
36821
|
* @param valueId
|
|
@@ -36532,6 +36824,7 @@
|
|
|
36532
36824
|
this.stringValue[id] = valueId;
|
|
36533
36825
|
}
|
|
36534
36826
|
/**
|
|
36827
|
+
* Value of a node or a token: the value of an identifier, a string, a hash, ...
|
|
36535
36828
|
*
|
|
36536
36829
|
* @param id
|
|
36537
36830
|
*/
|
|
@@ -36539,6 +36832,7 @@
|
|
|
36539
36832
|
return this.resolveString(this.stringValue[id]) ?? null;
|
|
36540
36833
|
}
|
|
36541
36834
|
/**
|
|
36835
|
+
* Set the numeric value of a token
|
|
36542
36836
|
*
|
|
36543
36837
|
* @param id
|
|
36544
36838
|
* @param numericValue
|
|
@@ -36547,6 +36841,7 @@
|
|
|
36547
36841
|
this.numericValue[id] = numericValue;
|
|
36548
36842
|
}
|
|
36549
36843
|
/**
|
|
36844
|
+
* Set the unit of a dimension token: `unit` is a string table id
|
|
36550
36845
|
*
|
|
36551
36846
|
* @param id
|
|
36552
36847
|
* @param unit
|
|
@@ -36555,6 +36850,7 @@
|
|
|
36555
36850
|
this.unit[id] = unit;
|
|
36556
36851
|
}
|
|
36557
36852
|
/**
|
|
36853
|
+
* Unit of a dimension token
|
|
36558
36854
|
*
|
|
36559
36855
|
* @param id
|
|
36560
36856
|
*/
|
|
@@ -36562,6 +36858,7 @@
|
|
|
36562
36858
|
return this.resolveString(this.unit[id]) ?? null;
|
|
36563
36859
|
}
|
|
36564
36860
|
/**
|
|
36861
|
+
* Numeric value of a token: number, dimension, percentage, ...
|
|
36565
36862
|
*
|
|
36566
36863
|
* @param id
|
|
36567
36864
|
*/
|
|
@@ -36569,6 +36866,8 @@
|
|
|
36569
36866
|
return this.numericValue[id];
|
|
36570
36867
|
}
|
|
36571
36868
|
/**
|
|
36869
|
+
* Set the parent id of a node. The node is not moved: use {@link AstArena.appendChild} or {@link
|
|
36870
|
+
* AstArena.insertBefore} to move it
|
|
36572
36871
|
*
|
|
36573
36872
|
* @param id
|
|
36574
36873
|
* @param parentId
|
|
@@ -36651,6 +36950,7 @@
|
|
|
36651
36950
|
}
|
|
36652
36951
|
}
|
|
36653
36952
|
/**
|
|
36953
|
+
* Last child of a node. 0 when the node has no children
|
|
36654
36954
|
*
|
|
36655
36955
|
* @param id
|
|
36656
36956
|
*/
|
|
@@ -36733,6 +37033,7 @@
|
|
|
36733
37033
|
}
|
|
36734
37034
|
}
|
|
36735
37035
|
/**
|
|
37036
|
+
* Set the color type of a color token, see {@link ColorType}
|
|
36736
37037
|
*
|
|
36737
37038
|
* @param id
|
|
36738
37039
|
* @param colorType
|
|
@@ -36741,6 +37042,7 @@
|
|
|
36741
37042
|
this.colorType[id] = colorType;
|
|
36742
37043
|
}
|
|
36743
37044
|
/**
|
|
37045
|
+
* Color type of a color token, see {@link ColorType}
|
|
36744
37046
|
*
|
|
36745
37047
|
* @param id
|
|
36746
37048
|
*/
|
|
@@ -36748,6 +37050,7 @@
|
|
|
36748
37050
|
return this.colorType[id];
|
|
36749
37051
|
}
|
|
36750
37052
|
/**
|
|
37053
|
+
* Replace the flags of a node, see {@link EnumAstNodeStatus}
|
|
36751
37054
|
*
|
|
36752
37055
|
* @param id
|
|
36753
37056
|
* @param flags
|
|
@@ -36756,6 +37059,7 @@
|
|
|
36756
37059
|
this.flags[id] = flags;
|
|
36757
37060
|
}
|
|
36758
37061
|
/**
|
|
37062
|
+
* Flags of a node, see {@link EnumAstNodeStatus}
|
|
36759
37063
|
*
|
|
36760
37064
|
* @param id
|
|
36761
37065
|
*/
|
|
@@ -36763,6 +37067,7 @@
|
|
|
36763
37067
|
return this.flags[id];
|
|
36764
37068
|
}
|
|
36765
37069
|
/**
|
|
37070
|
+
* `true` when a node has all the given flags, see {@link EnumAstNodeStatus}
|
|
36766
37071
|
*
|
|
36767
37072
|
* @param id
|
|
36768
37073
|
* @param flag
|
|
@@ -36771,6 +37076,7 @@
|
|
|
36771
37076
|
return (this.flags[id] & flag) === flag;
|
|
36772
37077
|
}
|
|
36773
37078
|
/**
|
|
37079
|
+
* The child of a node at a position (0 based). null when the position is out of range
|
|
36774
37080
|
*
|
|
36775
37081
|
* @param id
|
|
36776
37082
|
* @param index
|
|
@@ -36892,6 +37198,7 @@
|
|
|
36892
37198
|
this.appendTokenList(this.fieldList(id, field), tokens);
|
|
36893
37199
|
}
|
|
36894
37200
|
/**
|
|
37201
|
+
* Replace the tokens of the left hand side of a structured token
|
|
36895
37202
|
*
|
|
36896
37203
|
* @param id
|
|
36897
37204
|
* @param children
|
|
@@ -36901,6 +37208,7 @@
|
|
|
36901
37208
|
this.setTokenList(this.fieldList(id, exports.TokenField.L), children);
|
|
36902
37209
|
}
|
|
36903
37210
|
/**
|
|
37211
|
+
* Tokens of the left hand side of a structured token (numerator of a fraction, ...). null when it is not set
|
|
36904
37212
|
*
|
|
36905
37213
|
* @param id
|
|
36906
37214
|
*/
|
|
@@ -36908,15 +37216,17 @@
|
|
|
36908
37216
|
return this.getChildAt(id, exports.TokenField.L) == null ? null : this.fieldTokens(id, exports.TokenField.L);
|
|
36909
37217
|
}
|
|
36910
37218
|
/**
|
|
37219
|
+
* Replace the tokens of the right hand side of a structured token. null removes them
|
|
36911
37220
|
*
|
|
36912
|
-
* @param id
|
|
36913
|
-
* @param rightId
|
|
37221
|
+
* @param id the structured token
|
|
37222
|
+
* @param rightId the tokens, or null
|
|
36914
37223
|
*/
|
|
36915
37224
|
setRight(id, ...rightId) {
|
|
36916
37225
|
// inlined: this.setField(id, TokenField.R, ...(rightId == null || rightId[0] == null ? [] : (rightId as number[])))
|
|
36917
37226
|
this.setTokenList(this.fieldList(id, exports.TokenField.R), rightId == null || rightId[0] == null ? [] : rightId);
|
|
36918
37227
|
}
|
|
36919
37228
|
/**
|
|
37229
|
+
* Tokens of the right hand side of a structured token (denominator of a fraction, ...). null when it is not set
|
|
36920
37230
|
*
|
|
36921
37231
|
* @param id
|
|
36922
37232
|
*/
|
|
@@ -36924,6 +37234,7 @@
|
|
|
36924
37234
|
return this.getChildAt(id, exports.TokenField.R) == null ? null : this.fieldTokens(id, exports.TokenField.R);
|
|
36925
37235
|
}
|
|
36926
37236
|
/**
|
|
37237
|
+
* Set the operator token of a structured token
|
|
36927
37238
|
*
|
|
36928
37239
|
* @param id
|
|
36929
37240
|
* @param opId
|
|
@@ -36933,6 +37244,7 @@
|
|
|
36933
37244
|
this.setTokenList(this.fieldList(id, exports.TokenField.Op), [opId]);
|
|
36934
37245
|
}
|
|
36935
37246
|
/**
|
|
37247
|
+
* Operator token of a structured token: the operator of a binary expression, ...
|
|
36936
37248
|
*
|
|
36937
37249
|
* @param id
|
|
36938
37250
|
*/
|
|
@@ -36940,6 +37252,7 @@
|
|
|
36940
37252
|
return this.field(id, exports.TokenField.Op);
|
|
36941
37253
|
}
|
|
36942
37254
|
/**
|
|
37255
|
+
* Set the second operator token of a structured token: the second operator of a media range query
|
|
36943
37256
|
*
|
|
36944
37257
|
* @param id
|
|
36945
37258
|
* @param op2Id
|
|
@@ -36949,6 +37262,7 @@
|
|
|
36949
37262
|
this.setTokenList(this.fieldList(id, exports.TokenField.Op2), [op2Id]);
|
|
36950
37263
|
}
|
|
36951
37264
|
/**
|
|
37265
|
+
* Second operator token of a structured token: the second operator of a media range query
|
|
36952
37266
|
*
|
|
36953
37267
|
* @param id
|
|
36954
37268
|
*/
|
|
@@ -36956,6 +37270,7 @@
|
|
|
36956
37270
|
return this.field(id, exports.TokenField.Op2);
|
|
36957
37271
|
}
|
|
36958
37272
|
/**
|
|
37273
|
+
* Set the location of a node or a token: the id of its source file and its start and end offsets
|
|
36959
37274
|
*
|
|
36960
37275
|
* @param id
|
|
36961
37276
|
* @param sourceId
|
|
@@ -36984,6 +37299,7 @@
|
|
|
36984
37299
|
this.spans32[t + 1] = this.spans32[s + 1];
|
|
36985
37300
|
}
|
|
36986
37301
|
/**
|
|
37302
|
+
* Id of the source file of a node or a token, see {@link getSpanStart} and {@link getSpanEnd}
|
|
36987
37303
|
*
|
|
36988
37304
|
* @param id
|
|
36989
37305
|
*/
|
|
@@ -36994,6 +37310,7 @@
|
|
|
36994
37310
|
return Number((this.spans[id] >> 56n) & 0xffn);
|
|
36995
37311
|
}
|
|
36996
37312
|
/**
|
|
37313
|
+
* Start offset of a node or a token in its source file
|
|
36997
37314
|
*
|
|
36998
37315
|
* @param id
|
|
36999
37316
|
*/
|
|
@@ -37006,6 +37323,7 @@
|
|
|
37006
37323
|
}
|
|
37007
37324
|
// ---- spans ---------------------------------------------------------------------
|
|
37008
37325
|
/**
|
|
37326
|
+
* Set the start offset of a node or a token in its source file
|
|
37009
37327
|
*
|
|
37010
37328
|
* @param id
|
|
37011
37329
|
* @param start
|
|
@@ -37014,6 +37332,7 @@
|
|
|
37014
37332
|
this.setSpan(id, this.getSourceId(id), start, this.getSpanEnd(id));
|
|
37015
37333
|
}
|
|
37016
37334
|
/**
|
|
37335
|
+
* End offset of a node or a token in its source file
|
|
37017
37336
|
*
|
|
37018
37337
|
* @param id
|
|
37019
37338
|
*/
|
|
@@ -37024,6 +37343,7 @@
|
|
|
37024
37343
|
return Number(this.spans[id] & 0xfffffffn);
|
|
37025
37344
|
}
|
|
37026
37345
|
/**
|
|
37346
|
+
* Set the end offset of a node or a token in its source file
|
|
37027
37347
|
*
|
|
37028
37348
|
* @param id
|
|
37029
37349
|
* @param end
|
|
@@ -37032,6 +37352,7 @@
|
|
|
37032
37352
|
this.setSpan(id, this.getSourceId(id), this.getSpanStart(id), end);
|
|
37033
37353
|
}
|
|
37034
37354
|
/**
|
|
37355
|
+
* Parent of a node. 0 when the node has no parent
|
|
37035
37356
|
*
|
|
37036
37357
|
* @param id
|
|
37037
37358
|
*/
|
|
@@ -37039,6 +37360,7 @@
|
|
|
37039
37360
|
return this.parents[id];
|
|
37040
37361
|
}
|
|
37041
37362
|
/**
|
|
37363
|
+
* The string of a string table id. The string is created the first time it is read
|
|
37042
37364
|
*
|
|
37043
37365
|
* @param id
|
|
37044
37366
|
*/
|
|
@@ -37381,6 +37703,7 @@
|
|
|
37381
37703
|
return result;
|
|
37382
37704
|
}
|
|
37383
37705
|
/**
|
|
37706
|
+
* The first child of a node for which the predicate returns `true`. null when there is none
|
|
37384
37707
|
*
|
|
37385
37708
|
* @param id
|
|
37386
37709
|
* @param predicate
|
|
@@ -37476,6 +37799,7 @@
|
|
|
37476
37799
|
return count;
|
|
37477
37800
|
}
|
|
37478
37801
|
/**
|
|
37802
|
+
* Replace the children of a node
|
|
37479
37803
|
*
|
|
37480
37804
|
* @param id
|
|
37481
37805
|
* @param children
|
|
@@ -37502,6 +37826,7 @@
|
|
|
37502
37826
|
this.appendChildList(id, children);
|
|
37503
37827
|
}
|
|
37504
37828
|
/**
|
|
37829
|
+
* Replace the tokens of a node or a token
|
|
37505
37830
|
*
|
|
37506
37831
|
* @param id
|
|
37507
37832
|
* @param children
|
|
@@ -37551,6 +37876,7 @@
|
|
|
37551
37876
|
}
|
|
37552
37877
|
}
|
|
37553
37878
|
/**
|
|
37879
|
+
* Append children to a node
|
|
37554
37880
|
*
|
|
37555
37881
|
* @param id
|
|
37556
37882
|
* @param children
|
|
@@ -37589,6 +37915,7 @@
|
|
|
37589
37915
|
}
|
|
37590
37916
|
}
|
|
37591
37917
|
/**
|
|
37918
|
+
* Append tokens to a node or a token
|
|
37592
37919
|
*
|
|
37593
37920
|
* @param id
|
|
37594
37921
|
* @param children
|
|
@@ -37693,6 +38020,8 @@
|
|
|
37693
38020
|
}
|
|
37694
38021
|
}
|
|
37695
38022
|
/**
|
|
38023
|
+
* Compare the name (`"nam"`) or the value (`"val"`) of a node with a string, ignoring the case. The string of the
|
|
38024
|
+
* node is not created
|
|
37696
38025
|
*
|
|
37697
38026
|
* @param node
|
|
37698
38027
|
* @param key
|
|
@@ -37703,6 +38032,8 @@
|
|
|
37703
38032
|
return this.stringTable.equalsIgnoreCase(key === "nam" ? this.name[node] : this.stringValue[node], string);
|
|
37704
38033
|
}
|
|
37705
38034
|
/**
|
|
38035
|
+
* `true` when the name (`"nam"`) or the value (`"val"`) of a node starts with a string. The string of the node is
|
|
38036
|
+
* not created
|
|
37706
38037
|
*
|
|
37707
38038
|
* @param node
|
|
37708
38039
|
* @param key
|
|
@@ -37713,6 +38044,7 @@
|
|
|
37713
38044
|
return this.stringTable.startsWith(key === "nam" ? this.name[node] : this.stringValue[node], string);
|
|
37714
38045
|
}
|
|
37715
38046
|
/**
|
|
38047
|
+
* Grow the columns of the arena so they hold `newSize` ids. The columns are never shrunk
|
|
37716
38048
|
*
|
|
37717
38049
|
* @param newSize
|
|
37718
38050
|
*/
|
|
@@ -37980,6 +38312,7 @@
|
|
|
37980
38312
|
return this.compact(errors);
|
|
37981
38313
|
}
|
|
37982
38314
|
/**
|
|
38315
|
+
* Set the validation errors of a node. null or an empty list removes them
|
|
37983
38316
|
*
|
|
37984
38317
|
* @param id
|
|
37985
38318
|
* @param errors
|
|
@@ -37994,6 +38327,7 @@
|
|
|
37994
38327
|
}
|
|
37995
38328
|
}
|
|
37996
38329
|
/**
|
|
38330
|
+
* Validation errors of a node. null when the node has no errors
|
|
37997
38331
|
*
|
|
37998
38332
|
* @param id
|
|
37999
38333
|
*/
|
|
@@ -38104,8 +38438,8 @@
|
|
|
38104
38438
|
*/
|
|
38105
38439
|
inputLengths = [];
|
|
38106
38440
|
/**
|
|
38107
|
-
*
|
|
38108
|
-
* @param size
|
|
38441
|
+
* create an arena that holds an empty stylesheet
|
|
38442
|
+
* @param size initial number of nodes the columns can hold. the columns grow when they are full
|
|
38109
38443
|
*/
|
|
38110
38444
|
constructor(size = 4096) {
|
|
38111
38445
|
super(size);
|
|
@@ -38114,7 +38448,10 @@
|
|
|
38114
38448
|
this.flags[this.root] = exports.EnumAstNodeStatus.HasChildren;
|
|
38115
38449
|
}
|
|
38116
38450
|
/**
|
|
38117
|
-
*
|
|
38451
|
+
* release nodes: detach them and drop their data (interned strings, errors) and their minification caches. node
|
|
38452
|
+
* ids are never reused: the memory is reclaimed by {@link trim}
|
|
38453
|
+
* @param id the node to release. every marked node (and its descendants) is released when omitted
|
|
38454
|
+
* @param deep release the children and the tokens too
|
|
38118
38455
|
*/
|
|
38119
38456
|
release(id, deep = false) {
|
|
38120
38457
|
super.release(id, deep);
|
|
@@ -38132,7 +38469,11 @@
|
|
|
38132
38469
|
}
|
|
38133
38470
|
}
|
|
38134
38471
|
/**
|
|
38135
|
-
*
|
|
38472
|
+
* drop the nodes that are not reachable from the root and renumber the remaining nodes in document order.
|
|
38473
|
+
* the node ids change: ids obtained before the call (from visitors for instance) are no longer valid.
|
|
38474
|
+
* the unused strings and the minification caches are dropped too
|
|
38475
|
+
* @param errors error descriptions whose `node` is remapped
|
|
38476
|
+
* @returns mapping of the old ids to the new ids (0 when the node was dropped)
|
|
38136
38477
|
*/
|
|
38137
38478
|
compact(errors) {
|
|
38138
38479
|
const mapping = super.compact(errors);
|
|
@@ -39070,7 +39411,7 @@
|
|
|
39070
39411
|
return tokens.reduce((acc, curr) => acc + renderValue(this, curr), "");
|
|
39071
39412
|
}
|
|
39072
39413
|
/**
|
|
39073
|
-
*
|
|
39414
|
+
* structured-cloneable properties of the arena, the sources and the minification caches included
|
|
39074
39415
|
*/
|
|
39075
39416
|
exportProperties() {
|
|
39076
39417
|
return {
|
|
@@ -39083,7 +39424,10 @@
|
|
|
39083
39424
|
};
|
|
39084
39425
|
}
|
|
39085
39426
|
/**
|
|
39086
|
-
*
|
|
39427
|
+
* initialize the arena from exported properties and column buffers, the sources and the minification caches
|
|
39428
|
+
* included
|
|
39429
|
+
* @param properties
|
|
39430
|
+
* @param transferables
|
|
39087
39431
|
*/
|
|
39088
39432
|
importProperties(properties, transferables) {
|
|
39089
39433
|
super.importProperties(properties, transferables);
|
|
@@ -39491,6 +39835,7 @@
|
|
|
39491
39835
|
}
|
|
39492
39836
|
}
|
|
39493
39837
|
/**
|
|
39838
|
+
* Replace the nesting selectors (`&`) of a compound selector with a selector
|
|
39494
39839
|
*
|
|
39495
39840
|
* @param selector
|
|
39496
39841
|
* @param replace
|
|
@@ -41081,7 +41426,30 @@
|
|
|
41081
41426
|
*/
|
|
41082
41427
|
const littleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
41083
41428
|
const decoder = new TextDecoder();
|
|
41084
|
-
|
|
41429
|
+
/**
|
|
41430
|
+
* true if the bytes are ascii. the bytes are read 4 at a time when they are aligned: 5 times faster than a regular
|
|
41431
|
+
* expression on the decoded text
|
|
41432
|
+
* @param bytes
|
|
41433
|
+
*/
|
|
41434
|
+
function isAscii(bytes) {
|
|
41435
|
+
const length = bytes.length;
|
|
41436
|
+
let bits = 0;
|
|
41437
|
+
let i = 0;
|
|
41438
|
+
if ((bytes.byteOffset & 3) === 0) {
|
|
41439
|
+
const words = new Uint32Array(bytes.buffer, bytes.byteOffset, length >>> 2);
|
|
41440
|
+
for (let k = 0; k < words.length; k++) {
|
|
41441
|
+
bits |= words[k];
|
|
41442
|
+
}
|
|
41443
|
+
if ((bits & 0x80808080) !== 0) {
|
|
41444
|
+
return false;
|
|
41445
|
+
}
|
|
41446
|
+
i = words.length << 2;
|
|
41447
|
+
}
|
|
41448
|
+
for (; i < length; i++) {
|
|
41449
|
+
bits |= bytes[i];
|
|
41450
|
+
}
|
|
41451
|
+
return (bits & 0x80) === 0;
|
|
41452
|
+
}
|
|
41085
41453
|
const empty = new Uint8Array(0);
|
|
41086
41454
|
/**
|
|
41087
41455
|
* true if the input is an ArrayBuffer or a view of an ArrayBuffer
|
|
@@ -41144,11 +41512,46 @@
|
|
|
41144
41512
|
const bytes = bytesOf(input);
|
|
41145
41513
|
const text = decoder.decode(bytes);
|
|
41146
41514
|
// the text of an ascii input has a character for each byte. the byte order mark is removed by the decoder
|
|
41147
|
-
if (text.length === bytes.length &&
|
|
41515
|
+
if (text.length === bytes.length && isAscii(bytes)) {
|
|
41148
41516
|
return { codes: bytes, text };
|
|
41149
41517
|
}
|
|
41150
41518
|
return { codes: codeUnitsOf(text), text };
|
|
41151
41519
|
}
|
|
41520
|
+
/**
|
|
41521
|
+
* the size of the css of the streams, in bytes, when it is known (a file, a response with a content length)
|
|
41522
|
+
*/
|
|
41523
|
+
const streamSizes = new WeakMap();
|
|
41524
|
+
/**
|
|
41525
|
+
* record the size of the css of a stream, in bytes: the parser allocates the code units and the arena once, like for
|
|
41526
|
+
* an ArrayBuffer, instead of growing them as the stream is read. 0: the size is not known
|
|
41527
|
+
* @param stream
|
|
41528
|
+
* @param size
|
|
41529
|
+
*/
|
|
41530
|
+
function setStreamSize(stream, size) {
|
|
41531
|
+
if (size > 0) {
|
|
41532
|
+
streamSizes.set(stream, size);
|
|
41533
|
+
}
|
|
41534
|
+
return stream;
|
|
41535
|
+
}
|
|
41536
|
+
/**
|
|
41537
|
+
* the size of the css of a stream, in bytes, see {@link setStreamSize}. 0: the size is not known
|
|
41538
|
+
* @param stream
|
|
41539
|
+
*/
|
|
41540
|
+
function getStreamSize(stream) {
|
|
41541
|
+
return stream == null ? 0 : (streamSizes.get(stream) ?? 0);
|
|
41542
|
+
}
|
|
41543
|
+
/**
|
|
41544
|
+
* the size of the body of a response: its content length, 0 when it is not known or when the body is compressed (the
|
|
41545
|
+
* content length is the size of the compressed body)
|
|
41546
|
+
* @param response
|
|
41547
|
+
*/
|
|
41548
|
+
function responseSize(response) {
|
|
41549
|
+
if (response.headers.get("content-encoding") != null) {
|
|
41550
|
+
return 0;
|
|
41551
|
+
}
|
|
41552
|
+
const length = Number(response.headers.get("content-length"));
|
|
41553
|
+
return Number.isFinite(length) && length > 0 ? length : 0;
|
|
41554
|
+
}
|
|
41152
41555
|
|
|
41153
41556
|
/**
|
|
41154
41557
|
* decoded code units of the last value decoded by {@link decodeEscapes}
|
|
@@ -41804,17 +42207,52 @@
|
|
|
41804
42207
|
hint = null;
|
|
41805
42208
|
state = null;
|
|
41806
42209
|
parseInfo;
|
|
42210
|
+
/**
|
|
42211
|
+
* true when the whole css is in {@link ParseInfo.codes}: the input is not a stream, or the stream is read to its end
|
|
42212
|
+
*/
|
|
42213
|
+
streamDone = true;
|
|
42214
|
+
/**
|
|
42215
|
+
* the last call of {@link next} reached the end of the code units read from the stream: the token may continue in
|
|
42216
|
+
* the next chunk. no token is returned, the stream must be read ({@link read}) before {@link next} is called again
|
|
42217
|
+
*/
|
|
42218
|
+
waiting = false;
|
|
42219
|
+
/**
|
|
42220
|
+
* reader of the stream
|
|
42221
|
+
*/
|
|
42222
|
+
reader = null;
|
|
42223
|
+
/**
|
|
42224
|
+
* decoder of the chunks of the stream: a character can be split between two chunks
|
|
42225
|
+
*/
|
|
42226
|
+
decoder = null;
|
|
42227
|
+
/**
|
|
42228
|
+
* the code units read from the stream: {@link ParseInfo.codes} is a view of its first {@link ParseInfo.length}
|
|
42229
|
+
* code units. the buffer doubles when it is full, the code units are copied once per doubling
|
|
42230
|
+
*/
|
|
42231
|
+
buffer = new Uint8Array(0);
|
|
42232
|
+
/**
|
|
42233
|
+
* the size of the css of the stream, in bytes, when it is known (see {@link setStreamSize}). 0: not known
|
|
42234
|
+
*/
|
|
42235
|
+
expectedLength = 0;
|
|
41807
42236
|
/**
|
|
41808
42237
|
* @param parseInfo the parse info, or the css: a string, an ArrayBuffer or a view of an ArrayBuffer
|
|
41809
42238
|
* @param input a stream of css
|
|
41810
42239
|
*/
|
|
41811
42240
|
constructor(parseInfo, input = null) {
|
|
41812
42241
|
this.input = input;
|
|
42242
|
+
if (input != null) {
|
|
42243
|
+
this.streamDone = false;
|
|
42244
|
+
this.expectedLength = getStreamSize(input);
|
|
42245
|
+
// the size of the stream is known: the code units are allocated once. the size in bytes is not less than
|
|
42246
|
+
// the number of utf-16 code units
|
|
42247
|
+
if (this.expectedLength > 0) {
|
|
42248
|
+
this.buffer = new Uint8Array(this.expectedLength);
|
|
42249
|
+
}
|
|
42250
|
+
}
|
|
41813
42251
|
if (isCssInput(parseInfo)) {
|
|
41814
42252
|
this.parseInfo = createParseInfo(parseInfo, new SourceFile("", [], ""));
|
|
41815
42253
|
}
|
|
41816
42254
|
else {
|
|
41817
|
-
// the
|
|
42255
|
+
// the code units of a stream are appended chunk by chunk, see read()
|
|
41818
42256
|
if (parseInfo.codes == null && input == null) {
|
|
41819
42257
|
Tokenizer.load(parseInfo, parseInfo.source.content);
|
|
41820
42258
|
}
|
|
@@ -42712,9 +43150,37 @@
|
|
|
42712
43150
|
return this.typ === exports.EnumToken.EOF;
|
|
42713
43151
|
}
|
|
42714
43152
|
/**
|
|
42715
|
-
*
|
|
43153
|
+
* read the next token. when the input is a stream that is not read to its end, a token that ends near the end of
|
|
43154
|
+
* the code units read so far may continue in the next chunk (an identifier, a number, a string, a comment, ...): the
|
|
43155
|
+
* token is not returned, {@link waiting} is true and the stream must be read ({@link read}) before the next call
|
|
43156
|
+
*/
|
|
43157
|
+
next() {
|
|
43158
|
+
if (this.streamDone) {
|
|
43159
|
+
return this.nextToken();
|
|
43160
|
+
}
|
|
43161
|
+
const parseInfo = this.parseInfo;
|
|
43162
|
+
const position = parseInfo.position;
|
|
43163
|
+
const currentPosition = parseInfo.currentPosition;
|
|
43164
|
+
const state = this.state;
|
|
43165
|
+
const lineStarts = parseInfo.source.lineStarts.lineStarts;
|
|
43166
|
+
const lineCount = lineStarts.length;
|
|
43167
|
+
this.nextToken();
|
|
43168
|
+
// the tokenizer reads at most a few code units after the end of a token: the token is complete when the
|
|
43169
|
+
// stream has more code units after it
|
|
43170
|
+
if (parseInfo.currentPosition + STREAM_LOOKAHEAD > parseInfo.length) {
|
|
43171
|
+
parseInfo.position = position;
|
|
43172
|
+
parseInfo.currentPosition = currentPosition;
|
|
43173
|
+
this.state = state;
|
|
43174
|
+
lineStarts.length = lineCount;
|
|
43175
|
+
this.typ = null;
|
|
43176
|
+
this.waiting = true;
|
|
43177
|
+
}
|
|
43178
|
+
return this;
|
|
43179
|
+
}
|
|
43180
|
+
/**
|
|
43181
|
+
* read the next token from the code units of the input
|
|
42716
43182
|
*/
|
|
42717
|
-
|
|
43183
|
+
nextToken() {
|
|
42718
43184
|
const parseInfo = this.parseInfo;
|
|
42719
43185
|
this.source = parseInfo.source;
|
|
42720
43186
|
let charCode;
|
|
@@ -43141,27 +43607,106 @@
|
|
|
43141
43607
|
return this.makeToken(parseInfo, exports.EnumToken.EOFTokenType);
|
|
43142
43608
|
}
|
|
43143
43609
|
/**
|
|
43144
|
-
*
|
|
43610
|
+
* start reading the stream: the first chunk is read. the next chunks are read when the tokenizer reaches the end
|
|
43611
|
+
* of the code units read so far, see {@link next} and {@link read}
|
|
43145
43612
|
*/
|
|
43146
43613
|
async tokenizeStream() {
|
|
43147
|
-
|
|
43148
|
-
|
|
43149
|
-
|
|
43150
|
-
|
|
43151
|
-
|
|
43152
|
-
|
|
43153
|
-
|
|
43154
|
-
|
|
43155
|
-
|
|
43156
|
-
|
|
43157
|
-
|
|
43614
|
+
if (!this.streamDone && this.reader == null) {
|
|
43615
|
+
await this.read();
|
|
43616
|
+
}
|
|
43617
|
+
return this;
|
|
43618
|
+
}
|
|
43619
|
+
/**
|
|
43620
|
+
* read the next chunk of the stream and append it to the css: the text of the source file and the code units.
|
|
43621
|
+
* the code units stay a view of the bytes while the css is ascii, they are utf-16 code units otherwise
|
|
43622
|
+
*/
|
|
43623
|
+
async read() {
|
|
43624
|
+
if (this.streamDone) {
|
|
43625
|
+
this.waiting = false;
|
|
43626
|
+
return;
|
|
43627
|
+
}
|
|
43628
|
+
if (this.reader == null) {
|
|
43629
|
+
this.reader = this.input.getReader();
|
|
43630
|
+
this.decoder = new TextDecoder("utf-8");
|
|
43631
|
+
}
|
|
43632
|
+
// the chunks are appended together: at least 64 KB, or half of the css read so far. the text of the css is copied
|
|
43633
|
+
// when it is read after a chunk is appended (a string is not appended in place): the batches grow with the css,
|
|
43634
|
+
// the text is copied a few times instead of once per chunk
|
|
43635
|
+
const batch = Math.max(STREAM_BATCH, this.parseInfo.length >> 1);
|
|
43636
|
+
const texts = [];
|
|
43637
|
+
let length = 0;
|
|
43638
|
+
while (length < batch) {
|
|
43639
|
+
const { done, value } = await this.reader.read();
|
|
43640
|
+
if (done) {
|
|
43641
|
+
// the end of a character split between the last chunks
|
|
43642
|
+
texts.push(this.decoder.decode());
|
|
43643
|
+
this.streamDone = true;
|
|
43644
|
+
this.reader.releaseLock();
|
|
43158
43645
|
break;
|
|
43159
43646
|
}
|
|
43647
|
+
const text = typeof value === "string" ? value : this.decoder.decode(value, { stream: true });
|
|
43648
|
+
texts.push(text);
|
|
43649
|
+
length += text.length;
|
|
43650
|
+
}
|
|
43651
|
+
const text = texts.length === 1 ? texts[0] : texts.join("");
|
|
43652
|
+
if (text.length > 0) {
|
|
43653
|
+
this.append(text);
|
|
43654
|
+
}
|
|
43655
|
+
this.waiting = false;
|
|
43656
|
+
}
|
|
43657
|
+
/**
|
|
43658
|
+
* append the text of a chunk to the css
|
|
43659
|
+
* @param text
|
|
43660
|
+
*/
|
|
43661
|
+
append(text) {
|
|
43662
|
+
const parseInfo = this.parseInfo;
|
|
43663
|
+
const length = parseInfo.length;
|
|
43664
|
+
const required = length + text.length;
|
|
43665
|
+
parseInfo.source.content += text;
|
|
43666
|
+
if (required > this.buffer.length) {
|
|
43667
|
+
let capacity = this.buffer.length > 0 ? this.buffer.length * 2 : 1 << 16;
|
|
43668
|
+
while (capacity < required) {
|
|
43669
|
+
capacity *= 2;
|
|
43670
|
+
}
|
|
43671
|
+
const buffer = this.buffer instanceof Uint8Array ? new Uint8Array(capacity) : new Uint16Array(capacity);
|
|
43672
|
+
buffer.set(this.buffer.subarray(0, length));
|
|
43673
|
+
this.buffer = buffer;
|
|
43674
|
+
}
|
|
43675
|
+
let ascii = false;
|
|
43676
|
+
if (this.buffer instanceof Uint8Array) {
|
|
43677
|
+
// an ascii text has a byte for each character
|
|
43678
|
+
const { read, written } = streamEncoder.encodeInto(text, this.buffer.subarray(length, required));
|
|
43679
|
+
ascii = read === text.length && written === text.length;
|
|
43680
|
+
if (!ascii) {
|
|
43681
|
+
// the css is not ascii: the code units are utf-16 code units from now on
|
|
43682
|
+
const buffer = new Uint16Array(this.buffer.length);
|
|
43683
|
+
buffer.set(this.buffer.subarray(0, length));
|
|
43684
|
+
this.buffer = buffer;
|
|
43685
|
+
}
|
|
43686
|
+
}
|
|
43687
|
+
if (!ascii) {
|
|
43688
|
+
const buffer = this.buffer;
|
|
43689
|
+
for (let i = 0; i < text.length; i++) {
|
|
43690
|
+
buffer[length + i] = text.charCodeAt(i);
|
|
43691
|
+
}
|
|
43160
43692
|
}
|
|
43161
|
-
|
|
43162
|
-
|
|
43693
|
+
parseInfo.length = required;
|
|
43694
|
+
parseInfo.codes = this.buffer.subarray(0, required);
|
|
43163
43695
|
}
|
|
43164
43696
|
}
|
|
43697
|
+
/**
|
|
43698
|
+
* number of code units the tokenizer may read after the end of a token (escape sequences, unicode ranges, `<!--`,
|
|
43699
|
+
* ...): a token read from a stream is complete when the stream has more code units after it, see {@link Tokenizer.next}
|
|
43700
|
+
*/
|
|
43701
|
+
const STREAM_LOOKAHEAD = 32;
|
|
43702
|
+
/**
|
|
43703
|
+
* minimum number of code units appended to the css when a stream is read, see {@link Tokenizer.read}
|
|
43704
|
+
*/
|
|
43705
|
+
const STREAM_BATCH = 1 << 16;
|
|
43706
|
+
/**
|
|
43707
|
+
* encoder of the chunks of a stream, see {@link Tokenizer.append}
|
|
43708
|
+
*/
|
|
43709
|
+
const streamEncoder = new TextEncoder();
|
|
43165
43710
|
|
|
43166
43711
|
/**
|
|
43167
43712
|
* response type
|
|
@@ -43463,6 +44008,58 @@
|
|
|
43463
44008
|
}
|
|
43464
44009
|
}
|
|
43465
44010
|
}
|
|
44011
|
+
/**
|
|
44012
|
+
* true if the token is a keyframe selector: `from`, `to` or a percentage between 0 and 100
|
|
44013
|
+
* @param arena
|
|
44014
|
+
* @param token
|
|
44015
|
+
*/
|
|
44016
|
+
function isKeyframeSelectorToken(arena, token) {
|
|
44017
|
+
if (token === undefined) {
|
|
44018
|
+
return false;
|
|
44019
|
+
}
|
|
44020
|
+
if (arena.dataTypes[token] === exports.EnumToken.PercentageTokenType) {
|
|
44021
|
+
return arena.numericValue[token] >= 0 && arena.numericValue[token] <= 100;
|
|
44022
|
+
}
|
|
44023
|
+
if (arena.dataTypes[token] !== exports.EnumToken.IdenTokenType) {
|
|
44024
|
+
return false;
|
|
44025
|
+
}
|
|
44026
|
+
const id = arena.stringValue[token];
|
|
44027
|
+
const length = arena.stringLength(id);
|
|
44028
|
+
// `from` and `to`, case-insensitive
|
|
44029
|
+
return length === 4
|
|
44030
|
+
? (arena.stringCodeAt(id, 0) | 0x20) === 0x66 &&
|
|
44031
|
+
(arena.stringCodeAt(id, 1) | 0x20) === 0x72 &&
|
|
44032
|
+
(arena.stringCodeAt(id, 2) | 0x20) === 0x6f &&
|
|
44033
|
+
(arena.stringCodeAt(id, 3) | 0x20) === 0x6d
|
|
44034
|
+
: length === 2 && (arena.stringCodeAt(id, 0) | 0x20) === 0x74 && (arena.stringCodeAt(id, 1) | 0x20) === 0x6f;
|
|
44035
|
+
}
|
|
44036
|
+
/**
|
|
44037
|
+
* true if the selector of a keyframe is a list of `from`, `to` and percentages between 0 and 100, separated by commas
|
|
44038
|
+
* and whitespace: it matches the `keyframe-selectors` syntax
|
|
44039
|
+
* @param arena
|
|
44040
|
+
* @param tokens
|
|
44041
|
+
*/
|
|
44042
|
+
function isSimpleKeyframeSelector(arena, tokens) {
|
|
44043
|
+
// a keyframe selector is expected
|
|
44044
|
+
let selector = true;
|
|
44045
|
+
let i = 0;
|
|
44046
|
+
for (; i < tokens.length; i++) {
|
|
44047
|
+
const type = arena.dataTypes[tokens[i]];
|
|
44048
|
+
if (type === exports.EnumToken.WhitespaceTokenType) {
|
|
44049
|
+
continue;
|
|
44050
|
+
}
|
|
44051
|
+
if (selector) {
|
|
44052
|
+
if (!isKeyframeSelectorToken(arena, tokens[i])) {
|
|
44053
|
+
return false;
|
|
44054
|
+
}
|
|
44055
|
+
}
|
|
44056
|
+
else if (type !== exports.EnumToken.CommaTokenType) {
|
|
44057
|
+
return false;
|
|
44058
|
+
}
|
|
44059
|
+
selector = !selector;
|
|
44060
|
+
}
|
|
44061
|
+
return !selector;
|
|
44062
|
+
}
|
|
43466
44063
|
/**
|
|
43467
44064
|
* parse selector
|
|
43468
44065
|
* @param arena
|
|
@@ -43475,7 +44072,10 @@
|
|
|
43475
44072
|
const contextType = context == null ? null : arena.dataTypes[context];
|
|
43476
44073
|
splitUnicodeRanges(arena, tokens);
|
|
43477
44074
|
if (contextType === exports.EnumToken.KeyframesAtRuleNodeType) {
|
|
43478
|
-
|
|
44075
|
+
// `from`, `to` and the percentages are valid: the syntax is not matched
|
|
44076
|
+
const result = isSimpleKeyframeSelector(arena, tokens)
|
|
44077
|
+
? { success: true, errors: [] }
|
|
44078
|
+
: matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "keyframe-selectors"), createValidationContext(arena, tokens), options);
|
|
43479
44079
|
const parts = splitTokenList(arena, tokens);
|
|
43480
44080
|
for (const part of parts) {
|
|
43481
44081
|
trimArray(arena, part);
|
|
@@ -43523,8 +44123,11 @@
|
|
|
43523
44123
|
allowed = false;
|
|
43524
44124
|
if (contextType === exports.EnumToken.AtRuleNodeType) {
|
|
43525
44125
|
// computed once per at-rule name: the name is not concatenated for each selector
|
|
44126
|
+
const previousAtRuleArena = atRuleArena;
|
|
43526
44127
|
atRuleArena = arena;
|
|
43527
44128
|
allowed = arena.stringDerived(arena.name[context], 3 /* StringDerived.AtRuleAcceptsRules */, atRuleAcceptsRules);
|
|
44129
|
+
// the arena is not kept after the parse: the previous arena is restored (a nested call)
|
|
44130
|
+
atRuleArena = previousAtRuleArena;
|
|
43528
44131
|
}
|
|
43529
44132
|
}
|
|
43530
44133
|
while (parent != null && parent > 0) {
|
|
@@ -43625,9 +44228,11 @@
|
|
|
43625
44228
|
}
|
|
43626
44229
|
tokens.length = write;
|
|
43627
44230
|
}
|
|
43628
|
-
|
|
44231
|
+
// a selector made of simple selectors is valid, it has no attribute selector and no function
|
|
44232
|
+
const simple = matchSimpleSelector(arena, tokens);
|
|
44233
|
+
const result = simple ? simpleSelectorMatch : matchSelectorSyntax(arena, tokens, errors, options, nested);
|
|
43629
44234
|
trimArray(arena, tokens);
|
|
43630
|
-
if (result.success) {
|
|
44235
|
+
if (result.success && !simple) {
|
|
43631
44236
|
for (let i = 0; i < tokens.length; i++) {
|
|
43632
44237
|
const token = tokens[i];
|
|
43633
44238
|
switch (arena.dataTypes[token]) {
|
|
@@ -43680,7 +44285,7 @@
|
|
|
43680
44285
|
}
|
|
43681
44286
|
}
|
|
43682
44287
|
}
|
|
43683
|
-
const node = arena.createRule(exports.EnumToken.RuleNodeType, renderSelector(arena, tokens), tokens, result.success && allowed
|
|
44288
|
+
const node = arena.createRule(exports.EnumToken.RuleNodeType, simple ? renderSimpleSelector(arena, tokens) : renderSelector(arena, tokens), tokens, result.success && allowed
|
|
43684
44289
|
? exports.EnumAstNodeStatus.Validated
|
|
43685
44290
|
: allowed
|
|
43686
44291
|
? exports.EnumAstNodeStatus.Invalid
|
|
@@ -43689,6 +44294,13 @@
|
|
|
43689
44294
|
arena.setLocation(node, arena.sources[arena.getSourceId(tokens[0])] ?? 0, arena.getSpanStart(tokens[0]), arena.getSpanEnd(tokens[tokens.length - 1]));
|
|
43690
44295
|
return node;
|
|
43691
44296
|
}
|
|
44297
|
+
/**
|
|
44298
|
+
* result of the validation of a simple selector, see {@link matchSimpleSelector}
|
|
44299
|
+
*/
|
|
44300
|
+
const simpleSelectorMatch = Object.freeze({
|
|
44301
|
+
success: true,
|
|
44302
|
+
errors: Object.freeze([]),
|
|
44303
|
+
});
|
|
43692
44304
|
// options of the rendering of the selector tokens
|
|
43693
44305
|
const selectorRenderOptions = { minify: false };
|
|
43694
44306
|
/**
|
|
@@ -43712,7 +44324,7 @@
|
|
|
43712
44324
|
const rules = syntaxRule?.getBlockRules?.();
|
|
43713
44325
|
if (rules != null) {
|
|
43714
44326
|
for (const rule of rules) {
|
|
43715
|
-
if (ValidationTokenEnum.PropertyType === rule.typ &&
|
|
44327
|
+
if (exports.ValidationTokenEnum.PropertyType === rule.typ &&
|
|
43716
44328
|
("block-contents" === rule.val ||
|
|
43717
44329
|
"rule-list" === rule.val)) {
|
|
43718
44330
|
return true;
|
|
@@ -43953,6 +44565,31 @@
|
|
|
43953
44565
|
selectorOffsets[selectors * 2 + 1] = end;
|
|
43954
44566
|
return selectors + 1;
|
|
43955
44567
|
}
|
|
44568
|
+
/**
|
|
44569
|
+
* selector of a rule made of simple selectors (see {@link matchSimpleSelector}), without the leading and the trailing
|
|
44570
|
+
* whitespace: the string of a single token is used as is, a compound or a complex selector is built without
|
|
44571
|
+
* {@link renderSelector}. a selector list is rendered with {@link renderSelector}: the duplicate selectors are removed
|
|
44572
|
+
* @param arena
|
|
44573
|
+
* @param tokens
|
|
44574
|
+
* @returns the interned string id of the selector
|
|
44575
|
+
*/
|
|
44576
|
+
function renderSimpleSelector(arena, tokens) {
|
|
44577
|
+
if (tokens.length === 1) {
|
|
44578
|
+
const type = arena.dataTypes[tokens[0]];
|
|
44579
|
+
// rendered as their string by appendSelectorToken()
|
|
44580
|
+
if (type !== exports.EnumToken.PseudoElementTokenType) {
|
|
44581
|
+
return arena.stringValue[tokens[0]];
|
|
44582
|
+
}
|
|
44583
|
+
}
|
|
44584
|
+
selectorBuilder.reset();
|
|
44585
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
44586
|
+
if (arena.dataTypes[tokens[index]] === exports.EnumToken.CommaTokenType) {
|
|
44587
|
+
return renderSelector(arena, tokens);
|
|
44588
|
+
}
|
|
44589
|
+
appendSelectorToken(arena, tokens[index], selectorBuilder);
|
|
44590
|
+
}
|
|
44591
|
+
return arena.internBuilder(selectorBuilder);
|
|
44592
|
+
}
|
|
43956
44593
|
/**
|
|
43957
44594
|
* selector of a rule: the distinct comma separated selectors, the whitespace around the combinators is removed.
|
|
43958
44595
|
* a universal selector is removed before a compound selector. the selector is built from the code units of the
|
|
@@ -44163,7 +44800,7 @@
|
|
|
44163
44800
|
// else
|
|
44164
44801
|
if (syntaxRules == null ||
|
|
44165
44802
|
(syntaxRules.length === 1 &&
|
|
44166
|
-
syntaxRules[0].typ === ValidationTokenEnum.PropertyType &&
|
|
44803
|
+
syntaxRules[0].typ === exports.ValidationTokenEnum.PropertyType &&
|
|
44167
44804
|
(syntaxRules[0].val === "declaration-list" ||
|
|
44168
44805
|
syntaxRules[0].val === "declaration-rule-list" ||
|
|
44169
44806
|
syntaxRules[0].val === "block-contents"))) {
|
|
@@ -44532,7 +45169,47 @@
|
|
|
44532
45169
|
i++;
|
|
44533
45170
|
}
|
|
44534
45171
|
// [not | only] <media-type> [ and <media-condition-without-or> ]?
|
|
44535
|
-
|
|
45172
|
+
let modifier = null;
|
|
45173
|
+
if (i < stream.length && arena.dataTypes[stream[i]] === exports.EnumToken.IdenTokenType) {
|
|
45174
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
45175
|
+
if (val === "not" || val === "only") {
|
|
45176
|
+
modifier = val;
|
|
45177
|
+
tokens.push(stream[i]);
|
|
45178
|
+
i++;
|
|
45179
|
+
while (i < stream.length &&
|
|
45180
|
+
(arena.dataTypes[stream[i]] === exports.EnumToken.WhitespaceTokenType ||
|
|
45181
|
+
arena.dataTypes[stream[i]] === exports.EnumToken.CommentTokenType)) {
|
|
45182
|
+
tokens.push(stream[i]);
|
|
45183
|
+
i++;
|
|
45184
|
+
}
|
|
45185
|
+
}
|
|
45186
|
+
}
|
|
45187
|
+
if (modifier != null && i === stream.length) {
|
|
45188
|
+
success = false;
|
|
45189
|
+
errors.push({
|
|
45190
|
+
action: "drop",
|
|
45191
|
+
message: `expecting '<media-type>'`,
|
|
45192
|
+
node: stream[i - 1],
|
|
45193
|
+
location: [
|
|
45194
|
+
options.source.file,
|
|
45195
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i - 1])),
|
|
45196
|
+
],
|
|
45197
|
+
});
|
|
45198
|
+
}
|
|
45199
|
+
else if (modifier === "only" && arena.dataTypes[stream[i]] !== exports.EnumToken.IdenTokenType) {
|
|
45200
|
+
// only is followed by a media type
|
|
45201
|
+
success = false;
|
|
45202
|
+
errors.push({
|
|
45203
|
+
action: "drop",
|
|
45204
|
+
message: `expecting '<media-type>'`,
|
|
45205
|
+
node: stream[i],
|
|
45206
|
+
location: [
|
|
45207
|
+
options.source.file,
|
|
45208
|
+
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
45209
|
+
],
|
|
45210
|
+
});
|
|
45211
|
+
}
|
|
45212
|
+
else if (i < stream.length) {
|
|
44536
45213
|
if (arena.dataTypes[stream[i]] === exports.EnumToken.IdenTokenType) {
|
|
44537
45214
|
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
44538
45215
|
if (mediaTypes.includes(val)) {
|
|
@@ -46145,7 +46822,8 @@
|
|
|
46145
46822
|
* @param tokenizer
|
|
46146
46823
|
*/
|
|
46147
46824
|
function arenaCapacity(tokenizer) {
|
|
46148
|
-
|
|
46825
|
+
// a stream: the size of the css when it is known, the arena is allocated as for an ArrayBuffer
|
|
46826
|
+
const length = Math.max(tokenizer.streamLength, tokenizer.expectedLength);
|
|
46149
46827
|
// small inputs (css modules, inline styles, ...) do not allocate a large arena, the arena grows when needed
|
|
46150
46828
|
return length === 0 ? 4096 : Math.min(1 << 25, Math.ceil(length / 4) + 1024);
|
|
46151
46829
|
}
|
|
@@ -46187,6 +46865,29 @@
|
|
|
46187
46865
|
}
|
|
46188
46866
|
return item;
|
|
46189
46867
|
}
|
|
46868
|
+
/**
|
|
46869
|
+
* allocate a whitespace token
|
|
46870
|
+
* @param arena
|
|
46871
|
+
* @param sourceIndex index of the source in the arena sources table
|
|
46872
|
+
* @param start
|
|
46873
|
+
* @param end
|
|
46874
|
+
*/
|
|
46875
|
+
function allocateWhitespace(arena, sourceIndex, start, end) {
|
|
46876
|
+
const item = arena.allocate();
|
|
46877
|
+
arena.dataTypes[item] = exports.EnumToken.WhitespaceTokenType;
|
|
46878
|
+
arena.setTokenLocation(item, sourceIndex, start, end);
|
|
46879
|
+
return item;
|
|
46880
|
+
}
|
|
46881
|
+
/**
|
|
46882
|
+
* true if the token ends a statement or a block: the whitespace that precedes it is not significant
|
|
46883
|
+
* @param type
|
|
46884
|
+
*/
|
|
46885
|
+
function isStatementEnd(type) {
|
|
46886
|
+
return (type === exports.EnumToken.SemiColonTokenType ||
|
|
46887
|
+
type === exports.EnumToken.BlockStartTokenType ||
|
|
46888
|
+
type === exports.EnumToken.BlockEndTokenType ||
|
|
46889
|
+
type === exports.EnumToken.EOFTokenType);
|
|
46890
|
+
}
|
|
46190
46891
|
/**
|
|
46191
46892
|
* recycle the tokens of a statement that were not attached to the tree: their ids are reused by the next allocations.
|
|
46192
46893
|
* the tokens referenced by the errors or the invalid nodes of the statement are kept
|
|
@@ -46198,6 +46899,8 @@
|
|
|
46198
46899
|
* @param invalidStart index of the first invalid node of the statement
|
|
46199
46900
|
*/
|
|
46200
46901
|
function recycleStatementTokens(arena, tokens, errors, errorStart, invalidNodes, invalidStart) {
|
|
46902
|
+
// the statement has errors or invalid nodes: the tokens they reference are kept
|
|
46903
|
+
const references = errors.length > errorStart || invalidNodes.length > invalidStart;
|
|
46201
46904
|
for (let i = 0; i < tokens.length; i++) {
|
|
46202
46905
|
const token = tokens[i];
|
|
46203
46906
|
// already recycled (a token can be recorded twice), attached or holding other tokens
|
|
@@ -46207,6 +46910,10 @@
|
|
|
46207
46910
|
arena.firstToken[token] !== 0) {
|
|
46208
46911
|
continue;
|
|
46209
46912
|
}
|
|
46913
|
+
if (!references) {
|
|
46914
|
+
arena.recycle(token);
|
|
46915
|
+
continue;
|
|
46916
|
+
}
|
|
46210
46917
|
let referenced = invalidNodes.indexOf(token, invalidStart) !== -1;
|
|
46211
46918
|
for (let j = errorStart; !referenced && j < errors.length; j++) {
|
|
46212
46919
|
referenced = errors[j].node === token;
|
|
@@ -46650,6 +47357,14 @@
|
|
|
46650
47357
|
}
|
|
46651
47358
|
return result;
|
|
46652
47359
|
}
|
|
47360
|
+
/**
|
|
47361
|
+
* the settings of the fast mode (see {@link ParserOptions.fastMode}): the default values of these options when
|
|
47362
|
+
* `fastMode` is `true`
|
|
47363
|
+
*/
|
|
47364
|
+
const fastModeOptions = Object.freeze({
|
|
47365
|
+
minify: false,
|
|
47366
|
+
mergeRules: exports.MergeRulesEnum.None,
|
|
47367
|
+
});
|
|
46653
47368
|
/**
|
|
46654
47369
|
* Parse css string
|
|
46655
47370
|
* @param tokenizer
|
|
@@ -46660,6 +47375,8 @@
|
|
|
46660
47375
|
*/
|
|
46661
47376
|
function doParseSync(tokenizer, options = {}) {
|
|
46662
47377
|
if (options.signal != null) {
|
|
47378
|
+
// an aborted signal does not dispatch the abort event
|
|
47379
|
+
options.signal.throwIfAborted();
|
|
46663
47380
|
options.signal.addEventListener("abort", reject);
|
|
46664
47381
|
}
|
|
46665
47382
|
options = {
|
|
@@ -46684,6 +47401,7 @@
|
|
|
46684
47401
|
removePrefix: false,
|
|
46685
47402
|
validation: false,
|
|
46686
47403
|
lenient: true,
|
|
47404
|
+
...(options.fastMode ? fastModeOptions : null),
|
|
46687
47405
|
...options,
|
|
46688
47406
|
};
|
|
46689
47407
|
options.validation = !!options.validation;
|
|
@@ -46735,13 +47453,34 @@
|
|
|
46735
47453
|
// the strings of the tokens are ranges of the content of the source
|
|
46736
47454
|
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
46737
47455
|
let itemType;
|
|
47456
|
+
// whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
|
|
47457
|
+
// is not allocated. the whitespace that follows a token is allocated when the next token is read
|
|
47458
|
+
let whitespaceStart = -1;
|
|
47459
|
+
let whitespaceEnd = 0;
|
|
46738
47460
|
// inlined: tokenizer.done()
|
|
46739
47461
|
while (!(tokenizer.typ === exports.EnumToken.EOF)) {
|
|
46740
47462
|
tokenizer.next();
|
|
46741
|
-
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
46742
47463
|
itemType = tokenizer.typ;
|
|
46743
47464
|
stats.bytesIn = tokenizer.bytesIn;
|
|
46744
47465
|
stats.tokensCount++;
|
|
47466
|
+
if (parensMatch === 0) {
|
|
47467
|
+
if (itemType === exports.EnumToken.WhitespaceTokenType) {
|
|
47468
|
+
if (tokens.length > 0) {
|
|
47469
|
+
whitespaceStart = tokenizer.sta;
|
|
47470
|
+
whitespaceEnd = tokenizer.end;
|
|
47471
|
+
}
|
|
47472
|
+
continue;
|
|
47473
|
+
}
|
|
47474
|
+
if (whitespaceStart !== -1) {
|
|
47475
|
+
if (!isStatementEnd(itemType)) {
|
|
47476
|
+
item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
|
|
47477
|
+
tokens.push(item);
|
|
47478
|
+
statement.push(item);
|
|
47479
|
+
}
|
|
47480
|
+
whitespaceStart = -1;
|
|
47481
|
+
}
|
|
47482
|
+
}
|
|
47483
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
46745
47484
|
if (isBadToken(itemType)) {
|
|
46746
47485
|
tokens.push(item);
|
|
46747
47486
|
statement.push(item);
|
|
@@ -47035,6 +47774,13 @@
|
|
|
47035
47774
|
}
|
|
47036
47775
|
}
|
|
47037
47776
|
}
|
|
47777
|
+
else if (options.mergeRules != null &&
|
|
47778
|
+
options.mergeRules !== false &&
|
|
47779
|
+
options.mergeRules !== exports.MergeRulesEnum.None &&
|
|
47780
|
+
arena.firstChild[ast] !== 0) {
|
|
47781
|
+
// the ast is not minified: the adjacent rules are merged
|
|
47782
|
+
mergeRules(arena, ast, minifyOptions);
|
|
47783
|
+
}
|
|
47038
47784
|
stats.bytesIn += stats.importedBytesIn;
|
|
47039
47785
|
// the source is no longer tokenized: the code units are not kept
|
|
47040
47786
|
arena.releaseSourceCodes(sourceIndex);
|
|
@@ -47590,6 +48336,8 @@
|
|
|
47590
48336
|
*/
|
|
47591
48337
|
async function doParse(iter, options = {}) {
|
|
47592
48338
|
if (options.signal != null) {
|
|
48339
|
+
// an aborted signal does not dispatch the abort event
|
|
48340
|
+
options.signal.throwIfAborted();
|
|
47593
48341
|
options.signal.addEventListener("abort", reject);
|
|
47594
48342
|
}
|
|
47595
48343
|
options = {
|
|
@@ -47615,6 +48363,7 @@
|
|
|
47615
48363
|
removePrefix: false,
|
|
47616
48364
|
validation: false,
|
|
47617
48365
|
lenient: true,
|
|
48366
|
+
...(options.fastMode ? fastModeOptions : null),
|
|
47618
48367
|
...options,
|
|
47619
48368
|
};
|
|
47620
48369
|
options.minifyAST ??= options.minify;
|
|
@@ -47671,13 +48420,41 @@
|
|
|
47671
48420
|
// the strings of the tokens are ranges of the content of the source
|
|
47672
48421
|
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
47673
48422
|
let itemType;
|
|
48423
|
+
// whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
|
|
48424
|
+
// is not allocated. the whitespace that follows a token is allocated when the next token is read
|
|
48425
|
+
let whitespaceStart = -1;
|
|
48426
|
+
let whitespaceEnd = 0;
|
|
47674
48427
|
// inlined: tokenizer.done()
|
|
47675
48428
|
while (!(tokenizer.typ === exports.EnumToken.EOF)) {
|
|
47676
48429
|
tokenizer.next();
|
|
47677
|
-
|
|
48430
|
+
// a stream: the token may continue in the next chunk, the chunk is read and the token is read again
|
|
48431
|
+
if (tokenizer.waiting) {
|
|
48432
|
+
await tokenizer.read();
|
|
48433
|
+
// the strings of the tokens are ranges of the content read so far
|
|
48434
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
48435
|
+
continue;
|
|
48436
|
+
}
|
|
47678
48437
|
itemType = tokenizer.typ;
|
|
47679
48438
|
stats.bytesIn = tokenizer.bytesIn;
|
|
47680
48439
|
stats.tokensCount++;
|
|
48440
|
+
if (parensMatch === 0) {
|
|
48441
|
+
if (itemType === exports.EnumToken.WhitespaceTokenType) {
|
|
48442
|
+
if (tokens.length > 0) {
|
|
48443
|
+
whitespaceStart = tokenizer.sta;
|
|
48444
|
+
whitespaceEnd = tokenizer.end;
|
|
48445
|
+
}
|
|
48446
|
+
continue;
|
|
48447
|
+
}
|
|
48448
|
+
if (whitespaceStart !== -1) {
|
|
48449
|
+
if (!isStatementEnd(itemType)) {
|
|
48450
|
+
item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
|
|
48451
|
+
tokens.push(item);
|
|
48452
|
+
statement.push(item);
|
|
48453
|
+
}
|
|
48454
|
+
whitespaceStart = -1;
|
|
48455
|
+
}
|
|
48456
|
+
}
|
|
48457
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
47681
48458
|
if (isBadToken(itemType)) {
|
|
47682
48459
|
tokens.push(item);
|
|
47683
48460
|
statement.push(item);
|
|
@@ -47739,6 +48516,11 @@
|
|
|
47739
48516
|
tokens.push(item);
|
|
47740
48517
|
do {
|
|
47741
48518
|
tokenizer.next();
|
|
48519
|
+
if (tokenizer.waiting) {
|
|
48520
|
+
await tokenizer.read();
|
|
48521
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
48522
|
+
continue;
|
|
48523
|
+
}
|
|
47742
48524
|
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
47743
48525
|
itemType = tokenizer.typ;
|
|
47744
48526
|
tokens.push(item);
|
|
@@ -48031,6 +48813,13 @@
|
|
|
48031
48813
|
}
|
|
48032
48814
|
}
|
|
48033
48815
|
}
|
|
48816
|
+
else if (options.mergeRules != null &&
|
|
48817
|
+
options.mergeRules !== false &&
|
|
48818
|
+
options.mergeRules !== exports.MergeRulesEnum.None &&
|
|
48819
|
+
arena.firstChild[ast] !== 0) {
|
|
48820
|
+
// the ast is not minified: the adjacent rules are merged
|
|
48821
|
+
mergeRules(arena, ast, minifyOptions);
|
|
48822
|
+
}
|
|
48034
48823
|
stats.bytesIn += stats.importedBytesIn;
|
|
48035
48824
|
// the source is no longer tokenized: the code units are not kept
|
|
48036
48825
|
arena.releaseSourceCodes(sourceIndex);
|
|
@@ -48994,10 +49783,7 @@
|
|
|
48994
49783
|
if (stream.length === 0 ||
|
|
48995
49784
|
arena.dataTypes[stream[0]] !== exports.EnumToken.WhitespaceTokenType ||
|
|
48996
49785
|
arena.getSpanEnd(stream[0]) - arena.getSpanStart(stream[0]) !== 1 ||
|
|
48997
|
-
|
|
48998
|
-
options.sourcesMap
|
|
48999
|
-
?.get(arena.sources[arena.getSourceId(stream[0])] ?? 0)
|
|
49000
|
-
?.content.charCodeAt(arena.getSpanStart(stream[0])) !== 0x20) {
|
|
49786
|
+
arena.sourceCodeAt(arena.getSourceId(stream[0]), arena.getSpanStart(stream[0])) !== 0x20) {
|
|
49001
49787
|
success = false;
|
|
49002
49788
|
errors.push({
|
|
49003
49789
|
action: "drop",
|
|
@@ -49405,8 +50191,7 @@
|
|
|
49405
50191
|
}
|
|
49406
50192
|
else {
|
|
49407
50193
|
context = createValidationContext(arena, stream, index);
|
|
49408
|
-
|
|
49409
|
-
range = context.peekRange((t) => arena.dataTypes[t] === exports.EnumToken.EndParensTokenType);
|
|
50194
|
+
range = context.peekRange(exports.EnumToken.EndParensTokenType);
|
|
49410
50195
|
// inlined: arena.typeOf(range.at(-1))
|
|
49411
50196
|
if (arena.dataTypes[range.at(-1)] !== exports.EnumToken.EndParensTokenType) {
|
|
49412
50197
|
errors.push({
|
|
@@ -50121,7 +50906,7 @@
|
|
|
50121
50906
|
/**
|
|
50122
50907
|
* Version number
|
|
50123
50908
|
*/
|
|
50124
|
-
const version = "2.3.
|
|
50909
|
+
const version = "2.3.2";
|
|
50125
50910
|
|
|
50126
50911
|
/**
|
|
50127
50912
|
* Load file or url
|
|
@@ -50163,7 +50948,10 @@
|
|
|
50163
50948
|
if (responseType === exports.ResponseType.JSON) {
|
|
50164
50949
|
return response.json();
|
|
50165
50950
|
}
|
|
50166
|
-
|
|
50951
|
+
// the size of the body: the parser allocates its buffers once
|
|
50952
|
+
return responseType === exports.ResponseType.ReadableStream
|
|
50953
|
+
? setStreamSize(response.body, responseSize(response))
|
|
50954
|
+
: response.text();
|
|
50167
50955
|
});
|
|
50168
50956
|
}
|
|
50169
50957
|
/**
|
|
@@ -50300,7 +51088,8 @@
|
|
|
50300
51088
|
validateSyncArguments(options);
|
|
50301
51089
|
}
|
|
50302
51090
|
// the options of the caller are not modified: they may be reused
|
|
50303
|
-
|
|
51091
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
51092
|
+
options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
|
|
50304
51093
|
const startTime = performance.now();
|
|
50305
51094
|
const parseResult = parseSyncInput(stream, options);
|
|
50306
51095
|
let mapping = null;
|
|
@@ -50447,7 +51236,8 @@
|
|
|
50447
51236
|
stream = input;
|
|
50448
51237
|
}
|
|
50449
51238
|
}
|
|
50450
|
-
|
|
51239
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
51240
|
+
options = { ...(options?.fastMode ? null : { minify: true }), removeEmpty: true, removeCharset: true, ...options };
|
|
50451
51241
|
const startTime = performance.now();
|
|
50452
51242
|
return parseInput(stream, options).then((parseResult) => {
|
|
50453
51243
|
let mapping = null;
|
|
@@ -50478,6 +51268,7 @@
|
|
|
50478
51268
|
exports.Arena = Arena;
|
|
50479
51269
|
exports.AstArena = AstArena;
|
|
50480
51270
|
exports.AstArenaNode = AstArenaNode;
|
|
51271
|
+
exports.LOC = LOC;
|
|
50481
51272
|
exports.PropertyList = PropertyList;
|
|
50482
51273
|
exports.RenderResult = RenderResult;
|
|
50483
51274
|
exports.SourceMap = SourceMap;
|