@tbela99/css-parser 1.6.9 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -1
- package/README.md +1 -0
- package/dist/index-umd-web.js +1139 -529
- package/dist/index.cjs +1138 -528
- package/dist/index.d.ts +259 -8
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +11 -2
- package/dist/src/lib/ast/clone.js +1 -1
- package/dist/src/lib/ast/expand.js +1 -1
- package/dist/src/lib/ast/features/calc.js +1 -1
- package/dist/src/lib/ast/features/if.js +1 -1
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/src/lib/ast/features/prefix.js +1 -1
- package/dist/src/lib/ast/features/shorthand.js +39 -22
- package/dist/src/lib/ast/features/transform.js +1 -1
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/find.js +26 -21
- package/dist/src/lib/ast/math/expression.js +4 -1
- package/dist/src/lib/ast/math/math.js +1 -1
- package/dist/src/lib/ast/minify.js +31 -3
- package/dist/src/lib/ast/node.js +1 -1
- package/dist/src/lib/ast/transform/compute.js +1 -1
- package/dist/src/lib/ast/transform/matrix.js +1 -1
- package/dist/src/lib/ast/transform/minify.js +1 -1
- package/dist/src/lib/ast/transform/perspective.js +1 -1
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +1 -1
- package/dist/src/lib/ast/types.js +5 -1
- package/dist/src/lib/ast/walk.js +319 -94
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +35 -1
- package/dist/src/lib/parser/declaration/map.js +2 -2
- package/dist/src/lib/parser/declaration/set.js +1 -1
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +504 -177
- package/dist/src/lib/parser/source.js +1 -1
- package/dist/src/lib/parser/tokenize.js +23 -3
- package/dist/src/lib/parser/utils/angle.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-container.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-import.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/src/lib/parser/utils/at-rule-support.js +2 -2
- package/dist/src/lib/parser/utils/at-rule-when-else.js +1 -1
- package/dist/src/lib/parser/utils/at-rule.js +1 -1
- package/dist/src/lib/parser/utils/base64.js +1 -1
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +1 -1
- package/dist/src/lib/parser/utils/eq.js +1 -1
- package/dist/src/lib/parser/utils/hash.js +1 -1
- package/dist/src/lib/parser/utils/selector.js +1 -1
- package/dist/src/lib/parser/utils/text.js +1 -1
- package/dist/src/lib/parser/utils/token.js +12 -4
- package/dist/src/lib/parser/utils/type.js +1 -1
- package/dist/src/lib/printer/render.js +6 -3
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +1 -1
- package/dist/src/lib/syntax/color/cmyk.js +1 -1
- package/dist/src/lib/syntax/color/color-mix.js +1 -1
- package/dist/src/lib/syntax/color/color.js +1 -1
- package/dist/src/lib/syntax/color/hex.js +1 -1
- package/dist/src/lib/syntax/color/hsl.js +1 -1
- package/dist/src/lib/syntax/color/hwb.js +1 -1
- package/dist/src/lib/syntax/color/lab.js +1 -1
- package/dist/src/lib/syntax/color/lch.js +1 -1
- package/dist/src/lib/syntax/color/oklab.js +1 -1
- package/dist/src/lib/syntax/color/oklch.js +1 -1
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +1 -1
- package/dist/src/lib/syntax/color/rgb.js +1 -1
- package/dist/src/lib/syntax/color/srgb.js +1 -1
- package/dist/src/lib/syntax/color/utils/color-type.js +1 -1
- package/dist/src/lib/syntax/color/utils/colorspace.js +1 -1
- package/dist/src/lib/syntax/color/utils/components.js +1 -1
- package/dist/src/lib/syntax/color/utils/distance.js +1 -1
- package/dist/src/lib/syntax/color/utils/make-color.js +1 -1
- package/dist/src/lib/syntax/color/utils/matrix.js +1 -1
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +1 -1
- package/dist/src/lib/syntax/syntax.js +1 -1
- package/dist/src/lib/validation/config.js +20 -3
- package/dist/src/lib/validation/match.js +105 -200
- package/dist/src/lib/validation/parser/parse.js +8 -3
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +1 -1
- package/dist/src/node.js +2 -1
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +1 -1
- package/dist/src/web.js +2 -1
- package/package.json +8 -7
- package/CONTRIBUTING.md +0 -119
package/dist/index.cjs
CHANGED
|
@@ -693,6 +693,10 @@ exports.EnumToken = void 0;
|
|
|
693
693
|
* CSS type token
|
|
694
694
|
*/
|
|
695
695
|
EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
|
|
696
|
+
/**
|
|
697
|
+
* user defined dimension token type
|
|
698
|
+
*/
|
|
699
|
+
EnumToken[EnumToken["UserDefinedDimensionTokenType"] = 145] = "UserDefinedDimensionTokenType";
|
|
696
700
|
/* aliases */
|
|
697
701
|
/**
|
|
698
702
|
* alias for time token type
|
|
@@ -5717,7 +5721,16 @@ var atRules = {
|
|
|
5717
5721
|
syntax: " @bottom-right-corner { <declaration-list> }"
|
|
5718
5722
|
},
|
|
5719
5723
|
"@function": {
|
|
5720
|
-
syntax: " @function <dashed-
|
|
5724
|
+
syntax: " @function <dashed-function> <function-parameter>#?) [returns <css-type>]? { <declaration-rule-list> }"
|
|
5725
|
+
},
|
|
5726
|
+
"@mixin": {
|
|
5727
|
+
syntax: " @mixin [<dashed-function> <function-parameter>#? ) | <ident-token> ]{<block-contents>}"
|
|
5728
|
+
},
|
|
5729
|
+
"@apply": {
|
|
5730
|
+
syntax: " @apply [ <dashed-ident> | <dashed-function> ] [ { <declaration-list> } ]?;"
|
|
5731
|
+
},
|
|
5732
|
+
"@contents": {
|
|
5733
|
+
syntax: " @contents [ { <declaration-list> } ]?;"
|
|
5721
5734
|
},
|
|
5722
5735
|
"@left-top": {
|
|
5723
5736
|
syntax: " @left-top { <declaration-list> }"
|
|
@@ -9683,7 +9696,6 @@ exports.WalkerEvent = void 0;
|
|
|
9683
9696
|
*/
|
|
9684
9697
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
9685
9698
|
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
9686
|
-
const maxQueueLength = 25000;
|
|
9687
9699
|
/**
|
|
9688
9700
|
* Walk ast nodes
|
|
9689
9701
|
* @param node initial node
|
|
@@ -9766,7 +9778,6 @@ function* walk(node, filter, reverse) {
|
|
|
9766
9778
|
let isNumeric = false;
|
|
9767
9779
|
let children = true;
|
|
9768
9780
|
let attributes = false;
|
|
9769
|
-
let i = 0;
|
|
9770
9781
|
if (options != null && typeof options == "object") {
|
|
9771
9782
|
filter = options.filter;
|
|
9772
9783
|
reverse = options.reverse;
|
|
@@ -9786,12 +9797,11 @@ function* walk(node, filter, reverse) {
|
|
|
9786
9797
|
}
|
|
9787
9798
|
},
|
|
9788
9799
|
};
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
let option = null;
|
|
9800
|
+
let option = null;
|
|
9801
|
+
let source = [];
|
|
9802
|
+
while (parents.length > 0) {
|
|
9803
|
+
node = parents.pop();
|
|
9804
|
+
// enter node
|
|
9795
9805
|
if (filter != null) {
|
|
9796
9806
|
// @ts-expect-error
|
|
9797
9807
|
option = filter(node);
|
|
@@ -9812,36 +9822,175 @@ function* walk(node, filter, reverse) {
|
|
|
9812
9822
|
yield result;
|
|
9813
9823
|
}
|
|
9814
9824
|
if (attributes) {
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9825
|
+
source.length = 0;
|
|
9826
|
+
if (Array.isArray(node[TOKENS])) {
|
|
9827
|
+
if (reverse) {
|
|
9828
|
+
for (const token of node[TOKENS]) {
|
|
9829
|
+
parents.push(token);
|
|
9830
|
+
token[PARENT] = node;
|
|
9831
|
+
}
|
|
9832
|
+
}
|
|
9833
|
+
else {
|
|
9834
|
+
for (let i = node[TOKENS].length - 1; i >= 0; i--) {
|
|
9835
|
+
parents.push(node[TOKENS][i]);
|
|
9836
|
+
node[TOKENS][i][PARENT] = node;
|
|
9821
9837
|
}
|
|
9822
9838
|
}
|
|
9823
|
-
// @ts-expect-error
|
|
9824
9839
|
}
|
|
9825
|
-
else if (
|
|
9826
|
-
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9840
|
+
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
9841
|
+
if (reverse) {
|
|
9842
|
+
for (const token of node.val) {
|
|
9843
|
+
parents.push(token);
|
|
9844
|
+
token[PARENT] = node;
|
|
9845
|
+
}
|
|
9846
|
+
}
|
|
9847
|
+
else {
|
|
9848
|
+
for (let i = node.val.length - 1; i >= 0; i--) {
|
|
9849
|
+
parents.push(node.val[i]);
|
|
9850
|
+
node.val[i][PARENT] = node;
|
|
9851
|
+
}
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
else {
|
|
9855
|
+
source.length = 0;
|
|
9856
|
+
switch (node.typ) {
|
|
9857
|
+
case exports.EnumToken.BinaryExpressionTokenType:
|
|
9858
|
+
case exports.EnumToken.IfElseConditionTokenType:
|
|
9859
|
+
source.push(node.l);
|
|
9860
|
+
node.l[PARENT] = node;
|
|
9861
|
+
source.push(node.r);
|
|
9862
|
+
node.r[PARENT] = node;
|
|
9863
|
+
break;
|
|
9864
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
9865
|
+
source.push(node.l);
|
|
9866
|
+
node.l[PARENT] = node;
|
|
9867
|
+
source.push(node.op);
|
|
9868
|
+
node.op[PARENT] = node;
|
|
9869
|
+
source.push(node.r);
|
|
9870
|
+
node.r[PARENT] = node;
|
|
9871
|
+
break;
|
|
9872
|
+
case exports.EnumToken.SupportsQueryConditionTokenType:
|
|
9873
|
+
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
9874
|
+
for (let i = 0; i < node.l.length; i++) {
|
|
9875
|
+
const element = node.l[i];
|
|
9876
|
+
source.push(element);
|
|
9877
|
+
element[PARENT] = node;
|
|
9878
|
+
}
|
|
9879
|
+
source.push(node.op);
|
|
9880
|
+
node.op[PARENT] = node;
|
|
9881
|
+
for (let i = 0; i < node.r.length; i++) {
|
|
9882
|
+
const element = node.r[i];
|
|
9883
|
+
source.push(element);
|
|
9884
|
+
element[PARENT] = node;
|
|
9885
|
+
}
|
|
9886
|
+
break;
|
|
9887
|
+
case exports.EnumToken.WhenElseQueryConditionTokenType:
|
|
9888
|
+
source.push(node.l);
|
|
9889
|
+
node.l[PARENT] = node;
|
|
9890
|
+
for (let i = 0; i < node.r.length; i++) {
|
|
9891
|
+
const element = node.r[i];
|
|
9892
|
+
source.push(element);
|
|
9893
|
+
element[PARENT] = node;
|
|
9894
|
+
}
|
|
9895
|
+
break;
|
|
9896
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
9897
|
+
for (let i = 0; i < node.l.length; i++) {
|
|
9898
|
+
const element = node.l[i];
|
|
9899
|
+
source.push(element);
|
|
9900
|
+
element[PARENT] = node;
|
|
9901
|
+
}
|
|
9902
|
+
if (node.r != null) {
|
|
9903
|
+
source.push(node.r);
|
|
9904
|
+
node.r[PARENT] = node;
|
|
9905
|
+
}
|
|
9906
|
+
break;
|
|
9907
|
+
case exports.EnumToken.IfConditionTokenType:
|
|
9908
|
+
for (let i = 0; i < node.l.length; i++) {
|
|
9909
|
+
const element = node.l[i];
|
|
9910
|
+
source.push(element);
|
|
9911
|
+
element[PARENT] = node;
|
|
9912
|
+
}
|
|
9913
|
+
for (let i = 0; i < node.r.length; i++) {
|
|
9914
|
+
const element = node.r[i];
|
|
9915
|
+
source.push(element);
|
|
9916
|
+
element[PARENT] = node;
|
|
9917
|
+
}
|
|
9918
|
+
break;
|
|
9919
|
+
case exports.EnumToken.ContainerStyleRangeTokenType:
|
|
9920
|
+
for (let i = 0; i < node.l.length; i++) {
|
|
9921
|
+
const element = node.l[i];
|
|
9922
|
+
source.push(element);
|
|
9923
|
+
element[PARENT] = node;
|
|
9924
|
+
}
|
|
9925
|
+
for (let i = 0; i < node.op.length; i++) {
|
|
9926
|
+
const element = node.op[i];
|
|
9927
|
+
source.push(element);
|
|
9928
|
+
element[PARENT] = node;
|
|
9929
|
+
}
|
|
9930
|
+
for (let i = 0; i < node.r.length; i++) {
|
|
9931
|
+
const element = node.r[i];
|
|
9932
|
+
source.push(element);
|
|
9933
|
+
element[PARENT] = node;
|
|
9934
|
+
}
|
|
9935
|
+
break;
|
|
9936
|
+
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
9937
|
+
for (let i = 0; i < node.l.length; i++) {
|
|
9938
|
+
const element = node.l[i];
|
|
9939
|
+
source.push(element);
|
|
9940
|
+
element[PARENT] = node;
|
|
9941
|
+
}
|
|
9942
|
+
source.push(node.op1);
|
|
9943
|
+
node.op1[PARENT] = node;
|
|
9944
|
+
for (let i = 0; i < node.val.length; i++) {
|
|
9945
|
+
const element = node.val[i];
|
|
9946
|
+
source.push(element);
|
|
9947
|
+
element[PARENT] = node;
|
|
9948
|
+
}
|
|
9949
|
+
source.push(node.op2);
|
|
9950
|
+
node.op2[PARENT] = node;
|
|
9951
|
+
for (let i = 0; i < node.r.length; i++) {
|
|
9952
|
+
const element = node.r[i];
|
|
9953
|
+
source.push(element);
|
|
9954
|
+
element[PARENT] = node;
|
|
9955
|
+
}
|
|
9956
|
+
break;
|
|
9957
|
+
}
|
|
9958
|
+
if (source.length > 0) {
|
|
9959
|
+
if (reverse) {
|
|
9960
|
+
for (let i = 0; i < source.length; i++) {
|
|
9961
|
+
parents.push(source[i]);
|
|
9962
|
+
source[i][PARENT] = node;
|
|
9963
|
+
}
|
|
9964
|
+
}
|
|
9965
|
+
else {
|
|
9966
|
+
for (let i = source.length - 1; i >= 0; i--) {
|
|
9967
|
+
parents.push(source[i]);
|
|
9968
|
+
source[i][PARENT] = node;
|
|
9969
|
+
}
|
|
9830
9970
|
}
|
|
9831
9971
|
}
|
|
9832
|
-
// @ts-expect-error
|
|
9833
|
-
parents.splice(i, 0, ...(reverse ? node.val.toReversed() : node.val));
|
|
9834
9972
|
}
|
|
9835
9973
|
}
|
|
9836
9974
|
if (children &&
|
|
9837
9975
|
// @ts-expect-error
|
|
9838
9976
|
node["chi"] != null &&
|
|
9839
9977
|
(!isNumeric || (option & exports.WalkerOptionEnum.IgnoreChildren) === 0)) {
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9844
|
-
|
|
9978
|
+
if (reverse) {
|
|
9979
|
+
// @ts-expect-error
|
|
9980
|
+
for (let i = 0; i < node.chi.length; i++) {
|
|
9981
|
+
// @ts-expect-error
|
|
9982
|
+
parents.push(node.chi[i]);
|
|
9983
|
+
// @ts-expect-error
|
|
9984
|
+
node.chi[i][PARENT] = node;
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
else {
|
|
9988
|
+
// @ts-expect-error
|
|
9989
|
+
for (let i = node.chi.length - 1; i >= 0; i--) {
|
|
9990
|
+
// @ts-expect-error
|
|
9991
|
+
parents.push(node.chi[i]);
|
|
9992
|
+
// @ts-expect-error
|
|
9993
|
+
node.chi[i][PARENT] = node;
|
|
9845
9994
|
}
|
|
9846
9995
|
}
|
|
9847
9996
|
}
|
|
@@ -9894,9 +10043,19 @@ function* walk(node, filter, reverse) {
|
|
|
9894
10043
|
* // [ "Iden", "from" ]
|
|
9895
10044
|
* ```
|
|
9896
10045
|
*/
|
|
9897
|
-
function* walkValues(
|
|
9898
|
-
const
|
|
10046
|
+
function* walkValues(tokens, root = null, filter, reverse) {
|
|
10047
|
+
const nodes = [];
|
|
9899
10048
|
let previous = null;
|
|
10049
|
+
if (reverse) {
|
|
10050
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
10051
|
+
nodes.push(tokens[i]);
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
else {
|
|
10055
|
+
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
10056
|
+
nodes.push(tokens[i]);
|
|
10057
|
+
}
|
|
10058
|
+
}
|
|
9900
10059
|
if (filter != null && typeof filter == "function") {
|
|
9901
10060
|
filter = {
|
|
9902
10061
|
event: exports.WalkerEvent.Enter,
|
|
@@ -9912,7 +10071,7 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
9912
10071
|
let value;
|
|
9913
10072
|
let option;
|
|
9914
10073
|
let node;
|
|
9915
|
-
|
|
10074
|
+
const values = [];
|
|
9916
10075
|
const eventType = filter.event ?? exports.WalkerEvent.Enter;
|
|
9917
10076
|
// @ts-ignore
|
|
9918
10077
|
const result = {
|
|
@@ -9931,13 +10090,9 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
9931
10090
|
}
|
|
9932
10091
|
},
|
|
9933
10092
|
};
|
|
9934
|
-
while (
|
|
9935
|
-
value =
|
|
10093
|
+
while (nodes.length > 0) {
|
|
10094
|
+
value = nodes.pop();
|
|
9936
10095
|
option = null;
|
|
9937
|
-
if (i > maxQueueLength) {
|
|
9938
|
-
stack.splice(0, maxQueueLength);
|
|
9939
|
-
i -= maxQueueLength;
|
|
9940
|
-
}
|
|
9941
10096
|
if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
|
|
9942
10097
|
const isValid = filter.type == null ||
|
|
9943
10098
|
value.typ == filter.type ||
|
|
@@ -9965,10 +10120,16 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
9965
10120
|
//
|
|
9966
10121
|
if (option != null && typeof option == "object" && ("typ" in option || Array.isArray(option))) {
|
|
9967
10122
|
const op = Array.isArray(option) ? option : [option];
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
10123
|
+
if (reverse) {
|
|
10124
|
+
for (let i = 0; i < op.length; i++) {
|
|
10125
|
+
nodes.push(op[i]);
|
|
10126
|
+
op[i][PARENT] = value;
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
else {
|
|
10130
|
+
for (let i = op.length - 1; i >= 0; i--) {
|
|
10131
|
+
nodes.push(op[i]);
|
|
10132
|
+
op[i][PARENT] = value;
|
|
9972
10133
|
}
|
|
9973
10134
|
}
|
|
9974
10135
|
}
|
|
@@ -9977,70 +10138,140 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
9977
10138
|
result.value = value;
|
|
9978
10139
|
result.parent = value[PARENT] ?? root;
|
|
9979
10140
|
result.previousValue = previous;
|
|
9980
|
-
result.nextValue =
|
|
10141
|
+
result.nextValue = nodes[nodes.length - 1] ?? null;
|
|
9981
10142
|
yield result;
|
|
9982
10143
|
if (!isNumeric || (option & exports.WalkerOptionEnum.IgnoreChildren) === 0) {
|
|
9983
|
-
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
|
|
9988
|
-
|
|
9989
|
-
|
|
9990
|
-
stack.unshift(child);
|
|
10144
|
+
//
|
|
10145
|
+
if (value.chi != null) {
|
|
10146
|
+
const source = value.chi;
|
|
10147
|
+
if (reverse) {
|
|
10148
|
+
for (let i = 0; i < source.length; i++) {
|
|
10149
|
+
nodes.push(source[i]);
|
|
10150
|
+
source[i][PARENT] = value;
|
|
9991
10151
|
}
|
|
9992
|
-
|
|
9993
|
-
|
|
10152
|
+
}
|
|
10153
|
+
else {
|
|
10154
|
+
for (let i = source.length - 1; i >= 0; i--) {
|
|
10155
|
+
nodes.push(source[i]);
|
|
10156
|
+
source[i][PARENT] = value;
|
|
9994
10157
|
}
|
|
9995
10158
|
}
|
|
9996
10159
|
}
|
|
9997
10160
|
else {
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10003
|
-
if (value.l[PARENT] != value) {
|
|
10004
|
-
// @ts-expect-error
|
|
10161
|
+
values.length = 0;
|
|
10162
|
+
switch (value.typ) {
|
|
10163
|
+
case exports.EnumToken.BinaryExpressionTokenType:
|
|
10164
|
+
case exports.EnumToken.IfElseConditionTokenType:
|
|
10165
|
+
values.push(value.l);
|
|
10005
10166
|
value.l[PARENT] = value;
|
|
10006
|
-
|
|
10007
|
-
|
|
10008
|
-
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
// @ts-expect-error
|
|
10167
|
+
values.push(value.r);
|
|
10168
|
+
value.r[PARENT] = value;
|
|
10169
|
+
break;
|
|
10170
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
10171
|
+
values.push(value.l);
|
|
10172
|
+
value.l[PARENT] = value;
|
|
10173
|
+
values.push(value.op);
|
|
10014
10174
|
value.op[PARENT] = value;
|
|
10015
|
-
}
|
|
10016
|
-
}
|
|
10017
|
-
if ("r" in value && value.r != null) {
|
|
10018
|
-
if (Array.isArray(value.r)) {
|
|
10019
|
-
for (const r of value.r) {
|
|
10020
|
-
//
|
|
10021
|
-
values.push(r);
|
|
10022
|
-
if (r[PARENT] != value) {
|
|
10023
|
-
//
|
|
10024
|
-
r[PARENT] = value;
|
|
10025
|
-
}
|
|
10026
|
-
}
|
|
10027
|
-
}
|
|
10028
|
-
else {
|
|
10029
|
-
//
|
|
10030
10175
|
values.push(value.r);
|
|
10031
|
-
|
|
10032
|
-
|
|
10176
|
+
value.r[PARENT] = value;
|
|
10177
|
+
break;
|
|
10178
|
+
case exports.EnumToken.SupportsQueryConditionTokenType:
|
|
10179
|
+
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
10180
|
+
for (let i = 0; i < value.l.length; i++) {
|
|
10181
|
+
const element = value.l[i];
|
|
10182
|
+
values.push(element);
|
|
10183
|
+
element[PARENT] = value;
|
|
10184
|
+
}
|
|
10185
|
+
values.push(value.op);
|
|
10186
|
+
value.op[PARENT] = value;
|
|
10187
|
+
for (let i = 0; i < value.r.length; i++) {
|
|
10188
|
+
const element = value.r[i];
|
|
10189
|
+
values.push(element);
|
|
10190
|
+
element[PARENT] = value;
|
|
10191
|
+
}
|
|
10192
|
+
break;
|
|
10193
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
10194
|
+
for (let i = 0; i < value.l.length; i++) {
|
|
10195
|
+
const element = value.l[i];
|
|
10196
|
+
values.push(element);
|
|
10197
|
+
element[PARENT] = value;
|
|
10198
|
+
}
|
|
10199
|
+
if (value.r != null) {
|
|
10200
|
+
values.push(value.r);
|
|
10033
10201
|
value.r[PARENT] = value;
|
|
10034
10202
|
}
|
|
10035
|
-
|
|
10203
|
+
break;
|
|
10204
|
+
case exports.EnumToken.WhenElseQueryConditionTokenType:
|
|
10205
|
+
values.push(value.l);
|
|
10206
|
+
value.l[PARENT] = value;
|
|
10207
|
+
for (let i = 0; i < value.r.length; i++) {
|
|
10208
|
+
const element = value.r[i];
|
|
10209
|
+
values.push(element);
|
|
10210
|
+
element[PARENT] = value;
|
|
10211
|
+
}
|
|
10212
|
+
break;
|
|
10213
|
+
case exports.EnumToken.IfConditionTokenType:
|
|
10214
|
+
for (let i = 0; i < value.l.length; i++) {
|
|
10215
|
+
const element = value.l[i];
|
|
10216
|
+
values.push(element);
|
|
10217
|
+
element[PARENT] = value;
|
|
10218
|
+
}
|
|
10219
|
+
for (let i = 0; i < value.r.length; i++) {
|
|
10220
|
+
const element = value.r[i];
|
|
10221
|
+
values.push(element);
|
|
10222
|
+
element[PARENT] = value;
|
|
10223
|
+
}
|
|
10224
|
+
break;
|
|
10225
|
+
case exports.EnumToken.ContainerStyleRangeTokenType:
|
|
10226
|
+
for (let i = 0; i < value.l.length; i++) {
|
|
10227
|
+
const element = value.l[i];
|
|
10228
|
+
values.push(element);
|
|
10229
|
+
element[PARENT] = value;
|
|
10230
|
+
}
|
|
10231
|
+
for (let i = 0; i < value.op.length; i++) {
|
|
10232
|
+
const element = value.op[i];
|
|
10233
|
+
values.push(element);
|
|
10234
|
+
element[PARENT] = value;
|
|
10235
|
+
}
|
|
10236
|
+
for (let i = 0; i < value.r.length; i++) {
|
|
10237
|
+
const element = value.r[i];
|
|
10238
|
+
values.push(element);
|
|
10239
|
+
element[PARENT] = value;
|
|
10240
|
+
}
|
|
10241
|
+
break;
|
|
10242
|
+
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
10243
|
+
for (let i = 0; i < value.l.length; i++) {
|
|
10244
|
+
const element = value.l[i];
|
|
10245
|
+
values.push(element);
|
|
10246
|
+
element[PARENT] = value;
|
|
10247
|
+
}
|
|
10248
|
+
values.push(value.op1);
|
|
10249
|
+
value.op1[PARENT] = value;
|
|
10250
|
+
for (let i = 0; i < value.val.length; i++) {
|
|
10251
|
+
const element = value.val[i];
|
|
10252
|
+
values.push(element);
|
|
10253
|
+
element[PARENT] = value;
|
|
10254
|
+
}
|
|
10255
|
+
values.push(value.op2);
|
|
10256
|
+
value.op2[PARENT] = value;
|
|
10257
|
+
for (let i = 0; i < value.r.length; i++) {
|
|
10258
|
+
const element = value.r[i];
|
|
10259
|
+
values.push(element);
|
|
10260
|
+
element[PARENT] = value;
|
|
10261
|
+
}
|
|
10262
|
+
break;
|
|
10036
10263
|
}
|
|
10037
10264
|
if (values.length > 0) {
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10265
|
+
if (reverse) {
|
|
10266
|
+
for (let i = 0; i < values.length; i++) {
|
|
10267
|
+
nodes.push(values[i]);
|
|
10268
|
+
values[i][PARENT] = value;
|
|
10041
10269
|
}
|
|
10042
|
-
|
|
10043
|
-
|
|
10270
|
+
}
|
|
10271
|
+
else {
|
|
10272
|
+
for (let i = values.length - 1; i >= 0; i--) {
|
|
10273
|
+
nodes.push(values[i]);
|
|
10274
|
+
values[i][PARENT] = value;
|
|
10044
10275
|
}
|
|
10045
10276
|
}
|
|
10046
10277
|
}
|
|
@@ -10057,10 +10288,16 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
10057
10288
|
// @ts-ignore
|
|
10058
10289
|
if (option != null && ("typ" in option || Array.isArray(option))) {
|
|
10059
10290
|
const op = Array.isArray(option) ? option : [option];
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10291
|
+
if (reverse) {
|
|
10292
|
+
for (let i = 0; i < op.length; i++) {
|
|
10293
|
+
nodes.push(op[i]);
|
|
10294
|
+
op[i][PARENT] = value;
|
|
10295
|
+
}
|
|
10296
|
+
}
|
|
10297
|
+
else {
|
|
10298
|
+
for (let i = op.length - 1; i >= 0; i--) {
|
|
10299
|
+
nodes.push(op[i]);
|
|
10300
|
+
op[i][PARENT] = value;
|
|
10064
10301
|
}
|
|
10065
10302
|
}
|
|
10066
10303
|
}
|
|
@@ -10306,6 +10543,9 @@ function evaluate(tokens) {
|
|
|
10306
10543
|
}
|
|
10307
10544
|
}
|
|
10308
10545
|
if (acc.length > 0 && curr[0] != exports.EnumToken.ListToken) {
|
|
10546
|
+
if ("val" in token && +token.val == 0) {
|
|
10547
|
+
return acc;
|
|
10548
|
+
}
|
|
10309
10549
|
acc.push({
|
|
10310
10550
|
typ: exports.EnumToken.Add,
|
|
10311
10551
|
[LOCSRCID]: token[LOCSRCID],
|
|
@@ -11766,6 +12006,11 @@ function* tokenizeSyntax(syntax, position = {
|
|
|
11766
12006
|
[LOC]: { ...position },
|
|
11767
12007
|
};
|
|
11768
12008
|
}
|
|
12009
|
+
/**
|
|
12010
|
+
* parse mdn data syntax
|
|
12011
|
+
* @param syntax
|
|
12012
|
+
* @returns
|
|
12013
|
+
*/
|
|
11769
12014
|
function parseSyntax(syntax) {
|
|
11770
12015
|
const stack = [];
|
|
11771
12016
|
let tokens = [];
|
|
@@ -12309,8 +12554,8 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
12309
12554
|
}
|
|
12310
12555
|
}
|
|
12311
12556
|
}
|
|
12312
|
-
|
|
12313
|
-
|
|
12557
|
+
let block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
|
|
12558
|
+
let prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
|
|
12314
12559
|
let propertyDescriptors = null;
|
|
12315
12560
|
// @ts-expect-error
|
|
12316
12561
|
if (node.descriptors != null) {
|
|
@@ -12321,7 +12566,24 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
12321
12566
|
propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
|
|
12322
12567
|
}
|
|
12323
12568
|
}
|
|
12569
|
+
let optionalBody = false;
|
|
12570
|
+
if (block == null || block.length === 0) {
|
|
12571
|
+
let k = prelude.length - 1;
|
|
12572
|
+
if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
|
|
12573
|
+
k--;
|
|
12574
|
+
}
|
|
12575
|
+
if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
|
|
12576
|
+
if (prelude[k].chi[0].typ ===
|
|
12577
|
+
ValidationTokenEnum.OpenCurlyBrace &&
|
|
12578
|
+
prelude[k].chi.at(-1).typ ===
|
|
12579
|
+
ValidationTokenEnum.CloseCurlyBrace) {
|
|
12580
|
+
block = prelude[k].chi.slice(1, -1);
|
|
12581
|
+
optionalBody = prelude[k].isOptional ?? false;
|
|
12582
|
+
}
|
|
12583
|
+
}
|
|
12584
|
+
}
|
|
12324
12585
|
return {
|
|
12586
|
+
optionalBody,
|
|
12325
12587
|
acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
|
|
12326
12588
|
acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
|
|
12327
12589
|
node.syntax.includes("<stylesheet>"),
|
|
@@ -12409,15 +12671,6 @@ function trimArray(tokens) {
|
|
|
12409
12671
|
}
|
|
12410
12672
|
return tokens;
|
|
12411
12673
|
}
|
|
12412
|
-
/**
|
|
12413
|
-
* is a media feature
|
|
12414
|
-
* @param featureName
|
|
12415
|
-
* @returns
|
|
12416
|
-
*/
|
|
12417
|
-
// export function isMFName(featureName: string): boolean {
|
|
12418
|
-
// // @ts-expect-error
|
|
12419
|
-
// return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
|
|
12420
|
-
// }
|
|
12421
12674
|
/**
|
|
12422
12675
|
*
|
|
12423
12676
|
* @param featureName
|
|
@@ -12938,9 +13191,6 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
12938
13191
|
case exports.EnumToken.NumberTokenType:
|
|
12939
13192
|
case exports.EnumToken.LiteralTokenType:
|
|
12940
13193
|
case exports.EnumToken.DimensionTokenType:
|
|
12941
|
-
// if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
12942
|
-
// stack.pop();
|
|
12943
|
-
// }
|
|
12944
13194
|
if (stack.at(-1)?.typ === exports.EnumToken.PseudoClassFunctionTokenDefType) {
|
|
12945
13195
|
break;
|
|
12946
13196
|
}
|
|
@@ -13209,43 +13459,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
13209
13459
|
continue;
|
|
13210
13460
|
}
|
|
13211
13461
|
}
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
|
|
13216
|
-
syntaxes[i + 2]?.typ == null) {
|
|
13217
|
-
if (!isOptional) {
|
|
13218
|
-
return {
|
|
13219
|
-
success: false,
|
|
13220
|
-
errors: [
|
|
13221
|
-
{
|
|
13222
|
-
action: "drop",
|
|
13223
|
-
message: "could not match syntax",
|
|
13224
|
-
node: token,
|
|
13225
|
-
syntax: syntaxes[i],
|
|
13226
|
-
},
|
|
13227
|
-
],
|
|
13228
|
-
syntaxToken: syntaxes[i],
|
|
13229
|
-
valid: true,
|
|
13230
|
-
context,
|
|
13231
|
-
token: null,
|
|
13232
|
-
};
|
|
13233
|
-
}
|
|
13234
|
-
break;
|
|
13235
|
-
}
|
|
13236
|
-
const range = trimArray(context.peekRange());
|
|
13237
|
-
context.next();
|
|
13238
|
-
i++;
|
|
13239
|
-
result = matchSyntax([syntaxes[i + 1]], createValidationContext(range.slice(1, -1)), options);
|
|
13240
|
-
if (result.success) {
|
|
13241
|
-
context.update(range.at(-1));
|
|
13242
|
-
i += 2;
|
|
13243
|
-
}
|
|
13244
|
-
return result;
|
|
13245
|
-
}
|
|
13246
|
-
if (tokensfuncDefMap.has(token.typ) &&
|
|
13247
|
-
// @ts-ignore
|
|
13248
|
-
token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
|
|
13462
|
+
if (
|
|
13463
|
+
// @ts-ignore
|
|
13464
|
+
token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
|
|
13249
13465
|
const range = trimArray(context.peekRange());
|
|
13250
13466
|
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(range.slice(1, -1)), options);
|
|
13251
13467
|
if (result.success) {
|
|
@@ -13270,6 +13486,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
13270
13486
|
context.update(result.context.current());
|
|
13271
13487
|
continue;
|
|
13272
13488
|
}
|
|
13489
|
+
if (isOptional) {
|
|
13490
|
+
continue;
|
|
13491
|
+
}
|
|
13273
13492
|
return result;
|
|
13274
13493
|
}
|
|
13275
13494
|
if (syntaxes[i].isList) {
|
|
@@ -13290,6 +13509,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
13290
13509
|
context.update(result.context.current());
|
|
13291
13510
|
continue;
|
|
13292
13511
|
}
|
|
13512
|
+
if (isOptional) {
|
|
13513
|
+
continue;
|
|
13514
|
+
}
|
|
13293
13515
|
return {
|
|
13294
13516
|
success: false,
|
|
13295
13517
|
valid: true,
|
|
@@ -13314,6 +13536,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
13314
13536
|
context.update(result.context.current());
|
|
13315
13537
|
continue;
|
|
13316
13538
|
}
|
|
13539
|
+
if (isOptional) {
|
|
13540
|
+
continue;
|
|
13541
|
+
}
|
|
13317
13542
|
return {
|
|
13318
13543
|
success: false,
|
|
13319
13544
|
valid: true,
|
|
@@ -13718,6 +13943,20 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
13718
13943
|
syntaxToken: syntaxes[i],
|
|
13719
13944
|
errors: [],
|
|
13720
13945
|
};
|
|
13946
|
+
case ValidationTokenEnum.OpenCurlyBrace:
|
|
13947
|
+
if (token.typ === exports.EnumToken.BlockStartTokenType) {
|
|
13948
|
+
options.visited.get(token).delete(syntaxes[i]);
|
|
13949
|
+
context.next();
|
|
13950
|
+
break;
|
|
13951
|
+
}
|
|
13952
|
+
return {
|
|
13953
|
+
success: false,
|
|
13954
|
+
valid: true,
|
|
13955
|
+
token,
|
|
13956
|
+
context,
|
|
13957
|
+
syntaxToken: syntaxes[i],
|
|
13958
|
+
errors: [],
|
|
13959
|
+
};
|
|
13721
13960
|
case ValidationTokenEnum.CloseParenthesis:
|
|
13722
13961
|
if (token.typ === exports.EnumToken.EndParensTokenType) {
|
|
13723
13962
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -13919,6 +14158,7 @@ function matchProperty(property, context, options) {
|
|
|
13919
14158
|
};
|
|
13920
14159
|
}
|
|
13921
14160
|
switch (property.val) {
|
|
14161
|
+
case "function-parameter":
|
|
13922
14162
|
case "declaration-value":
|
|
13923
14163
|
{
|
|
13924
14164
|
// consume a declaration value
|
|
@@ -13928,18 +14168,43 @@ function matchProperty(property, context, options) {
|
|
|
13928
14168
|
// if semicolon or end curly brace is encountered, stop
|
|
13929
14169
|
let expectToken = true;
|
|
13930
14170
|
let token;
|
|
14171
|
+
const stack = [];
|
|
13931
14172
|
token = context.peek();
|
|
13932
|
-
|
|
13933
|
-
|
|
13934
|
-
|
|
13935
|
-
|
|
13936
|
-
|
|
13937
|
-
|
|
13938
|
-
expectToken
|
|
14173
|
+
if (token != null) {
|
|
14174
|
+
success = false;
|
|
14175
|
+
while ((token = context.peek()) != null) {
|
|
14176
|
+
if (token.typ == exports.EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
|
|
14177
|
+
stack.push(token);
|
|
14178
|
+
}
|
|
14179
|
+
if (expectToken) {
|
|
14180
|
+
expectToken = false;
|
|
14181
|
+
}
|
|
14182
|
+
if (token.typ == exports.EnumToken.CommaTokenType) {
|
|
14183
|
+
expectToken = true;
|
|
14184
|
+
}
|
|
14185
|
+
if (token.typ == exports.EnumToken.EndParensTokenType) {
|
|
14186
|
+
if (stack.length > 0) {
|
|
14187
|
+
stack.pop();
|
|
14188
|
+
}
|
|
14189
|
+
else {
|
|
14190
|
+
expectToken = false;
|
|
14191
|
+
break;
|
|
14192
|
+
}
|
|
14193
|
+
}
|
|
14194
|
+
context.next();
|
|
13939
14195
|
}
|
|
13940
|
-
context.next();
|
|
13941
14196
|
}
|
|
13942
14197
|
success = !expectToken;
|
|
14198
|
+
if (success) {
|
|
14199
|
+
return {
|
|
14200
|
+
success,
|
|
14201
|
+
valid: true,
|
|
14202
|
+
token: null,
|
|
14203
|
+
context,
|
|
14204
|
+
syntaxToken: property,
|
|
14205
|
+
errors: [],
|
|
14206
|
+
};
|
|
14207
|
+
}
|
|
13943
14208
|
}
|
|
13944
14209
|
break;
|
|
13945
14210
|
case "calc-sum": {
|
|
@@ -13972,9 +14237,6 @@ function matchProperty(property, context, options) {
|
|
|
13972
14237
|
}
|
|
13973
14238
|
break;
|
|
13974
14239
|
}
|
|
13975
|
-
// case "at-keyword-token":
|
|
13976
|
-
// success = context.peek()?.typ === EnumToken.AtRuleTokenType;
|
|
13977
|
-
// break;
|
|
13978
14240
|
case "an+b":
|
|
13979
14241
|
{
|
|
13980
14242
|
let token = context.peek();
|
|
@@ -14039,9 +14301,6 @@ function matchProperty(property, context, options) {
|
|
|
14039
14301
|
Object.assign(token, { typ: exports.EnumToken.Add });
|
|
14040
14302
|
}
|
|
14041
14303
|
token = context.peek(2);
|
|
14042
|
-
// if (token == null) {
|
|
14043
|
-
// break;
|
|
14044
|
-
// }
|
|
14045
14304
|
if (token?.typ === exports.EnumToken.NumberTokenType &&
|
|
14046
14305
|
Number.isInteger(token.val) &&
|
|
14047
14306
|
!token.toString().includes(".") &&
|
|
@@ -14149,9 +14408,6 @@ function matchProperty(property, context, options) {
|
|
|
14149
14408
|
break;
|
|
14150
14409
|
case "dimension": {
|
|
14151
14410
|
const token = context.peek();
|
|
14152
|
-
// if (token == null) {
|
|
14153
|
-
// break;
|
|
14154
|
-
// }
|
|
14155
14411
|
success =
|
|
14156
14412
|
token?.typ == exports.EnumToken.DimensionTokenType ||
|
|
14157
14413
|
token?.typ == exports.EnumToken.AngleTokenType ||
|
|
@@ -14160,25 +14416,20 @@ function matchProperty(property, context, options) {
|
|
|
14160
14416
|
token?.typ == exports.EnumToken.ResolutionTokenType ||
|
|
14161
14417
|
token?.typ == exports.EnumToken.TimeTokenType ||
|
|
14162
14418
|
token?.typ == exports.EnumToken.FrequencyTokenType ||
|
|
14419
|
+
token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
|
|
14163
14420
|
token?.typ == exports.EnumToken.FlexTokenType;
|
|
14164
14421
|
break;
|
|
14165
14422
|
}
|
|
14166
14423
|
case "angle":
|
|
14167
14424
|
{
|
|
14168
14425
|
const token = context.peek();
|
|
14169
|
-
|
|
14170
|
-
// break;
|
|
14171
|
-
// }
|
|
14172
|
-
success = token?.typ === exports.EnumToken.AngleTokenType;
|
|
14426
|
+
success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.UserDefinedDimensionTokenType;
|
|
14173
14427
|
}
|
|
14174
14428
|
break;
|
|
14175
14429
|
case "angle-percentage":
|
|
14176
14430
|
{
|
|
14177
14431
|
const token = context.peek();
|
|
14178
|
-
|
|
14179
|
-
// break;
|
|
14180
|
-
// }
|
|
14181
|
-
success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.PercentageTokenType;
|
|
14432
|
+
success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.UserDefinedDimensionTokenType || token?.typ === exports.EnumToken.PercentageTokenType;
|
|
14182
14433
|
}
|
|
14183
14434
|
break;
|
|
14184
14435
|
case "percentage":
|
|
@@ -14193,25 +14444,21 @@ function matchProperty(property, context, options) {
|
|
|
14193
14444
|
case "length-percentage":
|
|
14194
14445
|
{
|
|
14195
14446
|
const token = context.peek();
|
|
14196
|
-
// if (token == null) {
|
|
14197
|
-
// break;
|
|
14198
|
-
// }
|
|
14199
14447
|
success =
|
|
14200
14448
|
token?.typ == exports.EnumToken.PercentageTokenType ||
|
|
14201
14449
|
token?.typ == exports.EnumToken.LengthTokenType ||
|
|
14450
|
+
token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
|
|
14202
14451
|
(token?.typ == exports.EnumToken.NumberTokenType && token?.val === 0);
|
|
14203
14452
|
}
|
|
14204
14453
|
break;
|
|
14205
14454
|
case "flex":
|
|
14206
|
-
success = context.peek()?.typ == exports.EnumToken.FlexTokenType;
|
|
14455
|
+
success = context.peek()?.typ == exports.EnumToken.FlexTokenType || context.peek()?.typ == exports.EnumToken.UserDefinedDimensionTokenType;
|
|
14207
14456
|
break;
|
|
14208
14457
|
case "length": {
|
|
14209
14458
|
const token = context.peek();
|
|
14210
|
-
// if (token == null) {
|
|
14211
|
-
// break;
|
|
14212
|
-
// }
|
|
14213
14459
|
success =
|
|
14214
14460
|
token?.typ == exports.EnumToken.LengthTokenType ||
|
|
14461
|
+
token?.typ == exports.EnumToken.UserDefinedDimensionTokenType ||
|
|
14215
14462
|
(token?.typ == exports.EnumToken.NumberTokenType && token?.val === 0);
|
|
14216
14463
|
break;
|
|
14217
14464
|
}
|
|
@@ -14221,15 +14468,9 @@ function matchProperty(property, context, options) {
|
|
|
14221
14468
|
if (token == null) {
|
|
14222
14469
|
break;
|
|
14223
14470
|
}
|
|
14224
|
-
success = token.typ == exports.EnumToken.TimeTokenType;
|
|
14471
|
+
success = token.typ == exports.EnumToken.TimeTokenType || token.typ == exports.EnumToken.UserDefinedDimensionTokenType;
|
|
14225
14472
|
}
|
|
14226
14473
|
break;
|
|
14227
|
-
// case "hex-color": {
|
|
14228
|
-
// const token = context.peek();
|
|
14229
|
-
// success =
|
|
14230
|
-
// token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
|
|
14231
|
-
// break;
|
|
14232
|
-
// }
|
|
14233
14474
|
case "color":
|
|
14234
14475
|
case "color-function":
|
|
14235
14476
|
{
|
|
@@ -14237,13 +14478,6 @@ function matchProperty(property, context, options) {
|
|
|
14237
14478
|
const errors = [];
|
|
14238
14479
|
if (tokensfuncDefMap.has(token?.typ)) {
|
|
14239
14480
|
const range = context.peekRange();
|
|
14240
|
-
// if (
|
|
14241
|
-
// range.some(
|
|
14242
|
-
// (token) =>
|
|
14243
|
-
// token.typ == EnumToken.IdenTokenType &&
|
|
14244
|
-
// "hslrgbchwmyk".split("").some((t) => equalsIgnoreCase(t, (token as IdentToken).val)),
|
|
14245
|
-
// )
|
|
14246
|
-
// ) {
|
|
14247
14481
|
const newRange = range.map((t) => cloneNode(t, true));
|
|
14248
14482
|
// @ts-ignore
|
|
14249
14483
|
parseTokens(newRange, { parseColor: true }, errors);
|
|
@@ -14268,27 +14502,6 @@ function matchProperty(property, context, options) {
|
|
|
14268
14502
|
syntaxToken: null,
|
|
14269
14503
|
errors,
|
|
14270
14504
|
};
|
|
14271
|
-
// }
|
|
14272
|
-
// const result = matchSyntax(
|
|
14273
|
-
// getParsedSyntax(
|
|
14274
|
-
// ValidationSyntaxGroupEnum.Syntaxes,
|
|
14275
|
-
// (token as FunctionToken).val + "()",
|
|
14276
|
-
// ) as ValidationFunctionToken[],
|
|
14277
|
-
// createValidationContext(range),
|
|
14278
|
-
// options,
|
|
14279
|
-
// );
|
|
14280
|
-
// if (result.success) {
|
|
14281
|
-
// context.update(range.at(-1) as Token);
|
|
14282
|
-
// return {
|
|
14283
|
-
// success: true,
|
|
14284
|
-
// valid: true,
|
|
14285
|
-
// token: context.peek(),
|
|
14286
|
-
// context,
|
|
14287
|
-
// syntaxToken: null,
|
|
14288
|
-
// errors: [],
|
|
14289
|
-
// };
|
|
14290
|
-
// }
|
|
14291
|
-
// return result;
|
|
14292
14505
|
}
|
|
14293
14506
|
// @ts-expect-error
|
|
14294
14507
|
else if ("chi" in token) {
|
|
@@ -14307,10 +14520,6 @@ function matchProperty(property, context, options) {
|
|
|
14307
14520
|
}
|
|
14308
14521
|
}
|
|
14309
14522
|
break;
|
|
14310
|
-
// case "url-token":
|
|
14311
|
-
// success =
|
|
14312
|
-
// context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
|
|
14313
|
-
// break;
|
|
14314
14523
|
case "type-selector":
|
|
14315
14524
|
case "compound-selector":
|
|
14316
14525
|
case "complex-selector":
|
|
@@ -14335,15 +14544,6 @@ function matchProperty(property, context, options) {
|
|
|
14335
14544
|
};
|
|
14336
14545
|
}
|
|
14337
14546
|
case "function-token":
|
|
14338
|
-
// if (
|
|
14339
|
-
// context.peek()?.typ == EnumToken.IdenTokenType &&
|
|
14340
|
-
// context.peek(1, false)?.typ == EnumToken.StartParensTokenType
|
|
14341
|
-
// ) {
|
|
14342
|
-
// context.next();
|
|
14343
|
-
// context.next();
|
|
14344
|
-
// success = true;
|
|
14345
|
-
// break;
|
|
14346
|
-
// }
|
|
14347
14547
|
if (tokensfuncDefMap.has(context.peek()?.typ)) {
|
|
14348
14548
|
success = true;
|
|
14349
14549
|
context.next();
|
|
@@ -14365,17 +14565,6 @@ function matchProperty(property, context, options) {
|
|
|
14365
14565
|
config$3.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
|
|
14366
14566
|
break;
|
|
14367
14567
|
}
|
|
14368
|
-
// case "named-color": {
|
|
14369
|
-
// const token = context.peek();
|
|
14370
|
-
// success =
|
|
14371
|
-
// token != null &&
|
|
14372
|
-
// token.typ == EnumToken.ColorTokenType &&
|
|
14373
|
-
// ((token as ColorToken).kin == ColorType.LIT ||
|
|
14374
|
-
// (token as ColorToken).kin == ColorType.SYS ||
|
|
14375
|
-
// (token as ColorToken).kin == ColorType.DPSYS ||
|
|
14376
|
-
// (token as ColorToken).kin == ColorType.NON_STD);
|
|
14377
|
-
// break;
|
|
14378
|
-
// }
|
|
14379
14568
|
case "size-feature": {
|
|
14380
14569
|
const range = context.peekRange();
|
|
14381
14570
|
const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
|
|
@@ -14406,20 +14595,6 @@ function matchProperty(property, context, options) {
|
|
|
14406
14595
|
errors: [],
|
|
14407
14596
|
};
|
|
14408
14597
|
}
|
|
14409
|
-
// if (filteredRange.length === 3) {
|
|
14410
|
-
// success = isValue(filteredRange[2]);
|
|
14411
|
-
// if (success) {
|
|
14412
|
-
// context.update(filteredRange[2]);
|
|
14413
|
-
// return {
|
|
14414
|
-
// success,
|
|
14415
|
-
// valid: true,
|
|
14416
|
-
// token: filteredRange[2],
|
|
14417
|
-
// context,
|
|
14418
|
-
// syntaxToken: property,
|
|
14419
|
-
// errors: [],
|
|
14420
|
-
// };
|
|
14421
|
-
// }
|
|
14422
|
-
// }
|
|
14423
14598
|
break;
|
|
14424
14599
|
}
|
|
14425
14600
|
case "style-feature": {
|
|
@@ -14429,16 +14604,6 @@ function matchProperty(property, context, options) {
|
|
|
14429
14604
|
// match <style-range>
|
|
14430
14605
|
const range = context.peekRange();
|
|
14431
14606
|
const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
|
|
14432
|
-
// if (filteredRange.length === 0) {
|
|
14433
|
-
// return {
|
|
14434
|
-
// success: false,
|
|
14435
|
-
// valid: true,
|
|
14436
|
-
// token: context.peek(),
|
|
14437
|
-
// context,
|
|
14438
|
-
// syntaxToken: property,
|
|
14439
|
-
// errors: [],
|
|
14440
|
-
// };
|
|
14441
|
-
// }
|
|
14442
14607
|
if (filteredRange.length === 1) {
|
|
14443
14608
|
success =
|
|
14444
14609
|
filteredRange[0].typ === exports.EnumToken.IdenTokenType ||
|
|
@@ -14453,31 +14618,6 @@ function matchProperty(property, context, options) {
|
|
|
14453
14618
|
errors: [],
|
|
14454
14619
|
};
|
|
14455
14620
|
}
|
|
14456
|
-
// if (
|
|
14457
|
-
// filteredRange[1]?.typ === EnumToken.ColonTokenType ||
|
|
14458
|
-
// filteredRange[1]?.typ === EnumToken.DelimTokenType
|
|
14459
|
-
// ) {
|
|
14460
|
-
// const result = isDeclarationValue(filteredRange.slice(2));
|
|
14461
|
-
// if (result.success) {
|
|
14462
|
-
// context.update(filteredRange.at(-1)!);
|
|
14463
|
-
// return {
|
|
14464
|
-
// success: true,
|
|
14465
|
-
// valid: true,
|
|
14466
|
-
// token: filteredRange.at(-1)!,
|
|
14467
|
-
// context,
|
|
14468
|
-
// syntaxToken: property,
|
|
14469
|
-
// errors: [],
|
|
14470
|
-
// };
|
|
14471
|
-
// }
|
|
14472
|
-
// return {
|
|
14473
|
-
// success: false,
|
|
14474
|
-
// valid: false,
|
|
14475
|
-
// token: context.peek(),
|
|
14476
|
-
// context,
|
|
14477
|
-
// syntaxToken: property,
|
|
14478
|
-
// errors: result.errors,
|
|
14479
|
-
// };
|
|
14480
|
-
// }
|
|
14481
14621
|
return {
|
|
14482
14622
|
success: false,
|
|
14483
14623
|
valid: false,
|
|
@@ -14489,10 +14629,6 @@ function matchProperty(property, context, options) {
|
|
|
14489
14629
|
}
|
|
14490
14630
|
case "url": {
|
|
14491
14631
|
const token = context.peek();
|
|
14492
|
-
// if (token == null) {
|
|
14493
|
-
// success = false;
|
|
14494
|
-
// break;
|
|
14495
|
-
// }
|
|
14496
14632
|
let l;
|
|
14497
14633
|
if (token?.typ == exports.EnumToken.UrlFunctionTokenDefType) {
|
|
14498
14634
|
l = 0;
|
|
@@ -14506,11 +14642,6 @@ function matchProperty(property, context, options) {
|
|
|
14506
14642
|
(token.typ == exports.EnumToken.StringTokenType ||
|
|
14507
14643
|
token.typ == exports.EnumToken.IdenTokenType ||
|
|
14508
14644
|
token.typ == exports.EnumToken.UrlTokenTokenType)) {
|
|
14509
|
-
// if (token.typ === EnumToken.IdenTokenType) {
|
|
14510
|
-
// while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
|
|
14511
|
-
// l++;
|
|
14512
|
-
// }
|
|
14513
|
-
// }
|
|
14514
14645
|
while ((token = context.peek(++l))) {
|
|
14515
14646
|
if (token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType) {
|
|
14516
14647
|
break;
|
|
@@ -14574,10 +14705,46 @@ function matchProperty(property, context, options) {
|
|
|
14574
14705
|
}
|
|
14575
14706
|
break;
|
|
14576
14707
|
}
|
|
14708
|
+
case "dashed-function": {
|
|
14709
|
+
const token = context.peek();
|
|
14710
|
+
success = token?.typ == exports.EnumToken.CustomFunctionTokenDefType;
|
|
14711
|
+
if (success) {
|
|
14712
|
+
context.next();
|
|
14713
|
+
return {
|
|
14714
|
+
success: true,
|
|
14715
|
+
valid: true,
|
|
14716
|
+
token,
|
|
14717
|
+
context,
|
|
14718
|
+
syntaxToken: null,
|
|
14719
|
+
errors: [],
|
|
14720
|
+
};
|
|
14721
|
+
}
|
|
14722
|
+
break;
|
|
14723
|
+
}
|
|
14724
|
+
case "block-contents":
|
|
14725
|
+
success = context.peek()?.typ == exports.EnumToken.StartParensTokenType;
|
|
14726
|
+
if (success) {
|
|
14727
|
+
context.next();
|
|
14728
|
+
return {
|
|
14729
|
+
success: true,
|
|
14730
|
+
valid: true,
|
|
14731
|
+
token: null,
|
|
14732
|
+
context,
|
|
14733
|
+
syntaxToken: null,
|
|
14734
|
+
errors: [],
|
|
14735
|
+
};
|
|
14736
|
+
}
|
|
14737
|
+
return {
|
|
14738
|
+
success: false,
|
|
14739
|
+
valid: true,
|
|
14740
|
+
token,
|
|
14741
|
+
context,
|
|
14742
|
+
syntaxToken: property,
|
|
14743
|
+
errors: [],
|
|
14744
|
+
};
|
|
14577
14745
|
default:
|
|
14578
14746
|
if (!(property.val in config$3.syntaxes)) {
|
|
14579
14747
|
console.debug("Unknown syntax", context.peek(), property);
|
|
14580
|
-
console.debug(context.getRemainingTokens());
|
|
14581
14748
|
throw new Error(`Unexpected validation property ${property.val}`);
|
|
14582
14749
|
}
|
|
14583
14750
|
return matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
|
|
@@ -17613,7 +17780,7 @@ function replace(node, variableScope) {
|
|
|
17613
17780
|
}
|
|
17614
17781
|
}
|
|
17615
17782
|
for (const { value, parent: parentValue } of walkValues(node.val)) {
|
|
17616
|
-
if (value.typ == exports.EnumToken.
|
|
17783
|
+
if (value.typ == exports.EnumToken.MathFunctionTokenType ||
|
|
17617
17784
|
(value.typ == exports.EnumToken.WildCardFunctionTokenType && value.val == "var")) {
|
|
17618
17785
|
if (value.chi.length == 1 &&
|
|
17619
17786
|
value.chi[0].typ == exports.EnumToken.DashedIdenTokenType) {
|
|
@@ -17621,9 +17788,10 @@ function replace(node, variableScope) {
|
|
|
17621
17788
|
if (info?.replaceable) {
|
|
17622
17789
|
if (parentValue != null) {
|
|
17623
17790
|
let i = 0;
|
|
17624
|
-
|
|
17625
|
-
|
|
17626
|
-
|
|
17791
|
+
const source = parentValue.typ == exports.EnumToken.DeclarationNodeType ? parentValue.val : parentValue.chi;
|
|
17792
|
+
for (; i < source.length; i++) {
|
|
17793
|
+
if (source[i] == value) {
|
|
17794
|
+
source.splice(i, 1, ...info.node.val);
|
|
17627
17795
|
break;
|
|
17628
17796
|
}
|
|
17629
17797
|
}
|
|
@@ -20081,7 +20249,7 @@ class PropertyMap {
|
|
|
20081
20249
|
if (value instanceof PropertyMap) {
|
|
20082
20250
|
for (const [k, v] of value.declarations) {
|
|
20083
20251
|
if (k == value.config.shorthand) {
|
|
20084
|
-
for (const [key
|
|
20252
|
+
for (const [key] of Object.entries(value.config.properties)) {
|
|
20085
20253
|
mapped[key] = cloneNode(v);
|
|
20086
20254
|
for (let i = 0; i < v.val.length; i++) {
|
|
20087
20255
|
// @ts-ignore
|
|
@@ -20857,18 +21025,43 @@ const config = getConfig();
|
|
|
20857
21025
|
* Represents a list of property declarations, compute shorthand and remove duplicate declarations.
|
|
20858
21026
|
*/
|
|
20859
21027
|
class PropertyList {
|
|
21028
|
+
/**
|
|
21029
|
+
* options
|
|
21030
|
+
*/
|
|
20860
21031
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
21032
|
+
/**
|
|
21033
|
+
* declarations
|
|
21034
|
+
*/
|
|
20861
21035
|
declarations;
|
|
21036
|
+
/**
|
|
21037
|
+
*
|
|
21038
|
+
* @param options
|
|
21039
|
+
*/
|
|
20862
21040
|
constructor(options = {}) {
|
|
20863
21041
|
this.options = options;
|
|
20864
21042
|
this.declarations = new Map();
|
|
20865
21043
|
}
|
|
21044
|
+
/**
|
|
21045
|
+
* add declarations
|
|
21046
|
+
* @param declarations
|
|
21047
|
+
* @returns
|
|
21048
|
+
*/
|
|
20866
21049
|
add(declarations) {
|
|
20867
21050
|
let name;
|
|
20868
21051
|
let syntaxRules = null;
|
|
20869
21052
|
let result;
|
|
20870
21053
|
for (const declaration of declarations) {
|
|
20871
21054
|
name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
|
|
21055
|
+
// do not compute shorthand for invalid declarations
|
|
21056
|
+
if (name == null) {
|
|
21057
|
+
this.declarations.set(objectHash(declaration), declaration);
|
|
21058
|
+
continue;
|
|
21059
|
+
}
|
|
21060
|
+
// @functiom / result
|
|
21061
|
+
if (declaration[STATE] & exports.EnumAstNodeStatus.Unknown && equalsIgnoreCase("result", name)) {
|
|
21062
|
+
this.declarations.set(declaration.nam, declaration);
|
|
21063
|
+
continue;
|
|
21064
|
+
}
|
|
20872
21065
|
if (declaration[STATE] &
|
|
20873
21066
|
(exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
|
|
20874
21067
|
declaration.typ != exports.EnumToken.DeclarationNodeType ||
|
|
@@ -20992,6 +21185,11 @@ class PropertyList {
|
|
|
20992
21185
|
}
|
|
20993
21186
|
return this;
|
|
20994
21187
|
}
|
|
21188
|
+
/**
|
|
21189
|
+
*
|
|
21190
|
+
* @param declaration
|
|
21191
|
+
* @param mapping
|
|
21192
|
+
*/
|
|
20995
21193
|
mapValues(declaration, mapping) {
|
|
20996
21194
|
let name;
|
|
20997
21195
|
let values = declaration.val;
|
|
@@ -21051,6 +21249,10 @@ class PropertyList {
|
|
|
21051
21249
|
}
|
|
21052
21250
|
}
|
|
21053
21251
|
}
|
|
21252
|
+
/**
|
|
21253
|
+
*
|
|
21254
|
+
* @returns
|
|
21255
|
+
*/
|
|
21054
21256
|
[Symbol.iterator]() {
|
|
21055
21257
|
let iterator = this.declarations.values();
|
|
21056
21258
|
const iterators = [];
|
|
@@ -21106,32 +21308,49 @@ class ComputeShorthandFeature {
|
|
|
21106
21308
|
let l;
|
|
21107
21309
|
const rules = [];
|
|
21108
21310
|
const declarations = [];
|
|
21109
|
-
|
|
21110
|
-
|
|
21111
|
-
|
|
21112
|
-
|
|
21113
|
-
|
|
21114
|
-
|
|
21115
|
-
|
|
21116
|
-
|
|
21117
|
-
|
|
21118
|
-
|
|
21119
|
-
|
|
21120
|
-
|
|
21311
|
+
let doNotSort = false;
|
|
21312
|
+
if (ast.typ == exports.EnumToken.AtRuleNodeType) {
|
|
21313
|
+
switch (ast.nam) {
|
|
21314
|
+
case "function":
|
|
21315
|
+
case "mixin":
|
|
21316
|
+
doNotSort = true;
|
|
21317
|
+
break;
|
|
21318
|
+
}
|
|
21319
|
+
}
|
|
21320
|
+
// https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
|
|
21321
|
+
if (doNotSort) {
|
|
21322
|
+
for (const node of ast.chi) {
|
|
21323
|
+
declarations.push(node);
|
|
21121
21324
|
}
|
|
21325
|
+
}
|
|
21326
|
+
else {
|
|
21122
21327
|
// @ts-ignore
|
|
21123
|
-
|
|
21124
|
-
|
|
21125
|
-
|
|
21126
|
-
|
|
21328
|
+
for (; k < j; k++) {
|
|
21329
|
+
l = k;
|
|
21330
|
+
// capture comments with the next token
|
|
21331
|
+
while (l + 1 < j) {
|
|
21332
|
+
// @ts-ignore
|
|
21333
|
+
const node = ast.chi[l];
|
|
21334
|
+
if (node.typ == exports.EnumToken.CommentNodeType) {
|
|
21335
|
+
l++;
|
|
21336
|
+
continue;
|
|
21337
|
+
}
|
|
21338
|
+
break;
|
|
21127
21339
|
}
|
|
21128
|
-
|
|
21129
|
-
|
|
21130
|
-
|
|
21131
|
-
|
|
21340
|
+
// @ts-ignore
|
|
21341
|
+
const node = ast.chi[l];
|
|
21342
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
21343
|
+
for (let m = k; m <= l; m++) {
|
|
21344
|
+
declarations.push(ast.chi[m]);
|
|
21345
|
+
}
|
|
21132
21346
|
}
|
|
21347
|
+
else {
|
|
21348
|
+
for (let m = k; m <= l; m++) {
|
|
21349
|
+
rules.push(ast.chi[m]);
|
|
21350
|
+
}
|
|
21351
|
+
}
|
|
21352
|
+
k = l;
|
|
21133
21353
|
}
|
|
21134
|
-
k = l;
|
|
21135
21354
|
}
|
|
21136
21355
|
if (declarations.length > 0) {
|
|
21137
21356
|
ast.chi.length = 0;
|
|
@@ -21151,6 +21370,7 @@ const trimTokenSpace = new Set([
|
|
|
21151
21370
|
exports.EnumToken.LteTokenType,
|
|
21152
21371
|
exports.EnumToken.ChildCombinatorTokenType,
|
|
21153
21372
|
exports.EnumToken.PipeTokenType,
|
|
21373
|
+
exports.EnumToken.ColonTokenType,
|
|
21154
21374
|
]);
|
|
21155
21375
|
const trimSpaceAfter = new Set([
|
|
21156
21376
|
...tokensfuncSet.values(),
|
|
@@ -21172,9 +21392,16 @@ function replaceNodeOrValue(parent, node, replacement) {
|
|
|
21172
21392
|
if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
|
|
21173
21393
|
throw new TypeError(`replacement is null`);
|
|
21174
21394
|
}
|
|
21175
|
-
|
|
21176
|
-
if (
|
|
21177
|
-
|
|
21395
|
+
if (!Array.isArray(replacement)) {
|
|
21396
|
+
if (replacement[PARENT] != parent) {
|
|
21397
|
+
replacement[PARENT] = parent;
|
|
21398
|
+
}
|
|
21399
|
+
}
|
|
21400
|
+
else {
|
|
21401
|
+
for (const newNode of replacement) {
|
|
21402
|
+
if (newNode[PARENT] != parent) {
|
|
21403
|
+
newNode[PARENT] = parent;
|
|
21404
|
+
}
|
|
21178
21405
|
}
|
|
21179
21406
|
}
|
|
21180
21407
|
if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
@@ -22657,9 +22884,9 @@ button {
|
|
|
22657
22884
|
* @returns
|
|
22658
22885
|
*/
|
|
22659
22886
|
function find(ast, matcher) {
|
|
22660
|
-
for (const
|
|
22661
|
-
if (matcher(node, parent)) {
|
|
22662
|
-
return node;
|
|
22887
|
+
for (const r of walk(ast)) {
|
|
22888
|
+
if (matcher(r.node, r.parent)) {
|
|
22889
|
+
return r.node;
|
|
22663
22890
|
}
|
|
22664
22891
|
}
|
|
22665
22892
|
return null;
|
|
@@ -22698,21 +22925,25 @@ button {
|
|
|
22698
22925
|
*/
|
|
22699
22926
|
function findByValue(ast, matcher) {
|
|
22700
22927
|
let source;
|
|
22701
|
-
for (const
|
|
22928
|
+
for (const r1 of walk(ast)) {
|
|
22702
22929
|
source = null;
|
|
22703
|
-
if (node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
22704
|
-
source = node.val;
|
|
22930
|
+
if (r1.node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
22931
|
+
source = r1.node.val;
|
|
22705
22932
|
}
|
|
22706
|
-
else if (Array.isArray(node[TOKENS])) {
|
|
22707
|
-
source = node[TOKENS];
|
|
22933
|
+
else if (Array.isArray(r1.node[TOKENS])) {
|
|
22934
|
+
source = r1.node[TOKENS];
|
|
22708
22935
|
}
|
|
22709
22936
|
if (source == null) {
|
|
22710
22937
|
continue;
|
|
22711
22938
|
}
|
|
22712
|
-
for (const
|
|
22713
|
-
if (matcher(value, node)) {
|
|
22714
|
-
|
|
22715
|
-
|
|
22939
|
+
for (const r2 of walkValues(source, r1.node)) {
|
|
22940
|
+
if (matcher(r2.value, r1.node)) {
|
|
22941
|
+
return {
|
|
22942
|
+
// @ts-ignore
|
|
22943
|
+
node: r1.node,
|
|
22944
|
+
// @ts-ignore
|
|
22945
|
+
value: { node: r2.value, parent: r2.parent, root: r2.root, parents: r2.parents },
|
|
22946
|
+
};
|
|
22716
22947
|
}
|
|
22717
22948
|
}
|
|
22718
22949
|
}
|
|
@@ -22754,9 +22985,9 @@ button-small {
|
|
|
22754
22985
|
*/
|
|
22755
22986
|
function findAll(ast, matcher) {
|
|
22756
22987
|
const result = [];
|
|
22757
|
-
for (const
|
|
22758
|
-
if (matcher(node,
|
|
22759
|
-
result.push(node);
|
|
22988
|
+
for (const r of walk(ast)) {
|
|
22989
|
+
if (matcher(r.node, r.node[PARENT])) {
|
|
22990
|
+
result.push(r.node);
|
|
22760
22991
|
}
|
|
22761
22992
|
}
|
|
22762
22993
|
return result;
|
|
@@ -22792,11 +23023,12 @@ button {
|
|
|
22792
23023
|
* @returns
|
|
22793
23024
|
*/
|
|
22794
23025
|
function findLast(ast, matcher) {
|
|
22795
|
-
for (const
|
|
22796
|
-
|
|
22797
|
-
|
|
23026
|
+
for (const result of walk(ast, null, true))
|
|
23027
|
+
// for (const { node, parent } of walk(ast as AstNode, null, true)) {
|
|
23028
|
+
if (matcher(result.node, result.parent)) {
|
|
23029
|
+
return result.node;
|
|
22798
23030
|
}
|
|
22799
|
-
}
|
|
23031
|
+
// }
|
|
22800
23032
|
return null;
|
|
22801
23033
|
}
|
|
22802
23034
|
|
|
@@ -23339,8 +23571,35 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
23339
23571
|
previous = ast.chi[--nodeIndex];
|
|
23340
23572
|
}
|
|
23341
23573
|
node = ast.chi[i];
|
|
23342
|
-
if (node.typ === exports.EnumToken.AtRuleNodeType
|
|
23343
|
-
|
|
23574
|
+
if (node.typ === exports.EnumToken.AtRuleNodeType) {
|
|
23575
|
+
if (node.nam === "font-face") {
|
|
23576
|
+
continue;
|
|
23577
|
+
}
|
|
23578
|
+
// https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
|
|
23579
|
+
if (equalsIgnoreCase(node.nam, "function")) {
|
|
23580
|
+
const chi = node.chi;
|
|
23581
|
+
let k = chi?.length;
|
|
23582
|
+
let slice = false;
|
|
23583
|
+
while (k--) {
|
|
23584
|
+
if (chi[k].typ === exports.EnumToken.CommentNodeType ||
|
|
23585
|
+
chi[k].typ === exports.EnumToken.WhitespaceTokenType) {
|
|
23586
|
+
continue;
|
|
23587
|
+
}
|
|
23588
|
+
if (chi[k].typ === exports.EnumToken.DeclarationNodeType &&
|
|
23589
|
+
equalsIgnoreCase(chi[k].nam, "result")) {
|
|
23590
|
+
slice = true;
|
|
23591
|
+
break;
|
|
23592
|
+
}
|
|
23593
|
+
}
|
|
23594
|
+
if (k > 0 && slice) {
|
|
23595
|
+
while (k--) {
|
|
23596
|
+
if (chi[k].typ === exports.EnumToken.AtRuleNodeType) {
|
|
23597
|
+
chi.splice(k, 1);
|
|
23598
|
+
continue;
|
|
23599
|
+
}
|
|
23600
|
+
}
|
|
23601
|
+
}
|
|
23602
|
+
}
|
|
23344
23603
|
}
|
|
23345
23604
|
if (node.typ === exports.EnumToken.KeyframesAtRuleNodeType) {
|
|
23346
23605
|
if (previous?.typ === exports.EnumToken.KeyframesAtRuleNodeType &&
|
|
@@ -25875,7 +26134,7 @@ function renderAstNode(data, options, sourcemaps, sourceLocation, linesMap, erro
|
|
|
25875
26134
|
case exports.EnumToken.KeyframesRuleNodeType:
|
|
25876
26135
|
case exports.EnumToken.KeyframesAtRuleNodeType:
|
|
25877
26136
|
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframesAtRuleNodeType].includes(data.typ) && !("chi" in data)) {
|
|
25878
|
-
return `${indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
|
|
26137
|
+
return `${(indent.length > 0 ? options.newLine : "") + indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
|
|
25879
26138
|
}
|
|
25880
26139
|
const lineMapLength = linesMap ? linesMap.getLineStarts().length : 0;
|
|
25881
26140
|
const prelude = (indent.length > 0 ? options.newLine : "") +
|
|
@@ -26700,6 +26959,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
26700
26959
|
case exports.EnumToken.DimensionTokenType:
|
|
26701
26960
|
case exports.EnumToken.FrequencyTokenType:
|
|
26702
26961
|
case exports.EnumToken.ResolutionTokenType:
|
|
26962
|
+
case exports.EnumToken.UserDefinedDimensionTokenType:
|
|
26703
26963
|
let val = token.val.typ == exports.EnumToken.FractionTokenType
|
|
26704
26964
|
? renderValue(token.val, options, cache)
|
|
26705
26965
|
: minifyNumber(token.val);
|
|
@@ -26899,8 +27159,10 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
26899
27159
|
case exports.EnumToken.BadUrlTokenType:
|
|
26900
27160
|
case exports.EnumToken.EOFTokenType:
|
|
26901
27161
|
return "";
|
|
27162
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
27163
|
+
return `${token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "")}${token.r == null ? "" : " from " + renderValue(token.r, options, cache, reducer)}`;
|
|
26902
27164
|
default:
|
|
26903
|
-
console.
|
|
27165
|
+
console.error({ token });
|
|
26904
27166
|
throw new Error(`Unsupported token type for ${exports.EnumToken[token.typ]}`);
|
|
26905
27167
|
}
|
|
26906
27168
|
// errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
@@ -26963,7 +27225,6 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) {
|
|
|
26963
27225
|
SymbolsMapTokensLower[key.toLowerCase()] = tokenType;
|
|
26964
27226
|
}
|
|
26965
27227
|
}
|
|
26966
|
-
SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType;
|
|
26967
27228
|
SymbolsMapTokens["+"] = exports.EnumToken.Plus;
|
|
26968
27229
|
SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType;
|
|
26969
27230
|
SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType;
|
|
@@ -27412,6 +27673,11 @@ class Tokenizer {
|
|
|
27412
27673
|
hasLetter = true;
|
|
27413
27674
|
break;
|
|
27414
27675
|
}
|
|
27676
|
+
// dashed ident as unit
|
|
27677
|
+
if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
27678
|
+
hasLetter = true;
|
|
27679
|
+
break;
|
|
27680
|
+
}
|
|
27415
27681
|
return 0;
|
|
27416
27682
|
}
|
|
27417
27683
|
if (!hasLetter && !hasPercent) {
|
|
@@ -27440,6 +27706,10 @@ class Tokenizer {
|
|
|
27440
27706
|
else if (isLetter(codepoint)) {
|
|
27441
27707
|
hasLetter = true;
|
|
27442
27708
|
}
|
|
27709
|
+
// custom ident as unit
|
|
27710
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
27711
|
+
hasLetter = true;
|
|
27712
|
+
}
|
|
27443
27713
|
else {
|
|
27444
27714
|
return 0;
|
|
27445
27715
|
}
|
|
@@ -27477,6 +27747,10 @@ class Tokenizer {
|
|
|
27477
27747
|
hasLetter = true;
|
|
27478
27748
|
break;
|
|
27479
27749
|
}
|
|
27750
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
27751
|
+
hasLetter = true;
|
|
27752
|
+
break;
|
|
27753
|
+
}
|
|
27480
27754
|
if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
|
|
27481
27755
|
hasPercent = true;
|
|
27482
27756
|
break;
|
|
@@ -27540,6 +27814,11 @@ class Tokenizer {
|
|
|
27540
27814
|
hasLetter = true;
|
|
27541
27815
|
break;
|
|
27542
27816
|
}
|
|
27817
|
+
// custom ident as unit
|
|
27818
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
27819
|
+
hasLetter = true;
|
|
27820
|
+
break;
|
|
27821
|
+
}
|
|
27543
27822
|
else if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
|
|
27544
27823
|
hasPercent = true;
|
|
27545
27824
|
break;
|
|
@@ -27581,7 +27860,7 @@ class Tokenizer {
|
|
|
27581
27860
|
const slice = codepoint == 0x45 || codepoint == 0x65 ? position - 1 : position;
|
|
27582
27861
|
while (position + 1 <= parseInfo.stream.length) {
|
|
27583
27862
|
codepoint = parseInfo.stream.charCodeAt(++position);
|
|
27584
|
-
if (!isLetter(codepoint)) {
|
|
27863
|
+
if (!isLetter(codepoint) && codepoint != 0x2d) {
|
|
27585
27864
|
break;
|
|
27586
27865
|
}
|
|
27587
27866
|
}
|
|
@@ -27866,6 +28145,9 @@ class Tokenizer {
|
|
|
27866
28145
|
this.val = parseFloat(parseInfo.stream.slice(parseInfo.position - parseInfo.offset, options?.slice));
|
|
27867
28146
|
if (hint != exports.EnumToken.PercentageTokenType) {
|
|
27868
28147
|
this.unit = val;
|
|
28148
|
+
if (val.startsWith("--")) {
|
|
28149
|
+
this.typ = exports.EnumToken.UserDefinedDimensionTokenType;
|
|
28150
|
+
}
|
|
27869
28151
|
}
|
|
27870
28152
|
}
|
|
27871
28153
|
else if (hint == exports.EnumToken.NumberTokenType) {
|
|
@@ -29621,7 +29903,7 @@ function parseMediaqueryList(stream, options) {
|
|
|
29621
29903
|
Object.assign(stream[i], {
|
|
29622
29904
|
typ: val === "and" ? exports.EnumToken.AndTokenType : exports.EnumToken.OrTokenType,
|
|
29623
29905
|
});
|
|
29624
|
-
if (val === "or" && scopes.length
|
|
29906
|
+
if (val === "or" && (scopes.length == 1 && scopes[0].size > 0 && !scopes[0].has(exports.EnumToken.OrTokenType))) {
|
|
29625
29907
|
success = false;
|
|
29626
29908
|
errors.push({
|
|
29627
29909
|
action: "drop",
|
|
@@ -30137,7 +30419,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
|
|
|
30137
30419
|
break;
|
|
30138
30420
|
}
|
|
30139
30421
|
if ("and" === val || "or" === val) {
|
|
30140
|
-
if ("or" === val && scopes.length === 1) {
|
|
30422
|
+
if ("or" === val && scopes.length === 1 && scopes[0].size > 0) {
|
|
30141
30423
|
const fileName = options.source.getFileName() ?? "";
|
|
30142
30424
|
const [line, column] = options.source.getOffsets(stream[i]?.[LOCSTA]);
|
|
30143
30425
|
return {
|
|
@@ -31220,19 +31502,10 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
31220
31502
|
key = visitors[i][0];
|
|
31221
31503
|
value = visitors[i][1];
|
|
31222
31504
|
if (Number.isInteger(+key)) {
|
|
31223
|
-
// if (Array.isArray(value)) {
|
|
31224
|
-
// visitors.splice(i + 1, 0, ...Object.entries(value));
|
|
31225
|
-
// continue;
|
|
31226
|
-
// }
|
|
31227
31505
|
if (typeof value == "function") {
|
|
31228
31506
|
key = value.name;
|
|
31229
31507
|
}
|
|
31230
31508
|
}
|
|
31231
|
-
// if (Array.isArray(value)) {
|
|
31232
|
-
// // @ts-ignore
|
|
31233
|
-
// visitors.splice(i + 1, 0, ...value.map((item) => [key, item]));
|
|
31234
|
-
// continue;
|
|
31235
|
-
// }
|
|
31236
31509
|
if (key in exports.EnumToken) {
|
|
31237
31510
|
if (typeof value == "function") {
|
|
31238
31511
|
if (!valuesHandlers.has(exports.EnumToken[key])) {
|
|
@@ -31592,7 +31865,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31592
31865
|
if (tokens.length > 0) {
|
|
31593
31866
|
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
31594
31867
|
if (node != null) {
|
|
31595
|
-
if ("chi" in node
|
|
31868
|
+
if ("chi" in node) {
|
|
31596
31869
|
stack.push(node);
|
|
31597
31870
|
context = node;
|
|
31598
31871
|
}
|
|
@@ -31606,54 +31879,208 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31606
31879
|
if (options.visitor != null) {
|
|
31607
31880
|
const handlers = [];
|
|
31608
31881
|
const visitors = parseVisitors(options.visitor, errors);
|
|
31609
|
-
const subNodes = [];
|
|
31610
31882
|
let parens;
|
|
31611
31883
|
let genericKey;
|
|
31612
|
-
let nodes =
|
|
31613
|
-
let
|
|
31614
|
-
|
|
31615
|
-
|
|
31616
|
-
let freeBlock = 1;
|
|
31617
|
-
nodes[0] = ast;
|
|
31618
|
-
for (i = 0; i < nodes.length; i++) {
|
|
31619
|
-
if (nodes[i] == null) {
|
|
31620
|
-
break;
|
|
31621
|
-
}
|
|
31622
|
-
subNodes.length = 0;
|
|
31884
|
+
let nodes = [ast];
|
|
31885
|
+
let node;
|
|
31886
|
+
while (nodes.length > 0) {
|
|
31887
|
+
node = nodes.pop();
|
|
31623
31888
|
if (visitors.includeTokens) {
|
|
31624
|
-
switch (
|
|
31889
|
+
switch (node.typ) {
|
|
31625
31890
|
case exports.EnumToken.RuleNodeType:
|
|
31626
31891
|
case exports.EnumToken.AtRuleNodeType:
|
|
31627
31892
|
case exports.EnumToken.KeyframesRuleNodeType:
|
|
31628
31893
|
case exports.EnumToken.KeyframesAtRuleNodeType:
|
|
31629
|
-
for (
|
|
31630
|
-
|
|
31894
|
+
for (let i =
|
|
31895
|
+
// @ts-ignore
|
|
31896
|
+
node[TOKENS].length -
|
|
31897
|
+
1; i >= 0; i--) {
|
|
31898
|
+
// @ts-ignore
|
|
31899
|
+
node[TOKENS][i][PARENT] =
|
|
31900
|
+
node;
|
|
31901
|
+
nodes.push(
|
|
31902
|
+
// @ts-ignore
|
|
31903
|
+
node[TOKENS][i]);
|
|
31631
31904
|
}
|
|
31632
31905
|
break;
|
|
31633
31906
|
case exports.EnumToken.DeclarationNodeType:
|
|
31634
|
-
for (
|
|
31635
|
-
|
|
31907
|
+
for (let i =
|
|
31908
|
+
// @ts-ignore
|
|
31909
|
+
node.val.length - 1; i >= 0; i--) {
|
|
31910
|
+
node.val[i][PARENT] = node;
|
|
31911
|
+
// @ts-ignore
|
|
31912
|
+
nodes.push(node.val[i]);
|
|
31636
31913
|
}
|
|
31637
31914
|
break;
|
|
31638
31915
|
}
|
|
31916
|
+
// @ts-ignore
|
|
31917
|
+
// if (node.l != null) {
|
|
31918
|
+
// // @ts-ignore
|
|
31919
|
+
// if (node.op2 != null) {
|
|
31920
|
+
// // @ts-ignore
|
|
31921
|
+
// nodes.push(node.op2);
|
|
31922
|
+
// // @ts-ignore
|
|
31923
|
+
// node.op2[PARENT] = node;
|
|
31924
|
+
// }
|
|
31925
|
+
// // @ts-ignore
|
|
31926
|
+
// if (node.op1 != null) {
|
|
31927
|
+
// // @ts-ignore
|
|
31928
|
+
// nodes.push(node.op1);
|
|
31929
|
+
// // @ts-ignore
|
|
31930
|
+
// node.op1[PARENT] = node;
|
|
31931
|
+
// }
|
|
31932
|
+
// // @ts-ignore
|
|
31933
|
+
// if (nodes.op != null && node.op.typ != null) {
|
|
31934
|
+
// // @ts-ignore
|
|
31935
|
+
// nodes.push(node.op);
|
|
31936
|
+
// // @ts-ignore
|
|
31937
|
+
// node.op[PARENT] = node;
|
|
31938
|
+
// }
|
|
31939
|
+
// // @ts-ignore
|
|
31940
|
+
// if (node.r != null) {
|
|
31941
|
+
// // @ts-ignore
|
|
31942
|
+
// if (Array.isArray(node.r)) {
|
|
31943
|
+
// // @ts-ignore
|
|
31944
|
+
// for (let i = node.r.length - 1; i >= 0; i--) {
|
|
31945
|
+
// // @ts-ignore
|
|
31946
|
+
// nodes.push(node.r[i]);
|
|
31947
|
+
// // @ts-ignore
|
|
31948
|
+
// node.r[i][PARENT] = node;
|
|
31949
|
+
// }
|
|
31950
|
+
// } else {
|
|
31951
|
+
// // @ts-ignore
|
|
31952
|
+
// nodes.push(node.r);
|
|
31953
|
+
// // @ts-ignore
|
|
31954
|
+
// node.r[PARENT] = node;
|
|
31955
|
+
// }
|
|
31956
|
+
// }
|
|
31957
|
+
// // @ts-ignore
|
|
31958
|
+
// if (Array.isArray(node.l)) {
|
|
31959
|
+
// // @ts-ignore
|
|
31960
|
+
// for (let i = node.l.length - 1; i >= 0; i--) {
|
|
31961
|
+
// // @ts-ignore
|
|
31962
|
+
// nodes.push(node.l[i]);
|
|
31963
|
+
// // @ts-ignore
|
|
31964
|
+
// node.l[i][PARENT] = node;
|
|
31965
|
+
// }
|
|
31966
|
+
// } else {
|
|
31967
|
+
// // @ts-ignore
|
|
31968
|
+
// nodes.push(node.l);
|
|
31969
|
+
// // @ts-ignore
|
|
31970
|
+
// node.l[PARENT] = node;
|
|
31971
|
+
// }
|
|
31972
|
+
// }
|
|
31973
|
+
}
|
|
31974
|
+
switch (node.typ) {
|
|
31975
|
+
case exports.EnumToken.BinaryExpressionTokenType:
|
|
31976
|
+
case exports.EnumToken.IfElseConditionTokenType:
|
|
31977
|
+
nodes.push(node.r);
|
|
31978
|
+
node.r[PARENT] = node;
|
|
31979
|
+
nodes.push(node.l);
|
|
31980
|
+
node.l[PARENT] = node;
|
|
31981
|
+
break;
|
|
31982
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
31983
|
+
nodes.push(node.r);
|
|
31984
|
+
node.r[PARENT] = node;
|
|
31985
|
+
nodes.push(node.op);
|
|
31986
|
+
node.op[PARENT] = node;
|
|
31987
|
+
nodes.push(node.l);
|
|
31988
|
+
node.l[PARENT] = node;
|
|
31989
|
+
break;
|
|
31990
|
+
case exports.EnumToken.SupportsQueryConditionTokenType:
|
|
31991
|
+
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
31992
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
31993
|
+
const element = node.r[i];
|
|
31994
|
+
nodes.push(element);
|
|
31995
|
+
element[PARENT] = node;
|
|
31996
|
+
}
|
|
31997
|
+
nodes.push(node.op);
|
|
31998
|
+
node.op[PARENT] = node;
|
|
31999
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
32000
|
+
const element = node.l[i];
|
|
32001
|
+
nodes.push(element);
|
|
32002
|
+
element[PARENT] = node;
|
|
32003
|
+
}
|
|
32004
|
+
break;
|
|
32005
|
+
case exports.EnumToken.WhenElseQueryConditionTokenType:
|
|
32006
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
32007
|
+
const element = node.r[i];
|
|
32008
|
+
nodes.push(element);
|
|
32009
|
+
element[PARENT] = node;
|
|
32010
|
+
}
|
|
32011
|
+
nodes.push(node.l);
|
|
32012
|
+
node.l[PARENT] = node;
|
|
32013
|
+
break;
|
|
32014
|
+
case exports.EnumToken.IfConditionTokenType:
|
|
32015
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
32016
|
+
const element = node.r[i];
|
|
32017
|
+
nodes.push(element);
|
|
32018
|
+
element[PARENT] = node;
|
|
32019
|
+
}
|
|
32020
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
32021
|
+
const element = node.l[i];
|
|
32022
|
+
nodes.push(element);
|
|
32023
|
+
element[PARENT] = node;
|
|
32024
|
+
}
|
|
32025
|
+
break;
|
|
32026
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
32027
|
+
if (node.r != null) {
|
|
32028
|
+
nodes.push(node.r);
|
|
32029
|
+
node.r[PARENT] = node;
|
|
32030
|
+
}
|
|
32031
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
32032
|
+
const element = node.l[i];
|
|
32033
|
+
nodes.push(element);
|
|
32034
|
+
element[PARENT] = node;
|
|
32035
|
+
}
|
|
32036
|
+
break;
|
|
32037
|
+
case exports.EnumToken.ContainerStyleRangeTokenType:
|
|
32038
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
32039
|
+
const element = node.r[i];
|
|
32040
|
+
nodes.push(element);
|
|
32041
|
+
element[PARENT] = node;
|
|
32042
|
+
}
|
|
32043
|
+
for (let i = node.op.length - 1; i >= 0; i--) {
|
|
32044
|
+
const element = node.op[i];
|
|
32045
|
+
nodes.push(element);
|
|
32046
|
+
element[PARENT] = node;
|
|
32047
|
+
}
|
|
32048
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
32049
|
+
const element = node.l[i];
|
|
32050
|
+
nodes.push(element);
|
|
32051
|
+
element[PARENT] = node;
|
|
32052
|
+
}
|
|
32053
|
+
break;
|
|
32054
|
+
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
32055
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
32056
|
+
const element = node.r[i];
|
|
32057
|
+
nodes.push(element);
|
|
32058
|
+
element[PARENT] = node;
|
|
32059
|
+
}
|
|
32060
|
+
nodes.push(node.op2);
|
|
32061
|
+
node.op2[PARENT] = node;
|
|
32062
|
+
for (let i = node.val.length - 1; i >= 0; i--) {
|
|
32063
|
+
const element = node.val[i];
|
|
32064
|
+
nodes.push(element);
|
|
32065
|
+
element[PARENT] = node;
|
|
32066
|
+
}
|
|
32067
|
+
nodes.push(node.op1);
|
|
32068
|
+
node.op1[PARENT] = node;
|
|
32069
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
32070
|
+
const element = node.l[i];
|
|
32071
|
+
nodes.push(element);
|
|
32072
|
+
element[PARENT] = node;
|
|
32073
|
+
}
|
|
32074
|
+
break;
|
|
31639
32075
|
}
|
|
31640
32076
|
// @ts-ignore
|
|
31641
|
-
if (
|
|
32077
|
+
if (node.chi != null) {
|
|
32078
|
+
for (
|
|
31642
32079
|
// @ts-ignore
|
|
31643
|
-
|
|
31644
|
-
|
|
31645
|
-
|
|
31646
|
-
}
|
|
31647
|
-
if (subNodes.length > 0) {
|
|
31648
|
-
if (freeBlock <= i) {
|
|
31649
|
-
freeBlock = i + 1;
|
|
31650
|
-
}
|
|
31651
|
-
for (k = 0; k < subNodes.length; k++) {
|
|
31652
|
-
j = k + freeBlock;
|
|
31653
|
-
nodes[j] = subNodes[k];
|
|
31654
|
-
nodes[j][PARENT] = nodes[i];
|
|
32080
|
+
let i = node.chi.length - 1; i >= 0; i--) {
|
|
32081
|
+
// @ts-ignore
|
|
32082
|
+
nodes.push(node.chi[i]);
|
|
31655
32083
|
}
|
|
31656
|
-
freeBlock += subNodes.length;
|
|
31657
32084
|
}
|
|
31658
32085
|
parens = null;
|
|
31659
32086
|
handlers.length = 0;
|
|
@@ -31661,23 +32088,23 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31661
32088
|
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
31662
32089
|
}
|
|
31663
32090
|
genericKey =
|
|
31664
|
-
|
|
32091
|
+
node.typ == exports.EnumToken.DeclarationNodeType
|
|
31665
32092
|
? "Declaration"
|
|
31666
|
-
:
|
|
32093
|
+
: node.typ == exports.EnumToken.AtRuleNodeType
|
|
31667
32094
|
? "AtRule"
|
|
31668
|
-
:
|
|
32095
|
+
: node.typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
31669
32096
|
? "KeyframesAtRule"
|
|
31670
|
-
:
|
|
32097
|
+
: node.typ === exports.EnumToken.KeyframesRuleNodeType
|
|
31671
32098
|
? "KeyframesRule"
|
|
31672
|
-
:
|
|
32099
|
+
: node.typ == exports.EnumToken.RuleNodeType
|
|
31673
32100
|
? "Rule"
|
|
31674
|
-
:
|
|
32101
|
+
: node.typ == exports.EnumToken.KeyframesRuleNodeType
|
|
31675
32102
|
? "KeyframesRule"
|
|
31676
32103
|
: null;
|
|
31677
|
-
let keyName =
|
|
31678
|
-
? camelize(
|
|
31679
|
-
:
|
|
31680
|
-
? camelize(
|
|
32104
|
+
let keyName = node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType
|
|
32105
|
+
? camelize(node.nam)
|
|
32106
|
+
: node.typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
32107
|
+
? camelize(node.val)
|
|
31681
32108
|
: null;
|
|
31682
32109
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
31683
32110
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -31697,10 +32124,9 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31697
32124
|
}
|
|
31698
32125
|
}
|
|
31699
32126
|
}
|
|
31700
|
-
|
|
31701
|
-
if (map.has(nodes[i].typ)) {
|
|
32127
|
+
if (map.has(node.typ)) {
|
|
31702
32128
|
// @ts-ignore
|
|
31703
|
-
for (const handler of map.get(
|
|
32129
|
+
for (const handler of map.get(node.typ)) {
|
|
31704
32130
|
if (typeof handler == "function") {
|
|
31705
32131
|
handlers.push(handler);
|
|
31706
32132
|
}
|
|
@@ -31728,16 +32154,15 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31728
32154
|
if (handlers.length == 0) {
|
|
31729
32155
|
continue;
|
|
31730
32156
|
}
|
|
31731
|
-
let node = nodes[i];
|
|
31732
32157
|
for (const callable of handlers) {
|
|
31733
|
-
replacement = callable(node,
|
|
32158
|
+
replacement = callable(node, node[PARENT], ast,
|
|
31734
32159
|
// @ts-expect-error
|
|
31735
32160
|
function* () {
|
|
31736
32161
|
if (parens == null) {
|
|
31737
|
-
let
|
|
31738
|
-
while (
|
|
31739
|
-
yield
|
|
31740
|
-
|
|
32162
|
+
let parent = node[PARENT];
|
|
32163
|
+
while (parent != null) {
|
|
32164
|
+
yield parent;
|
|
32165
|
+
parent = parent[PARENT];
|
|
31741
32166
|
}
|
|
31742
32167
|
}
|
|
31743
32168
|
});
|
|
@@ -31748,37 +32173,33 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31748
32173
|
continue;
|
|
31749
32174
|
}
|
|
31750
32175
|
// @ts-ignore
|
|
31751
|
-
node = replacement;
|
|
32176
|
+
// node = replacement as AstNode;
|
|
31752
32177
|
//
|
|
31753
|
-
if (Array.isArray(
|
|
32178
|
+
if (Array.isArray(replacement)) {
|
|
31754
32179
|
break;
|
|
31755
32180
|
}
|
|
31756
32181
|
}
|
|
31757
|
-
|
|
32182
|
+
// @ts-ignore
|
|
32183
|
+
if (replacement != null && node != replacement) {
|
|
31758
32184
|
// @ts-ignore
|
|
31759
|
-
replaceNodeOrValue(
|
|
32185
|
+
replaceNodeOrValue(node[PARENT], node, replacement);
|
|
31760
32186
|
}
|
|
31761
32187
|
}
|
|
31762
32188
|
nodes = null;
|
|
31763
32189
|
}
|
|
31764
32190
|
if (invalidNodes.length > 0) {
|
|
31765
|
-
|
|
31766
|
-
for (const { node, parent } of walk(ast)) {
|
|
32191
|
+
for (const node of invalidNodes) {
|
|
31767
32192
|
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
31768
32193
|
continue;
|
|
31769
32194
|
}
|
|
31770
|
-
if (node[STATE] &
|
|
31771
|
-
|
|
31772
|
-
|
|
31773
|
-
|
|
31774
|
-
|
|
32195
|
+
if (node[STATE] &
|
|
32196
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
32197
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
32198
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
32199
|
+
exports.EnumAstNodeStatus.Malformed |
|
|
32200
|
+
exports.EnumAstNodeStatus.Disallowed)) {
|
|
31775
32201
|
// @ts-ignore
|
|
31776
|
-
|
|
31777
|
-
node[PARENT] = null;
|
|
31778
|
-
count--;
|
|
31779
|
-
if (count == 0) {
|
|
31780
|
-
break;
|
|
31781
|
-
}
|
|
32202
|
+
node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
|
|
31782
32203
|
}
|
|
31783
32204
|
}
|
|
31784
32205
|
}
|
|
@@ -31799,7 +32220,6 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31799
32220
|
...stats,
|
|
31800
32221
|
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
31801
32222
|
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
31802
|
-
// tokenize: `${(options?.parseInfo?.time ?? 0).toFixed(2)}ms`,
|
|
31803
32223
|
total: `${(endTime - startTime).toFixed(2)}ms`,
|
|
31804
32224
|
},
|
|
31805
32225
|
};
|
|
@@ -31877,6 +32297,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31877
32297
|
}
|
|
31878
32298
|
// @ts-ignore
|
|
31879
32299
|
if (node.typ == exports.EnumToken.CssVariableDeclarationMapTokenType) {
|
|
32300
|
+
// @ts-ignore
|
|
31880
32301
|
const from = node.from.find((t) => t.typ == exports.EnumToken.IdenTokenType || isIdentColor(t));
|
|
31881
32302
|
if (!(from.val in cssVariablesMap)) {
|
|
31882
32303
|
errors.push({
|
|
@@ -31886,6 +32307,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31886
32307
|
});
|
|
31887
32308
|
}
|
|
31888
32309
|
else {
|
|
32310
|
+
// @ts-ignore
|
|
31889
32311
|
for (const token of node.vars) {
|
|
31890
32312
|
if (token.typ == exports.EnumToken.IdenTokenType || isIdentColor(token)) {
|
|
31891
32313
|
if (!(token.val in cssVariablesMap[from.val])) {
|
|
@@ -31909,6 +32331,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31909
32331
|
if (result.cssModuleVariables == null) {
|
|
31910
32332
|
result.cssModuleVariables = {};
|
|
31911
32333
|
}
|
|
32334
|
+
// @ts-ignore
|
|
31912
32335
|
result.cssModuleVariables[node.nam] = node;
|
|
31913
32336
|
}
|
|
31914
32337
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
@@ -32074,7 +32497,8 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
32074
32497
|
value.val = mapping[idenToken];
|
|
32075
32498
|
}
|
|
32076
32499
|
}
|
|
32077
|
-
else if (node.nam == "grid-template-areas" ||
|
|
32500
|
+
else if (node.nam == "grid-template-areas" ||
|
|
32501
|
+
node.nam == "grid-template") {
|
|
32078
32502
|
for (let i = 0; i < node.val.length; i++) {
|
|
32079
32503
|
if (node.val[i].typ == exports.EnumToken.String) {
|
|
32080
32504
|
const tokens = parseString(node.val[i].val.slice(1, -1));
|
|
@@ -32101,7 +32525,8 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
32101
32525
|
}
|
|
32102
32526
|
}
|
|
32103
32527
|
}
|
|
32104
|
-
else if (node.nam == "animation" ||
|
|
32528
|
+
else if (node.nam == "animation" ||
|
|
32529
|
+
node.nam == "animation-name") {
|
|
32105
32530
|
for (const { value } of walkValues(node.val, node)) {
|
|
32106
32531
|
if (value.typ == exports.EnumToken.IdenTokenType &&
|
|
32107
32532
|
![
|
|
@@ -32144,14 +32569,14 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
32144
32569
|
}
|
|
32145
32570
|
}
|
|
32146
32571
|
}
|
|
32147
|
-
for (const
|
|
32148
|
-
if (value.typ == exports.EnumToken.DashedIdenTokenType) {
|
|
32149
|
-
value.val = mapping[value.val];
|
|
32572
|
+
for (const r of walkValues(node.val, node)) {
|
|
32573
|
+
if (r.value.typ == exports.EnumToken.DashedIdenTokenType) {
|
|
32574
|
+
r.value.val = mapping[r.value.val];
|
|
32150
32575
|
}
|
|
32151
|
-
else if ((value.typ == exports.EnumToken.IdenTokenType || isIdentColor(value)) &&
|
|
32152
|
-
value.val in importedCssVariables) {
|
|
32576
|
+
else if ((r.value.typ == exports.EnumToken.IdenTokenType || isIdentColor(r.value)) &&
|
|
32577
|
+
r.value.val in importedCssVariables) {
|
|
32153
32578
|
// @ts-ignore
|
|
32154
|
-
replaceNodeOrValue(parent, value, importedCssVariables[value.val].val);
|
|
32579
|
+
replaceNodeOrValue(r.parent, r.value, importedCssVariables[value.val].val);
|
|
32155
32580
|
}
|
|
32156
32581
|
}
|
|
32157
32582
|
}
|
|
@@ -32364,14 +32789,9 @@ async function doParse(iter, options = {}) {
|
|
|
32364
32789
|
let parensMatch = 0;
|
|
32365
32790
|
let curlyBracketMatch = 0;
|
|
32366
32791
|
let tokenizer = iter instanceof Promise ? await iter : iter;
|
|
32367
|
-
// ast[ROOT] = ast;
|
|
32368
32792
|
ast[LOCSRCID] = options.source.id;
|
|
32369
32793
|
ast[LOCSTA] = 0;
|
|
32370
32794
|
ast[LOCEND] = 0;
|
|
32371
|
-
// if (Array.isArray(iter)) {
|
|
32372
|
-
// // @ts-expect-error
|
|
32373
|
-
// iter = iter[Symbol.iterator]() as Iterator<TokenizeResult>;
|
|
32374
|
-
// }
|
|
32375
32795
|
while (!tokenizer.done()) {
|
|
32376
32796
|
tokenizer.next();
|
|
32377
32797
|
if (tokenizer.unit != null) {
|
|
@@ -32594,53 +33014,208 @@ async function doParse(iter, options = {}) {
|
|
|
32594
33014
|
let genericKey;
|
|
32595
33015
|
const handlers = [];
|
|
32596
33016
|
const visitors = parseVisitors(options.visitor, errors);
|
|
32597
|
-
let nodes =
|
|
32598
|
-
|
|
32599
|
-
|
|
32600
|
-
|
|
32601
|
-
|
|
32602
|
-
let freeblock = 1;
|
|
32603
|
-
nodes[0] = ast;
|
|
32604
|
-
for (i = 0; i < nodes.length; i++) {
|
|
32605
|
-
if (nodes[i] == null) {
|
|
32606
|
-
break;
|
|
32607
|
-
}
|
|
32608
|
-
subNodes.length = 0;
|
|
33017
|
+
let nodes = [ast];
|
|
33018
|
+
let node;
|
|
33019
|
+
// nodes[0] = ast;
|
|
33020
|
+
while (nodes.length > 0) {
|
|
33021
|
+
node = nodes.pop();
|
|
32609
33022
|
if (visitors.includeTokens) {
|
|
32610
|
-
switch (
|
|
33023
|
+
switch (node.typ) {
|
|
32611
33024
|
case exports.EnumToken.RuleNodeType:
|
|
32612
33025
|
case exports.EnumToken.AtRuleNodeType:
|
|
32613
33026
|
case exports.EnumToken.KeyframesRuleNodeType:
|
|
32614
33027
|
case exports.EnumToken.KeyframesAtRuleNodeType:
|
|
32615
|
-
for (
|
|
32616
|
-
|
|
33028
|
+
for (let i =
|
|
33029
|
+
// @ts-ignore
|
|
33030
|
+
node[TOKENS].length -
|
|
33031
|
+
1; i >= 0; i--) {
|
|
33032
|
+
// @ts-ignore
|
|
33033
|
+
node[TOKENS][i][PARENT] =
|
|
33034
|
+
node;
|
|
33035
|
+
nodes.push(
|
|
33036
|
+
// @ts-ignore
|
|
33037
|
+
node[TOKENS][i]);
|
|
32617
33038
|
}
|
|
32618
33039
|
break;
|
|
32619
33040
|
case exports.EnumToken.DeclarationNodeType:
|
|
32620
|
-
for (
|
|
32621
|
-
|
|
33041
|
+
for (let i =
|
|
33042
|
+
// @ts-ignore
|
|
33043
|
+
node.val.length - 1; i >= 0; i--) {
|
|
33044
|
+
// @ts-ignore
|
|
33045
|
+
node.val[i][PARENT] = node;
|
|
33046
|
+
// @ts-ignore
|
|
33047
|
+
nodes.push(node.val[i]);
|
|
32622
33048
|
}
|
|
32623
33049
|
break;
|
|
32624
33050
|
}
|
|
33051
|
+
// @ts-ignore
|
|
33052
|
+
// if (node.l != null) {
|
|
33053
|
+
// // @ts-ignore
|
|
33054
|
+
// if (node.op2 != null) {
|
|
33055
|
+
// // @ts-ignore
|
|
33056
|
+
// nodes.push(node.op2);
|
|
33057
|
+
// // @ts-ignore
|
|
33058
|
+
// nodes.op2[PARENT] = node;
|
|
33059
|
+
// }
|
|
33060
|
+
// // @ts-ignore
|
|
33061
|
+
// if (node.op1 != null) {
|
|
33062
|
+
// // @ts-ignore
|
|
33063
|
+
// nodes.push(node.op1);
|
|
33064
|
+
// // @ts-ignore
|
|
33065
|
+
// nodes.op1[PARENT] = node;
|
|
33066
|
+
// }
|
|
33067
|
+
// // @ts-ignore
|
|
33068
|
+
// if (nodes.op != null && node.op.typ != null) {
|
|
33069
|
+
// // @ts-ignore
|
|
33070
|
+
// nodes.push(node.op);
|
|
33071
|
+
// // @ts-ignore
|
|
33072
|
+
// nodes.op[PARENT] = node;
|
|
33073
|
+
// }
|
|
33074
|
+
// // @ts-ignore
|
|
33075
|
+
// if (node.r != null) {
|
|
33076
|
+
// // @ts-ignore
|
|
33077
|
+
// if (Array.isArray(node.r)) {
|
|
33078
|
+
// // @ts-ignore
|
|
33079
|
+
// for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33080
|
+
// // @ts-ignore
|
|
33081
|
+
// nodes.push(node.r[i]);
|
|
33082
|
+
// // @ts-ignore
|
|
33083
|
+
// node.r[i][PARENT] = node;
|
|
33084
|
+
// }
|
|
33085
|
+
// } else {
|
|
33086
|
+
// // @ts-ignore
|
|
33087
|
+
// nodes.push(node.r);
|
|
33088
|
+
// // @ts-ignore
|
|
33089
|
+
// node.r[PARENT] = node;
|
|
33090
|
+
// }
|
|
33091
|
+
// }
|
|
33092
|
+
// // @ts-ignore
|
|
33093
|
+
// if (Array.isArray(node.l)) {
|
|
33094
|
+
// // @ts-ignore
|
|
33095
|
+
// for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33096
|
+
// // @ts-ignore
|
|
33097
|
+
// node.l[i][PARENT] = node;
|
|
33098
|
+
// // @ts-ignore
|
|
33099
|
+
// nodes.push(node.l[i]);
|
|
33100
|
+
// }
|
|
33101
|
+
// } else {
|
|
33102
|
+
// // @ts-ignore
|
|
33103
|
+
// nodes.push(node.l);
|
|
33104
|
+
// // @ts-ignore
|
|
33105
|
+
// node.l[PARENT] = node;
|
|
33106
|
+
// }
|
|
33107
|
+
// }
|
|
33108
|
+
}
|
|
33109
|
+
switch (node.typ) {
|
|
33110
|
+
case exports.EnumToken.BinaryExpressionTokenType:
|
|
33111
|
+
case exports.EnumToken.IfElseConditionTokenType:
|
|
33112
|
+
nodes.push(node.r);
|
|
33113
|
+
node.r[PARENT] = node;
|
|
33114
|
+
nodes.push(node.l);
|
|
33115
|
+
node.l[PARENT] = node;
|
|
33116
|
+
break;
|
|
33117
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
33118
|
+
nodes.push(node.r);
|
|
33119
|
+
node.r[PARENT] = node;
|
|
33120
|
+
nodes.push(node.op);
|
|
33121
|
+
node.op[PARENT] = node;
|
|
33122
|
+
nodes.push(node.l);
|
|
33123
|
+
node.l[PARENT] = node;
|
|
33124
|
+
break;
|
|
33125
|
+
case exports.EnumToken.SupportsQueryConditionTokenType:
|
|
33126
|
+
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
33127
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33128
|
+
const element = node.r[i];
|
|
33129
|
+
nodes.push(element);
|
|
33130
|
+
element[PARENT] = node;
|
|
33131
|
+
}
|
|
33132
|
+
nodes.push(node.op);
|
|
33133
|
+
node.op[PARENT] = node;
|
|
33134
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33135
|
+
const element = node.l[i];
|
|
33136
|
+
nodes.push(element);
|
|
33137
|
+
element[PARENT] = node;
|
|
33138
|
+
}
|
|
33139
|
+
break;
|
|
33140
|
+
case exports.EnumToken.WhenElseQueryConditionTokenType:
|
|
33141
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33142
|
+
const element = node.r[i];
|
|
33143
|
+
nodes.push(element);
|
|
33144
|
+
element[PARENT] = node;
|
|
33145
|
+
}
|
|
33146
|
+
nodes.push(node.l);
|
|
33147
|
+
node.l[PARENT] = node;
|
|
33148
|
+
break;
|
|
33149
|
+
case exports.EnumToken.IfConditionTokenType:
|
|
33150
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33151
|
+
const element = node.r[i];
|
|
33152
|
+
nodes.push(element);
|
|
33153
|
+
element[PARENT] = node;
|
|
33154
|
+
}
|
|
33155
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33156
|
+
const element = node.l[i];
|
|
33157
|
+
nodes.push(element);
|
|
33158
|
+
element[PARENT] = node;
|
|
33159
|
+
}
|
|
33160
|
+
break;
|
|
33161
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
33162
|
+
if (node.r != null) {
|
|
33163
|
+
nodes.push(node.r);
|
|
33164
|
+
node.r[PARENT] = node;
|
|
33165
|
+
}
|
|
33166
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33167
|
+
const element = node.l[i];
|
|
33168
|
+
nodes.push(element);
|
|
33169
|
+
element[PARENT] = node;
|
|
33170
|
+
}
|
|
33171
|
+
break;
|
|
33172
|
+
case exports.EnumToken.ContainerStyleRangeTokenType:
|
|
33173
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33174
|
+
const element = node.r[i];
|
|
33175
|
+
nodes.push(element);
|
|
33176
|
+
element[PARENT] = node;
|
|
33177
|
+
}
|
|
33178
|
+
for (let i = node.op.length - 1; i >= 0; i--) {
|
|
33179
|
+
const element = node.op[i];
|
|
33180
|
+
nodes.push(element);
|
|
33181
|
+
element[PARENT] = node;
|
|
33182
|
+
}
|
|
33183
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33184
|
+
const element = node.l[i];
|
|
33185
|
+
nodes.push(element);
|
|
33186
|
+
element[PARENT] = node;
|
|
33187
|
+
}
|
|
33188
|
+
break;
|
|
33189
|
+
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
33190
|
+
for (let i = node.r.length - 1; i >= 0; i--) {
|
|
33191
|
+
const element = node.r[i];
|
|
33192
|
+
nodes.push(element);
|
|
33193
|
+
element[PARENT] = node;
|
|
33194
|
+
}
|
|
33195
|
+
nodes.push(node.op2);
|
|
33196
|
+
node.op2[PARENT] = node;
|
|
33197
|
+
for (let i = node.val.length - 1; i >= 0; i--) {
|
|
33198
|
+
const element = node.val[i];
|
|
33199
|
+
nodes.push(element);
|
|
33200
|
+
element[PARENT] = node;
|
|
33201
|
+
}
|
|
33202
|
+
nodes.push(node.op1);
|
|
33203
|
+
node.op1[PARENT] = node;
|
|
33204
|
+
for (let i = node.l.length - 1; i >= 0; i--) {
|
|
33205
|
+
const element = node.l[i];
|
|
33206
|
+
nodes.push(element);
|
|
33207
|
+
element[PARENT] = node;
|
|
33208
|
+
}
|
|
33209
|
+
break;
|
|
32625
33210
|
}
|
|
32626
33211
|
// @ts-ignore
|
|
32627
|
-
if (
|
|
33212
|
+
if (node.chi != null) {
|
|
33213
|
+
for (
|
|
32628
33214
|
// @ts-ignore
|
|
32629
|
-
|
|
33215
|
+
let i = node.chi.length - 1; i >= 0; i--) {
|
|
32630
33216
|
// @ts-ignore
|
|
32631
|
-
|
|
32632
|
-
}
|
|
32633
|
-
}
|
|
32634
|
-
if (subNodes.length > 0) {
|
|
32635
|
-
if (freeblock <= i) {
|
|
32636
|
-
freeblock = i + 1;
|
|
32637
|
-
}
|
|
32638
|
-
for (k = 0; k < subNodes.length; k++) {
|
|
32639
|
-
j = k + freeblock;
|
|
32640
|
-
nodes[j] = subNodes[k];
|
|
32641
|
-
nodes[j][PARENT] = nodes[i];
|
|
33217
|
+
nodes.push(node.chi[i]);
|
|
32642
33218
|
}
|
|
32643
|
-
freeblock += subNodes.length;
|
|
32644
33219
|
}
|
|
32645
33220
|
parens = null;
|
|
32646
33221
|
handlers.length = 0;
|
|
@@ -32648,23 +33223,23 @@ async function doParse(iter, options = {}) {
|
|
|
32648
33223
|
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
32649
33224
|
}
|
|
32650
33225
|
genericKey =
|
|
32651
|
-
|
|
33226
|
+
node.typ == exports.EnumToken.DeclarationNodeType
|
|
32652
33227
|
? "Declaration"
|
|
32653
|
-
:
|
|
33228
|
+
: node.typ == exports.EnumToken.AtRuleNodeType
|
|
32654
33229
|
? "AtRule"
|
|
32655
|
-
:
|
|
33230
|
+
: node.typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
32656
33231
|
? "KeyframesAtRule"
|
|
32657
|
-
:
|
|
33232
|
+
: node.typ === exports.EnumToken.KeyframesRuleNodeType
|
|
32658
33233
|
? "KeyframesRule"
|
|
32659
|
-
:
|
|
33234
|
+
: node.typ == exports.EnumToken.RuleNodeType
|
|
32660
33235
|
? "Rule"
|
|
32661
|
-
:
|
|
33236
|
+
: node.typ == exports.EnumToken.KeyframesRuleNodeType
|
|
32662
33237
|
? "KeyframesRule"
|
|
32663
33238
|
: null;
|
|
32664
|
-
let keyName =
|
|
32665
|
-
? camelize(
|
|
32666
|
-
:
|
|
32667
|
-
? camelize(
|
|
33239
|
+
let keyName = node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType
|
|
33240
|
+
? camelize(node.nam)
|
|
33241
|
+
: node.typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
33242
|
+
? camelize(node.val)
|
|
32668
33243
|
: null;
|
|
32669
33244
|
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
32670
33245
|
handlers.push(...visitors.allVisitorsHandlers);
|
|
@@ -32677,20 +33252,6 @@ async function doParse(iter, options = {}) {
|
|
|
32677
33252
|
if (typeof handler == "function") {
|
|
32678
33253
|
handlers.push(handler);
|
|
32679
33254
|
}
|
|
32680
|
-
// else if (Array.isArray(handler)) {
|
|
32681
|
-
// for (const h of handler) {
|
|
32682
|
-
// if (typeof h == "function") {
|
|
32683
|
-
// handlers.push(h);
|
|
32684
|
-
// }
|
|
32685
|
-
// // @ts-ignore
|
|
32686
|
-
// else if (h[keyName] != null) {
|
|
32687
|
-
// // @ts-ignore
|
|
32688
|
-
// handlers.push(h[keyName]);
|
|
32689
|
-
// }
|
|
32690
|
-
// }
|
|
32691
|
-
// } else if (typeof handler.handler! == "function") {
|
|
32692
|
-
// handlers.push(handler.handler);
|
|
32693
|
-
// }
|
|
32694
33255
|
// @ts-ignore
|
|
32695
33256
|
else if (typeof handler[keyName] == "function") {
|
|
32696
33257
|
// @ts-ignore
|
|
@@ -32698,10 +33259,9 @@ async function doParse(iter, options = {}) {
|
|
|
32698
33259
|
}
|
|
32699
33260
|
}
|
|
32700
33261
|
}
|
|
32701
|
-
|
|
32702
|
-
if (map.has(nodes[i].typ)) {
|
|
33262
|
+
if (map.has(node.typ)) {
|
|
32703
33263
|
// @ts-ignore
|
|
32704
|
-
for (const handler of map.get(
|
|
33264
|
+
for (const handler of map.get(node.typ)) {
|
|
32705
33265
|
if (typeof handler == "function") {
|
|
32706
33266
|
handlers.push(handler);
|
|
32707
33267
|
}
|
|
@@ -32729,16 +33289,16 @@ async function doParse(iter, options = {}) {
|
|
|
32729
33289
|
if (handlers.length == 0) {
|
|
32730
33290
|
continue;
|
|
32731
33291
|
}
|
|
32732
|
-
let node = nodes[i];
|
|
32733
33292
|
for (const callable of handlers) {
|
|
32734
|
-
replacement = callable(node,
|
|
33293
|
+
replacement = callable(node, node[PARENT], ast,
|
|
32735
33294
|
// @ts-expect-error
|
|
32736
33295
|
function* () {
|
|
32737
33296
|
if (parens == null) {
|
|
32738
|
-
let
|
|
32739
|
-
|
|
32740
|
-
|
|
32741
|
-
|
|
33297
|
+
let parent = node[PARENT];
|
|
33298
|
+
// let node = node[PARENT] as AstNode;
|
|
33299
|
+
while (parent != null) {
|
|
33300
|
+
yield parent;
|
|
33301
|
+
parent = parent[PARENT];
|
|
32742
33302
|
}
|
|
32743
33303
|
}
|
|
32744
33304
|
});
|
|
@@ -32752,37 +33312,37 @@ async function doParse(iter, options = {}) {
|
|
|
32752
33312
|
continue;
|
|
32753
33313
|
}
|
|
32754
33314
|
// @ts-ignore
|
|
32755
|
-
node = replacement;
|
|
33315
|
+
// node = replacement as AstNode;
|
|
32756
33316
|
//
|
|
32757
|
-
if (Array.isArray(
|
|
33317
|
+
if (Array.isArray(replacement)) {
|
|
32758
33318
|
break;
|
|
32759
33319
|
}
|
|
32760
33320
|
}
|
|
32761
|
-
|
|
33321
|
+
// @ts-ignore
|
|
33322
|
+
if (replacement != null && node != replacement) {
|
|
33323
|
+
console.error({
|
|
33324
|
+
node,
|
|
33325
|
+
replacement,
|
|
33326
|
+
});
|
|
32762
33327
|
// @ts-ignore
|
|
32763
|
-
replaceNodeOrValue(
|
|
33328
|
+
replaceNodeOrValue(node[PARENT], node, replacement);
|
|
32764
33329
|
}
|
|
32765
33330
|
}
|
|
32766
33331
|
nodes = null;
|
|
32767
33332
|
}
|
|
32768
33333
|
if (invalidNodes.length > 0) {
|
|
32769
|
-
|
|
32770
|
-
for (const { node, parent } of walk(ast)) {
|
|
33334
|
+
for (const node of invalidNodes) {
|
|
32771
33335
|
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
32772
33336
|
continue;
|
|
32773
33337
|
}
|
|
32774
|
-
if (node[STATE] &
|
|
32775
|
-
|
|
32776
|
-
|
|
32777
|
-
|
|
32778
|
-
|
|
33338
|
+
if (node[STATE] &
|
|
33339
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33340
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33341
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33342
|
+
exports.EnumAstNodeStatus.Malformed |
|
|
33343
|
+
exports.EnumAstNodeStatus.Disallowed)) {
|
|
32779
33344
|
// @ts-ignore
|
|
32780
|
-
|
|
32781
|
-
node[PARENT] = null;
|
|
32782
|
-
count--;
|
|
32783
|
-
if (count == 0) {
|
|
32784
|
-
break;
|
|
32785
|
-
}
|
|
33345
|
+
node[PARENT].chi.splice(node[PARENT].chi.indexOf(node), 1);
|
|
32786
33346
|
}
|
|
32787
33347
|
}
|
|
32788
33348
|
}
|
|
@@ -32908,6 +33468,7 @@ async function doParse(iter, options = {}) {
|
|
|
32908
33468
|
}
|
|
32909
33469
|
// @ts-ignore
|
|
32910
33470
|
if (node.typ == exports.EnumToken.CssVariableDeclarationMapTokenType) {
|
|
33471
|
+
// @ts-ignore
|
|
32911
33472
|
const from = node.from.find((t) => t.typ == exports.EnumToken.IdenTokenType || isIdentColor(t));
|
|
32912
33473
|
if (!(from.val in cssVariablesMap)) {
|
|
32913
33474
|
errors.push({
|
|
@@ -32917,6 +33478,7 @@ async function doParse(iter, options = {}) {
|
|
|
32917
33478
|
});
|
|
32918
33479
|
}
|
|
32919
33480
|
else {
|
|
33481
|
+
// @ts-ignore
|
|
32920
33482
|
for (const token of node.vars) {
|
|
32921
33483
|
if (token.typ == exports.EnumToken.IdenTokenType || isIdentColor(token)) {
|
|
32922
33484
|
if (!(token.val in cssVariablesMap[from.val])) {
|
|
@@ -32940,6 +33502,7 @@ async function doParse(iter, options = {}) {
|
|
|
32940
33502
|
if (result.cssModuleVariables == null) {
|
|
32941
33503
|
result.cssModuleVariables = {};
|
|
32942
33504
|
}
|
|
33505
|
+
// @ts-ignore
|
|
32943
33506
|
result.cssModuleVariables[node.nam] = node;
|
|
32944
33507
|
}
|
|
32945
33508
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
@@ -33180,7 +33743,8 @@ async function doParse(iter, options = {}) {
|
|
|
33180
33743
|
value.val = mapping[idenToken];
|
|
33181
33744
|
}
|
|
33182
33745
|
}
|
|
33183
|
-
else if (node.nam == "grid-template-areas" ||
|
|
33746
|
+
else if (node.nam == "grid-template-areas" ||
|
|
33747
|
+
node.nam == "grid-template") {
|
|
33184
33748
|
for (let i = 0; i < node.val.length; i++) {
|
|
33185
33749
|
if (node.val[i].typ == exports.EnumToken.String) {
|
|
33186
33750
|
const tokens = parseString(node.val[i].val.slice(1, -1));
|
|
@@ -33211,7 +33775,8 @@ async function doParse(iter, options = {}) {
|
|
|
33211
33775
|
}
|
|
33212
33776
|
}
|
|
33213
33777
|
}
|
|
33214
|
-
else if (node.nam == "animation" ||
|
|
33778
|
+
else if (node.nam == "animation" ||
|
|
33779
|
+
node.nam == "animation-name") {
|
|
33215
33780
|
for (const { value } of walkValues(node.val, node)) {
|
|
33216
33781
|
if (value.typ == exports.EnumToken.IdenTokenType &&
|
|
33217
33782
|
![
|
|
@@ -33606,7 +34171,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
33606
34171
|
else if (context.typ === exports.EnumToken.AtRuleNodeType &&
|
|
33607
34172
|
"page" === context.nam &&
|
|
33608
34173
|
pageMarginBoxType.has(atRuleName.toLowerCase())) {
|
|
33609
|
-
if (parseAsBlock === false) {
|
|
34174
|
+
if (parseAsBlock === false && syntaxRules.optionalBody === false) {
|
|
33610
34175
|
errors.push({
|
|
33611
34176
|
action: "drop",
|
|
33612
34177
|
node: atRule,
|
|
@@ -33645,7 +34210,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
33645
34210
|
if (parseAsBlock === null) {
|
|
33646
34211
|
parseAsBlock = blockAllowed;
|
|
33647
34212
|
}
|
|
33648
|
-
if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed) {
|
|
34213
|
+
if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed && !syntaxRules.optionalBody) {
|
|
33649
34214
|
errors.push({
|
|
33650
34215
|
action: "drop",
|
|
33651
34216
|
node: atRule,
|
|
@@ -34315,6 +34880,50 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
|
|
|
34315
34880
|
atRule[TOKENS] = stream.slice();
|
|
34316
34881
|
atRule[STATE] = result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.Invalid;
|
|
34317
34882
|
atRule[ERRORS] = result.errors;
|
|
34883
|
+
switch (atRule.nam) {
|
|
34884
|
+
case "mixin":
|
|
34885
|
+
if (context != null && context.typ != exports.EnumToken.StyleSheetNodeType) {
|
|
34886
|
+
atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
|
|
34887
|
+
atRule[ERRORS].push({
|
|
34888
|
+
message: "mixin rule cannot be a nested group rule or rule style body",
|
|
34889
|
+
location: atRule[LOCSTA],
|
|
34890
|
+
});
|
|
34891
|
+
}
|
|
34892
|
+
break;
|
|
34893
|
+
case "contents":
|
|
34894
|
+
let parent = context;
|
|
34895
|
+
let valid = parent == null;
|
|
34896
|
+
while (parent != null) {
|
|
34897
|
+
if (parent.typ == exports.EnumToken.AtRuleNodeType && "mixin" == parent.nam) {
|
|
34898
|
+
valid = true;
|
|
34899
|
+
break;
|
|
34900
|
+
}
|
|
34901
|
+
parent = parent[PARENT];
|
|
34902
|
+
}
|
|
34903
|
+
if (!valid) {
|
|
34904
|
+
atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
|
|
34905
|
+
atRule[ERRORS].push({
|
|
34906
|
+
message: "contents rule cannot be used outside mixin rule",
|
|
34907
|
+
location: atRule[LOCSTA],
|
|
34908
|
+
});
|
|
34909
|
+
}
|
|
34910
|
+
break;
|
|
34911
|
+
case "layer":
|
|
34912
|
+
if (context != null && context.typ != exports.EnumToken.StyleSheetNodeType) {
|
|
34913
|
+
let parent = context;
|
|
34914
|
+
while (parent != null) {
|
|
34915
|
+
if (parent.typ == exports.EnumToken.AtRuleNodeType && parent.nam == "mixin") {
|
|
34916
|
+
atRule[STATE] |= exports.EnumAstNodeStatus.Disallowed;
|
|
34917
|
+
atRule[ERRORS].push({
|
|
34918
|
+
message: "at-rule layeris not allowed inside mixin rule",
|
|
34919
|
+
location: atRule[LOCSTA],
|
|
34920
|
+
});
|
|
34921
|
+
break;
|
|
34922
|
+
}
|
|
34923
|
+
parent = parent[PARENT];
|
|
34924
|
+
}
|
|
34925
|
+
}
|
|
34926
|
+
}
|
|
34318
34927
|
// @ts-expect-error
|
|
34319
34928
|
return Object.assign(atRule, {
|
|
34320
34929
|
typ: exports.EnumToken.AtRuleNodeType,
|
|
@@ -34774,7 +35383,7 @@ function setNodeProperty(node, key, value) {
|
|
|
34774
35383
|
}
|
|
34775
35384
|
}
|
|
34776
35385
|
|
|
34777
|
-
var version = "1.
|
|
35386
|
+
var version = "1.8.1";
|
|
34778
35387
|
|
|
34779
35388
|
/**
|
|
34780
35389
|
* Load file or url
|
|
@@ -35251,6 +35860,7 @@ exports.parseDeclarations = parseDeclarations;
|
|
|
35251
35860
|
exports.parseFile = parseFile;
|
|
35252
35861
|
exports.parseString = parseString;
|
|
35253
35862
|
exports.parseSync = parseSync;
|
|
35863
|
+
exports.parseSyntax = parseSyntax;
|
|
35254
35864
|
exports.render = render;
|
|
35255
35865
|
exports.renderToken = renderValue;
|
|
35256
35866
|
exports.replaceNodeOrValue = replaceNodeOrValue;
|