@tbela99/css-parser 1.6.9 → 1.7.0
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 +12 -1
- package/dist/index-umd-web.js +221 -244
- package/dist/index.cjs +220 -243
- package/dist/index.d.ts +8 -1
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +8 -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 +1 -1
- 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 +1 -1
- package/dist/src/lib/ast/math/expression.js +1 -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 +1 -1
- package/dist/src/lib/ast/walk.js +1 -1
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +11 -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 +9 -18
- package/dist/src/lib/parser/source.js +1 -1
- package/dist/src/lib/parser/tokenize.js +1 -1
- 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 +2 -1
- package/dist/src/lib/parser/utils/type.js +1 -1
- package/dist/src/lib/printer/render.js +2 -2
- 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 +98 -196
- 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 +6 -5
- 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.7.0
|
|
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 ||
|
|
@@ -1807,18 +1801,12 @@ function matchProperty(property, context, options) {
|
|
|
1807
1801
|
case "angle":
|
|
1808
1802
|
{
|
|
1809
1803
|
const token = context.peek();
|
|
1810
|
-
// if (token == null) {
|
|
1811
|
-
// break;
|
|
1812
|
-
// }
|
|
1813
1804
|
success = token?.typ === EnumToken.AngleTokenType;
|
|
1814
1805
|
}
|
|
1815
1806
|
break;
|
|
1816
1807
|
case "angle-percentage":
|
|
1817
1808
|
{
|
|
1818
1809
|
const token = context.peek();
|
|
1819
|
-
// if (token == null) {
|
|
1820
|
-
// break;
|
|
1821
|
-
// }
|
|
1822
1810
|
success = token?.typ === EnumToken.AngleTokenType || token?.typ === EnumToken.PercentageTokenType;
|
|
1823
1811
|
}
|
|
1824
1812
|
break;
|
|
@@ -1834,9 +1822,6 @@ function matchProperty(property, context, options) {
|
|
|
1834
1822
|
case "length-percentage":
|
|
1835
1823
|
{
|
|
1836
1824
|
const token = context.peek();
|
|
1837
|
-
// if (token == null) {
|
|
1838
|
-
// break;
|
|
1839
|
-
// }
|
|
1840
1825
|
success =
|
|
1841
1826
|
token?.typ == EnumToken.PercentageTokenType ||
|
|
1842
1827
|
token?.typ == EnumToken.LengthTokenType ||
|
|
@@ -1848,9 +1833,6 @@ function matchProperty(property, context, options) {
|
|
|
1848
1833
|
break;
|
|
1849
1834
|
case "length": {
|
|
1850
1835
|
const token = context.peek();
|
|
1851
|
-
// if (token == null) {
|
|
1852
|
-
// break;
|
|
1853
|
-
// }
|
|
1854
1836
|
success =
|
|
1855
1837
|
token?.typ == EnumToken.LengthTokenType ||
|
|
1856
1838
|
(token?.typ == EnumToken.NumberTokenType && token?.val === 0);
|
|
@@ -1865,12 +1847,6 @@ function matchProperty(property, context, options) {
|
|
|
1865
1847
|
success = token.typ == EnumToken.TimeTokenType;
|
|
1866
1848
|
}
|
|
1867
1849
|
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
1850
|
case "color":
|
|
1875
1851
|
case "color-function":
|
|
1876
1852
|
{
|
|
@@ -1878,13 +1854,6 @@ function matchProperty(property, context, options) {
|
|
|
1878
1854
|
const errors = [];
|
|
1879
1855
|
if (tokensfuncDefMap.has(token?.typ)) {
|
|
1880
1856
|
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
1857
|
const newRange = range.map((t) => cloneNode(t, true));
|
|
1889
1858
|
// @ts-ignore
|
|
1890
1859
|
parseTokens(newRange, { parseColor: true }, errors);
|
|
@@ -1909,27 +1878,6 @@ function matchProperty(property, context, options) {
|
|
|
1909
1878
|
syntaxToken: null,
|
|
1910
1879
|
errors,
|
|
1911
1880
|
};
|
|
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
1881
|
}
|
|
1934
1882
|
// @ts-expect-error
|
|
1935
1883
|
else if ("chi" in token) {
|
|
@@ -1948,10 +1896,6 @@ function matchProperty(property, context, options) {
|
|
|
1948
1896
|
}
|
|
1949
1897
|
}
|
|
1950
1898
|
break;
|
|
1951
|
-
// case "url-token":
|
|
1952
|
-
// success =
|
|
1953
|
-
// context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
|
|
1954
|
-
// break;
|
|
1955
1899
|
case "type-selector":
|
|
1956
1900
|
case "compound-selector":
|
|
1957
1901
|
case "complex-selector":
|
|
@@ -1976,15 +1920,6 @@ function matchProperty(property, context, options) {
|
|
|
1976
1920
|
};
|
|
1977
1921
|
}
|
|
1978
1922
|
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
1923
|
if (tokensfuncDefMap.has(context.peek()?.typ)) {
|
|
1989
1924
|
success = true;
|
|
1990
1925
|
context.next();
|
|
@@ -2006,17 +1941,6 @@ function matchProperty(property, context, options) {
|
|
|
2006
1941
|
config.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
|
|
2007
1942
|
break;
|
|
2008
1943
|
}
|
|
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
1944
|
case "size-feature": {
|
|
2021
1945
|
const range = context.peekRange();
|
|
2022
1946
|
const filteredRange = range.filter((token) => token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType);
|
|
@@ -2047,20 +1971,6 @@ function matchProperty(property, context, options) {
|
|
|
2047
1971
|
errors: [],
|
|
2048
1972
|
};
|
|
2049
1973
|
}
|
|
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
1974
|
break;
|
|
2065
1975
|
}
|
|
2066
1976
|
case "style-feature": {
|
|
@@ -2070,16 +1980,6 @@ function matchProperty(property, context, options) {
|
|
|
2070
1980
|
// match <style-range>
|
|
2071
1981
|
const range = context.peekRange();
|
|
2072
1982
|
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
1983
|
if (filteredRange.length === 1) {
|
|
2084
1984
|
success =
|
|
2085
1985
|
filteredRange[0].typ === EnumToken.IdenTokenType ||
|
|
@@ -2094,31 +1994,6 @@ function matchProperty(property, context, options) {
|
|
|
2094
1994
|
errors: [],
|
|
2095
1995
|
};
|
|
2096
1996
|
}
|
|
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
1997
|
return {
|
|
2123
1998
|
success: false,
|
|
2124
1999
|
valid: false,
|
|
@@ -2130,10 +2005,6 @@ function matchProperty(property, context, options) {
|
|
|
2130
2005
|
}
|
|
2131
2006
|
case "url": {
|
|
2132
2007
|
const token = context.peek();
|
|
2133
|
-
// if (token == null) {
|
|
2134
|
-
// success = false;
|
|
2135
|
-
// break;
|
|
2136
|
-
// }
|
|
2137
2008
|
let l;
|
|
2138
2009
|
if (token?.typ == EnumToken.UrlFunctionTokenDefType) {
|
|
2139
2010
|
l = 0;
|
|
@@ -2147,11 +2018,6 @@ function matchProperty(property, context, options) {
|
|
|
2147
2018
|
(token.typ == EnumToken.StringTokenType ||
|
|
2148
2019
|
token.typ == EnumToken.IdenTokenType ||
|
|
2149
2020
|
token.typ == EnumToken.UrlTokenTokenType)) {
|
|
2150
|
-
// if (token.typ === EnumToken.IdenTokenType) {
|
|
2151
|
-
// while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
|
|
2152
|
-
// l++;
|
|
2153
|
-
// }
|
|
2154
|
-
// }
|
|
2155
2021
|
while ((token = context.peek(++l))) {
|
|
2156
2022
|
if (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType) {
|
|
2157
2023
|
break;
|
|
@@ -2215,10 +2081,46 @@ function matchProperty(property, context, options) {
|
|
|
2215
2081
|
}
|
|
2216
2082
|
break;
|
|
2217
2083
|
}
|
|
2084
|
+
case "dashed-function": {
|
|
2085
|
+
const token = context.peek();
|
|
2086
|
+
success = token?.typ == EnumToken.CustomFunctionTokenDefType;
|
|
2087
|
+
if (success) {
|
|
2088
|
+
context.next();
|
|
2089
|
+
return {
|
|
2090
|
+
success: true,
|
|
2091
|
+
valid: true,
|
|
2092
|
+
token,
|
|
2093
|
+
context,
|
|
2094
|
+
syntaxToken: null,
|
|
2095
|
+
errors: [],
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
break;
|
|
2099
|
+
}
|
|
2100
|
+
case "block-contents":
|
|
2101
|
+
success = context.peek()?.typ == EnumToken.StartParensTokenType;
|
|
2102
|
+
if (success) {
|
|
2103
|
+
context.next();
|
|
2104
|
+
return {
|
|
2105
|
+
success: true,
|
|
2106
|
+
valid: true,
|
|
2107
|
+
token: null,
|
|
2108
|
+
context,
|
|
2109
|
+
syntaxToken: null,
|
|
2110
|
+
errors: [],
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
return {
|
|
2114
|
+
success: false,
|
|
2115
|
+
valid: true,
|
|
2116
|
+
token,
|
|
2117
|
+
context,
|
|
2118
|
+
syntaxToken: property,
|
|
2119
|
+
errors: [],
|
|
2120
|
+
};
|
|
2218
2121
|
default:
|
|
2219
2122
|
if (!(property.val in config.syntaxes)) {
|
|
2220
2123
|
console.debug("Unknown syntax", context.peek(), property);
|
|
2221
|
-
console.debug(context.getRemainingTokens());
|
|
2222
2124
|
throw new Error(`Unexpected validation property ${property.val}`);
|
|
2223
2125
|
}
|
|
2224
2126
|
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.7.0
|
|
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.7.0
|
|
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
package/dist/src/utils/sync.js
CHANGED
package/dist/src/web.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.7.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { doParse, doParseSync } from './lib/parser/parse.js';
|
|
@@ -28,6 +28,7 @@ export { PropertyList } from './lib/parser/declaration/list.js';
|
|
|
28
28
|
export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
|
|
29
29
|
export { FeatureWalkMode } from './lib/ast/features/type.js';
|
|
30
30
|
export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
|
|
31
|
+
export { parseSyntax } from './lib/validation/parser/parse.js';
|
|
31
32
|
export { version } from '../package.json.js';
|
|
32
33
|
|
|
33
34
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser, minifier and validator for node and the browser",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.7.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/src/node.js",
|
|
7
7
|
"./node": "./dist/src/node.js",
|
|
@@ -64,12 +64,13 @@
|
|
|
64
64
|
"@rollup/plugin-commonjs": "^29.0.3",
|
|
65
65
|
"@rollup/plugin-json": "^6.1.0",
|
|
66
66
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
67
|
-
"@rollup/plugin-typescript": "^12.3.
|
|
67
|
+
"@rollup/plugin-typescript": "^12.3.1",
|
|
68
68
|
"@types/chai": "^5.2.3",
|
|
69
69
|
"@types/chai-as-promised": "^8.0.2",
|
|
70
70
|
"@types/mocha": "^10.0.10",
|
|
71
71
|
"@types/node": "^26.6.5",
|
|
72
|
-
"@types/web": "^0.0.
|
|
72
|
+
"@types/web": "^0.0.359",
|
|
73
|
+
"@typescript/typescript6": "^6.0.2",
|
|
73
74
|
"@web/test-runner": "^1.0.0",
|
|
74
75
|
"@web/test-runner-playwright": "^1.0.0",
|
|
75
76
|
"chai": "^6.3.0",
|
|
@@ -77,8 +78,8 @@
|
|
|
77
78
|
"esno": "^4.8.0",
|
|
78
79
|
"markdown-it-task-lists": "^2.1.1",
|
|
79
80
|
"mocha": "^12.0.3",
|
|
80
|
-
"playwright": "^1.64.
|
|
81
|
-
"rollup": "^4.
|
|
81
|
+
"playwright": "^1.64.1",
|
|
82
|
+
"rollup": "^4.65.0",
|
|
82
83
|
"rollup-plugin-dts": "^6.5.1",
|
|
83
84
|
"rollup-plugin-version-injector": "^1.3.3",
|
|
84
85
|
"superc8": "^12.7.0",
|