@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import config from '../../data/validation.json.js';
|
|
@@ -77,8 +77,8 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
let block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
|
|
81
|
+
let prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
|
|
82
82
|
let propertyDescriptors = null;
|
|
83
83
|
// @ts-expect-error
|
|
84
84
|
if (node.descriptors != null) {
|
|
@@ -89,7 +89,24 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
89
89
|
propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
let optionalBody = false;
|
|
93
|
+
if (block == null || block.length === 0) {
|
|
94
|
+
let k = prelude.length - 1;
|
|
95
|
+
if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
|
|
96
|
+
k--;
|
|
97
|
+
}
|
|
98
|
+
if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
|
|
99
|
+
if (prelude[k].chi[0].typ ===
|
|
100
|
+
ValidationTokenEnum.OpenCurlyBrace &&
|
|
101
|
+
prelude[k].chi.at(-1).typ ===
|
|
102
|
+
ValidationTokenEnum.CloseCurlyBrace) {
|
|
103
|
+
block = prelude[k].chi.slice(1, -1);
|
|
104
|
+
optionalBody = prelude[k].isOptional ?? false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
92
108
|
return {
|
|
109
|
+
optionalBody,
|
|
93
110
|
acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
|
|
94
111
|
acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
|
|
95
112
|
node.syntax.includes("<stylesheet>"),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getParsedSyntax, getSyntaxConfig } from './config.js';
|
|
@@ -50,15 +50,6 @@ function trimArray(tokens) {
|
|
|
50
50
|
}
|
|
51
51
|
return tokens;
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
54
|
-
* is a media feature
|
|
55
|
-
* @param featureName
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
// export function isMFName(featureName: string): boolean {
|
|
59
|
-
// // @ts-expect-error
|
|
60
|
-
// return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
|
|
61
|
-
// }
|
|
62
53
|
/**
|
|
63
54
|
*
|
|
64
55
|
* @param featureName
|
|
@@ -579,9 +570,6 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
|
|
|
579
570
|
case EnumToken.NumberTokenType:
|
|
580
571
|
case EnumToken.LiteralTokenType:
|
|
581
572
|
case EnumToken.DimensionTokenType:
|
|
582
|
-
// if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
|
|
583
|
-
// stack.pop();
|
|
584
|
-
// }
|
|
585
573
|
if (stack.at(-1)?.typ === EnumToken.PseudoClassFunctionTokenDefType) {
|
|
586
574
|
break;
|
|
587
575
|
}
|
|
@@ -850,43 +838,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
850
838
|
continue;
|
|
851
839
|
}
|
|
852
840
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
|
|
857
|
-
syntaxes[i + 2]?.typ == null) {
|
|
858
|
-
if (!isOptional) {
|
|
859
|
-
return {
|
|
860
|
-
success: false,
|
|
861
|
-
errors: [
|
|
862
|
-
{
|
|
863
|
-
action: "drop",
|
|
864
|
-
message: "could not match syntax",
|
|
865
|
-
node: token,
|
|
866
|
-
syntax: syntaxes[i],
|
|
867
|
-
},
|
|
868
|
-
],
|
|
869
|
-
syntaxToken: syntaxes[i],
|
|
870
|
-
valid: true,
|
|
871
|
-
context,
|
|
872
|
-
token: null,
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
break;
|
|
876
|
-
}
|
|
877
|
-
const range = trimArray(context.peekRange());
|
|
878
|
-
context.next();
|
|
879
|
-
i++;
|
|
880
|
-
result = matchSyntax([syntaxes[i + 1]], createValidationContext(range.slice(1, -1)), options);
|
|
881
|
-
if (result.success) {
|
|
882
|
-
context.update(range.at(-1));
|
|
883
|
-
i += 2;
|
|
884
|
-
}
|
|
885
|
-
return result;
|
|
886
|
-
}
|
|
887
|
-
if (tokensfuncDefMap.has(token.typ) &&
|
|
888
|
-
// @ts-ignore
|
|
889
|
-
token.typ === EnumToken.WildCardFunctionTokenDefType) {
|
|
841
|
+
if (
|
|
842
|
+
// @ts-ignore
|
|
843
|
+
token.typ === EnumToken.WildCardFunctionTokenDefType) {
|
|
890
844
|
const range = trimArray(context.peekRange());
|
|
891
845
|
result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(range.slice(1, -1)), options);
|
|
892
846
|
if (result.success) {
|
|
@@ -911,6 +865,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
911
865
|
context.update(result.context.current());
|
|
912
866
|
continue;
|
|
913
867
|
}
|
|
868
|
+
if (isOptional) {
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
914
871
|
return result;
|
|
915
872
|
}
|
|
916
873
|
if (syntaxes[i].isList) {
|
|
@@ -931,6 +888,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
931
888
|
context.update(result.context.current());
|
|
932
889
|
continue;
|
|
933
890
|
}
|
|
891
|
+
if (isOptional) {
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
934
894
|
return {
|
|
935
895
|
success: false,
|
|
936
896
|
valid: true,
|
|
@@ -955,6 +915,9 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
955
915
|
context.update(result.context.current());
|
|
956
916
|
continue;
|
|
957
917
|
}
|
|
918
|
+
if (isOptional) {
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
958
921
|
return {
|
|
959
922
|
success: false,
|
|
960
923
|
valid: true,
|
|
@@ -1359,6 +1322,20 @@ function matchSyntax(syntaxes, context, options) {
|
|
|
1359
1322
|
syntaxToken: syntaxes[i],
|
|
1360
1323
|
errors: [],
|
|
1361
1324
|
};
|
|
1325
|
+
case ValidationTokenEnum.OpenCurlyBrace:
|
|
1326
|
+
if (token.typ === EnumToken.BlockStartTokenType) {
|
|
1327
|
+
options.visited.get(token).delete(syntaxes[i]);
|
|
1328
|
+
context.next();
|
|
1329
|
+
break;
|
|
1330
|
+
}
|
|
1331
|
+
return {
|
|
1332
|
+
success: false,
|
|
1333
|
+
valid: true,
|
|
1334
|
+
token,
|
|
1335
|
+
context,
|
|
1336
|
+
syntaxToken: syntaxes[i],
|
|
1337
|
+
errors: [],
|
|
1338
|
+
};
|
|
1362
1339
|
case ValidationTokenEnum.CloseParenthesis:
|
|
1363
1340
|
if (token.typ === EnumToken.EndParensTokenType) {
|
|
1364
1341
|
options.visited.get(token).delete(syntaxes[i]);
|
|
@@ -1560,6 +1537,7 @@ function matchProperty(property, context, options) {
|
|
|
1560
1537
|
};
|
|
1561
1538
|
}
|
|
1562
1539
|
switch (property.val) {
|
|
1540
|
+
case "function-parameter":
|
|
1563
1541
|
case "declaration-value":
|
|
1564
1542
|
{
|
|
1565
1543
|
// consume a declaration value
|
|
@@ -1569,18 +1547,43 @@ function matchProperty(property, context, options) {
|
|
|
1569
1547
|
// if semicolon or end curly brace is encountered, stop
|
|
1570
1548
|
let expectToken = true;
|
|
1571
1549
|
let token;
|
|
1550
|
+
const stack = [];
|
|
1572
1551
|
token = context.peek();
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
expectToken
|
|
1552
|
+
if (token != null) {
|
|
1553
|
+
success = false;
|
|
1554
|
+
while ((token = context.peek()) != null) {
|
|
1555
|
+
if (token.typ == EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
|
|
1556
|
+
stack.push(token);
|
|
1557
|
+
}
|
|
1558
|
+
if (expectToken) {
|
|
1559
|
+
expectToken = false;
|
|
1560
|
+
}
|
|
1561
|
+
if (token.typ == EnumToken.CommaTokenType) {
|
|
1562
|
+
expectToken = true;
|
|
1563
|
+
}
|
|
1564
|
+
if (token.typ == EnumToken.EndParensTokenType) {
|
|
1565
|
+
if (stack.length > 0) {
|
|
1566
|
+
stack.pop();
|
|
1567
|
+
}
|
|
1568
|
+
else {
|
|
1569
|
+
expectToken = false;
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
context.next();
|
|
1580
1574
|
}
|
|
1581
|
-
context.next();
|
|
1582
1575
|
}
|
|
1583
1576
|
success = !expectToken;
|
|
1577
|
+
if (success) {
|
|
1578
|
+
return {
|
|
1579
|
+
success,
|
|
1580
|
+
valid: true,
|
|
1581
|
+
token: null,
|
|
1582
|
+
context,
|
|
1583
|
+
syntaxToken: property,
|
|
1584
|
+
errors: [],
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1584
1587
|
}
|
|
1585
1588
|
break;
|
|
1586
1589
|
case "calc-sum": {
|
|
@@ -1613,9 +1616,6 @@ function matchProperty(property, context, options) {
|
|
|
1613
1616
|
}
|
|
1614
1617
|
break;
|
|
1615
1618
|
}
|
|
1616
|
-
// case "at-keyword-token":
|
|
1617
|
-
// success = context.peek()?.typ === EnumToken.AtRuleTokenType;
|
|
1618
|
-
// break;
|
|
1619
1619
|
case "an+b":
|
|
1620
1620
|
{
|
|
1621
1621
|
let token = context.peek();
|
|
@@ -1680,9 +1680,6 @@ function matchProperty(property, context, options) {
|
|
|
1680
1680
|
Object.assign(token, { typ: EnumToken.Add });
|
|
1681
1681
|
}
|
|
1682
1682
|
token = context.peek(2);
|
|
1683
|
-
// if (token == null) {
|
|
1684
|
-
// break;
|
|
1685
|
-
// }
|
|
1686
1683
|
if (token?.typ === EnumToken.NumberTokenType &&
|
|
1687
1684
|
Number.isInteger(token.val) &&
|
|
1688
1685
|
!token.toString().includes(".") &&
|
|
@@ -1790,9 +1787,6 @@ function matchProperty(property, context, options) {
|
|
|
1790
1787
|
break;
|
|
1791
1788
|
case "dimension": {
|
|
1792
1789
|
const token = context.peek();
|
|
1793
|
-
// if (token == null) {
|
|
1794
|
-
// break;
|
|
1795
|
-
// }
|
|
1796
1790
|
success =
|
|
1797
1791
|
token?.typ == EnumToken.DimensionTokenType ||
|
|
1798
1792
|
token?.typ == EnumToken.AngleTokenType ||
|
|
@@ -1801,25 +1795,20 @@ function matchProperty(property, context, options) {
|
|
|
1801
1795
|
token?.typ == EnumToken.ResolutionTokenType ||
|
|
1802
1796
|
token?.typ == EnumToken.TimeTokenType ||
|
|
1803
1797
|
token?.typ == EnumToken.FrequencyTokenType ||
|
|
1798
|
+
token?.typ == EnumToken.UserDefinedDimensionTokenType ||
|
|
1804
1799
|
token?.typ == EnumToken.FlexTokenType;
|
|
1805
1800
|
break;
|
|
1806
1801
|
}
|
|
1807
1802
|
case "angle":
|
|
1808
1803
|
{
|
|
1809
1804
|
const token = context.peek();
|
|
1810
|
-
|
|
1811
|
-
// break;
|
|
1812
|
-
// }
|
|
1813
|
-
success = token?.typ === EnumToken.AngleTokenType;
|
|
1805
|
+
success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.UserDefinedDimensionTokenType;
|
|
1814
1806
|
}
|
|
1815
1807
|
break;
|
|
1816
1808
|
case "angle-percentage":
|
|
1817
1809
|
{
|
|
1818
1810
|
const token = context.peek();
|
|
1819
|
-
|
|
1820
|
-
// break;
|
|
1821
|
-
// }
|
|
1822
|
-
success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.PercentageTokenType;
|
|
1811
|
+
success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.UserDefinedDimensionTokenType || token?.typ === EnumToken.PercentageTokenType;
|
|
1823
1812
|
}
|
|
1824
1813
|
break;
|
|
1825
1814
|
case "percentage":
|
|
@@ -1834,25 +1823,21 @@ function matchProperty(property, context, options) {
|
|
|
1834
1823
|
case "length-percentage":
|
|
1835
1824
|
{
|
|
1836
1825
|
const token = context.peek();
|
|
1837
|
-
// if (token == null) {
|
|
1838
|
-
// break;
|
|
1839
|
-
// }
|
|
1840
1826
|
success =
|
|
1841
1827
|
token?.typ == EnumToken.PercentageTokenType ||
|
|
1842
1828
|
token?.typ == EnumToken.LengthTokenType ||
|
|
1829
|
+
token?.typ == EnumToken.UserDefinedDimensionTokenType ||
|
|
1843
1830
|
(token?.typ == EnumToken.NumberTokenType && token?.val === 0);
|
|
1844
1831
|
}
|
|
1845
1832
|
break;
|
|
1846
1833
|
case "flex":
|
|
1847
|
-
success = context.peek()?.typ == EnumToken.FlexTokenType;
|
|
1834
|
+
success = context.peek()?.typ == EnumToken.FlexTokenType || context.peek()?.typ == EnumToken.UserDefinedDimensionTokenType;
|
|
1848
1835
|
break;
|
|
1849
1836
|
case "length": {
|
|
1850
1837
|
const token = context.peek();
|
|
1851
|
-
// if (token == null) {
|
|
1852
|
-
// break;
|
|
1853
|
-
// }
|
|
1854
1838
|
success =
|
|
1855
1839
|
token?.typ == EnumToken.LengthTokenType ||
|
|
1840
|
+
token?.typ == EnumToken.UserDefinedDimensionTokenType ||
|
|
1856
1841
|
(token?.typ == EnumToken.NumberTokenType && token?.val === 0);
|
|
1857
1842
|
break;
|
|
1858
1843
|
}
|
|
@@ -1862,15 +1847,9 @@ function matchProperty(property, context, options) {
|
|
|
1862
1847
|
if (token == null) {
|
|
1863
1848
|
break;
|
|
1864
1849
|
}
|
|
1865
|
-
success = token.typ == EnumToken.TimeTokenType;
|
|
1850
|
+
success = token.typ == EnumToken.TimeTokenType || token.typ == EnumToken.UserDefinedDimensionTokenType;
|
|
1866
1851
|
}
|
|
1867
1852
|
break;
|
|
1868
|
-
// case "hex-color": {
|
|
1869
|
-
// const token = context.peek();
|
|
1870
|
-
// success =
|
|
1871
|
-
// token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
|
|
1872
|
-
// break;
|
|
1873
|
-
// }
|
|
1874
1853
|
case "color":
|
|
1875
1854
|
case "color-function":
|
|
1876
1855
|
{
|
|
@@ -1878,13 +1857,6 @@ function matchProperty(property, context, options) {
|
|
|
1878
1857
|
const errors = [];
|
|
1879
1858
|
if (tokensfuncDefMap.has(token?.typ)) {
|
|
1880
1859
|
const range = context.peekRange();
|
|
1881
|
-
// if (
|
|
1882
|
-
// range.some(
|
|
1883
|
-
// (token) =>
|
|
1884
|
-
// token.typ == EnumToken.IdenTokenType &&
|
|
1885
|
-
// "hslrgbchwmyk".split("").some((t) => equalsIgnoreCase(t, (token as IdentToken).val)),
|
|
1886
|
-
// )
|
|
1887
|
-
// ) {
|
|
1888
1860
|
const newRange = range.map((t) => cloneNode(t, true));
|
|
1889
1861
|
// @ts-ignore
|
|
1890
1862
|
parseTokens(newRange, { parseColor: true }, errors);
|
|
@@ -1909,27 +1881,6 @@ function matchProperty(property, context, options) {
|
|
|
1909
1881
|
syntaxToken: null,
|
|
1910
1882
|
errors,
|
|
1911
1883
|
};
|
|
1912
|
-
// }
|
|
1913
|
-
// const result = matchSyntax(
|
|
1914
|
-
// getParsedSyntax(
|
|
1915
|
-
// ValidationSyntaxGroupEnum.Syntaxes,
|
|
1916
|
-
// (token as FunctionToken).val + "()",
|
|
1917
|
-
// ) as ValidationFunctionToken[],
|
|
1918
|
-
// createValidationContext(range),
|
|
1919
|
-
// options,
|
|
1920
|
-
// );
|
|
1921
|
-
// if (result.success) {
|
|
1922
|
-
// context.update(range.at(-1) as Token);
|
|
1923
|
-
// return {
|
|
1924
|
-
// success: true,
|
|
1925
|
-
// valid: true,
|
|
1926
|
-
// token: context.peek(),
|
|
1927
|
-
// context,
|
|
1928
|
-
// syntaxToken: null,
|
|
1929
|
-
// errors: [],
|
|
1930
|
-
// };
|
|
1931
|
-
// }
|
|
1932
|
-
// return result;
|
|
1933
1884
|
}
|
|
1934
1885
|
// @ts-expect-error
|
|
1935
1886
|
else if ("chi" in token) {
|
|
@@ -1948,10 +1899,6 @@ function matchProperty(property, context, options) {
|
|
|
1948
1899
|
}
|
|
1949
1900
|
}
|
|
1950
1901
|
break;
|
|
1951
|
-
// case "url-token":
|
|
1952
|
-
// success =
|
|
1953
|
-
// context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
|
|
1954
|
-
// break;
|
|
1955
1902
|
case "type-selector":
|
|
1956
1903
|
case "compound-selector":
|
|
1957
1904
|
case "complex-selector":
|
|
@@ -1976,15 +1923,6 @@ function matchProperty(property, context, options) {
|
|
|
1976
1923
|
};
|
|
1977
1924
|
}
|
|
1978
1925
|
case "function-token":
|
|
1979
|
-
// if (
|
|
1980
|
-
// context.peek()?.typ == EnumToken.IdenTokenType &&
|
|
1981
|
-
// context.peek(1, false)?.typ == EnumToken.StartParensTokenType
|
|
1982
|
-
// ) {
|
|
1983
|
-
// context.next();
|
|
1984
|
-
// context.next();
|
|
1985
|
-
// success = true;
|
|
1986
|
-
// break;
|
|
1987
|
-
// }
|
|
1988
1926
|
if (tokensfuncDefMap.has(context.peek()?.typ)) {
|
|
1989
1927
|
success = true;
|
|
1990
1928
|
context.next();
|
|
@@ -2006,17 +1944,6 @@ function matchProperty(property, context, options) {
|
|
|
2006
1944
|
config.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
|
|
2007
1945
|
break;
|
|
2008
1946
|
}
|
|
2009
|
-
// case "named-color": {
|
|
2010
|
-
// const token = context.peek();
|
|
2011
|
-
// success =
|
|
2012
|
-
// token != null &&
|
|
2013
|
-
// token.typ == EnumToken.ColorTokenType &&
|
|
2014
|
-
// ((token as ColorToken).kin == ColorType.LIT ||
|
|
2015
|
-
// (token as ColorToken).kin == ColorType.SYS ||
|
|
2016
|
-
// (token as ColorToken).kin == ColorType.DPSYS ||
|
|
2017
|
-
// (token as ColorToken).kin == ColorType.NON_STD);
|
|
2018
|
-
// break;
|
|
2019
|
-
// }
|
|
2020
1947
|
case "size-feature": {
|
|
2021
1948
|
const range = context.peekRange();
|
|
2022
1949
|
const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
@@ -2047,20 +1974,6 @@ function matchProperty(property, context, options) {
|
|
|
2047
1974
|
errors: [],
|
|
2048
1975
|
};
|
|
2049
1976
|
}
|
|
2050
|
-
// if (filteredRange.length === 3) {
|
|
2051
|
-
// success = isValue(filteredRange[2]);
|
|
2052
|
-
// if (success) {
|
|
2053
|
-
// context.update(filteredRange[2]);
|
|
2054
|
-
// return {
|
|
2055
|
-
// success,
|
|
2056
|
-
// valid: true,
|
|
2057
|
-
// token: filteredRange[2],
|
|
2058
|
-
// context,
|
|
2059
|
-
// syntaxToken: property,
|
|
2060
|
-
// errors: [],
|
|
2061
|
-
// };
|
|
2062
|
-
// }
|
|
2063
|
-
// }
|
|
2064
1977
|
break;
|
|
2065
1978
|
}
|
|
2066
1979
|
case "style-feature": {
|
|
@@ -2070,16 +1983,6 @@ function matchProperty(property, context, options) {
|
|
|
2070
1983
|
// match <style-range>
|
|
2071
1984
|
const range = context.peekRange();
|
|
2072
1985
|
const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
2073
|
-
// if (filteredRange.length === 0) {
|
|
2074
|
-
// return {
|
|
2075
|
-
// success: false,
|
|
2076
|
-
// valid: true,
|
|
2077
|
-
// token: context.peek(),
|
|
2078
|
-
// context,
|
|
2079
|
-
// syntaxToken: property,
|
|
2080
|
-
// errors: [],
|
|
2081
|
-
// };
|
|
2082
|
-
// }
|
|
2083
1986
|
if (filteredRange.length === 1) {
|
|
2084
1987
|
success =
|
|
2085
1988
|
filteredRange[0].typ === EnumToken.IdenTokenType ||
|
|
@@ -2094,31 +1997,6 @@ function matchProperty(property, context, options) {
|
|
|
2094
1997
|
errors: [],
|
|
2095
1998
|
};
|
|
2096
1999
|
}
|
|
2097
|
-
// if (
|
|
2098
|
-
// filteredRange[1]?.typ === EnumToken.ColonTokenType ||
|
|
2099
|
-
// filteredRange[1]?.typ === EnumToken.DelimTokenType
|
|
2100
|
-
// ) {
|
|
2101
|
-
// const result = isDeclarationValue(filteredRange.slice(2));
|
|
2102
|
-
// if (result.success) {
|
|
2103
|
-
// context.update(filteredRange.at(-1)!);
|
|
2104
|
-
// return {
|
|
2105
|
-
// success: true,
|
|
2106
|
-
// valid: true,
|
|
2107
|
-
// token: filteredRange.at(-1)!,
|
|
2108
|
-
// context,
|
|
2109
|
-
// syntaxToken: property,
|
|
2110
|
-
// errors: [],
|
|
2111
|
-
// };
|
|
2112
|
-
// }
|
|
2113
|
-
// return {
|
|
2114
|
-
// success: false,
|
|
2115
|
-
// valid: false,
|
|
2116
|
-
// token: context.peek(),
|
|
2117
|
-
// context,
|
|
2118
|
-
// syntaxToken: property,
|
|
2119
|
-
// errors: result.errors,
|
|
2120
|
-
// };
|
|
2121
|
-
// }
|
|
2122
2000
|
return {
|
|
2123
2001
|
success: false,
|
|
2124
2002
|
valid: false,
|
|
@@ -2130,10 +2008,6 @@ function matchProperty(property, context, options) {
|
|
|
2130
2008
|
}
|
|
2131
2009
|
case "url": {
|
|
2132
2010
|
const token = context.peek();
|
|
2133
|
-
// if (token == null) {
|
|
2134
|
-
// success = false;
|
|
2135
|
-
// break;
|
|
2136
|
-
// }
|
|
2137
2011
|
let l;
|
|
2138
2012
|
if (token?.typ == EnumToken.UrlFunctionTokenDefType) {
|
|
2139
2013
|
l = 0;
|
|
@@ -2147,11 +2021,6 @@ function matchProperty(property, context, options) {
|
|
|
2147
2021
|
(token.typ == EnumToken.StringTokenType ||
|
|
2148
2022
|
token.typ == EnumToken.IdenTokenType ||
|
|
2149
2023
|
token.typ == EnumToken.UrlTokenTokenType)) {
|
|
2150
|
-
// if (token.typ === EnumToken.IdenTokenType) {
|
|
2151
|
-
// while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
|
|
2152
|
-
// l++;
|
|
2153
|
-
// }
|
|
2154
|
-
// }
|
|
2155
2024
|
while ((token = context.peek(++l))) {
|
|
2156
2025
|
if (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType) {
|
|
2157
2026
|
break;
|
|
@@ -2215,10 +2084,46 @@ function matchProperty(property, context, options) {
|
|
|
2215
2084
|
}
|
|
2216
2085
|
break;
|
|
2217
2086
|
}
|
|
2087
|
+
case "dashed-function": {
|
|
2088
|
+
const token = context.peek();
|
|
2089
|
+
success = token?.typ == EnumToken.CustomFunctionTokenDefType;
|
|
2090
|
+
if (success) {
|
|
2091
|
+
context.next();
|
|
2092
|
+
return {
|
|
2093
|
+
success: true,
|
|
2094
|
+
valid: true,
|
|
2095
|
+
token,
|
|
2096
|
+
context,
|
|
2097
|
+
syntaxToken: null,
|
|
2098
|
+
errors: [],
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
break;
|
|
2102
|
+
}
|
|
2103
|
+
case "block-contents":
|
|
2104
|
+
success = context.peek()?.typ == EnumToken.StartParensTokenType;
|
|
2105
|
+
if (success) {
|
|
2106
|
+
context.next();
|
|
2107
|
+
return {
|
|
2108
|
+
success: true,
|
|
2109
|
+
valid: true,
|
|
2110
|
+
token: null,
|
|
2111
|
+
context,
|
|
2112
|
+
syntaxToken: null,
|
|
2113
|
+
errors: [],
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
return {
|
|
2117
|
+
success: false,
|
|
2118
|
+
valid: true,
|
|
2119
|
+
token,
|
|
2120
|
+
context,
|
|
2121
|
+
syntaxToken: property,
|
|
2122
|
+
errors: [],
|
|
2123
|
+
};
|
|
2218
2124
|
default:
|
|
2219
2125
|
if (!(property.val in config.syntaxes)) {
|
|
2220
2126
|
console.debug("Unknown syntax", context.peek(), property);
|
|
2221
|
-
console.debug(context.getRemainingTokens());
|
|
2222
2127
|
throw new Error(`Unexpected validation property ${property.val}`);
|
|
2223
2128
|
}
|
|
2224
2129
|
return matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
|
-
import { isIdentStart, isIdent, parseDimension, isPseudo } from '../../syntax/syntax.js';
|
|
10
|
-
import { ValidationTokenEnum } from './typedef.js';
|
|
11
9
|
import { LOC } from '../../syntax/constants.js';
|
|
10
|
+
import { ValidationTokenEnum } from './typedef.js';
|
|
11
|
+
import { isIdentStart, isIdent, parseDimension, isPseudo } from '../../syntax/syntax.js';
|
|
12
12
|
|
|
13
13
|
const SymbolsMapTokens = {
|
|
14
14
|
"&&": ValidationTokenEnum.Ampersand,
|
|
@@ -264,6 +264,11 @@ function* tokenizeSyntax(syntax, position = {
|
|
|
264
264
|
[LOC]: { ...position },
|
|
265
265
|
};
|
|
266
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* parse mdn data syntax
|
|
269
|
+
* @param syntax
|
|
270
|
+
* @returns
|
|
271
|
+
*/
|
|
267
272
|
function parseSyntax(syntax) {
|
|
268
273
|
const stack = [];
|
|
269
274
|
let tokens = [];
|
package/dist/src/node.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { deprecate } from 'node:util';
|
|
@@ -33,6 +33,7 @@ export { replaceNodeOrValue } from './lib/parser/utils/token.js';
|
|
|
33
33
|
export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
|
|
34
34
|
export { FeatureWalkMode } from './lib/ast/features/type.js';
|
|
35
35
|
export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
|
|
36
|
+
export { parseSyntax } from './lib/validation/parser/parse.js';
|
|
36
37
|
export { version } from '../package.json.js';
|
|
37
38
|
|
|
38
39
|
/**
|
package/dist/src/types.js
CHANGED