@eslint/css-tree 3.3.0 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/version.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = "3.3.0";
1
+ module.exports = "3.3.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "3.3.0";
1
+ export const version = "3.3.2";
package/lib/index.d.ts CHANGED
@@ -606,6 +606,18 @@ export interface Comment extends CssNodeCommon {
606
606
  value: string;
607
607
  }
608
608
 
609
+ export interface Condition extends CssNodeCommon {
610
+ type: "Condition";
611
+ kind: string;
612
+ children: List<CssNode>;
613
+ }
614
+
615
+ export interface ConditionPlain extends CssNodeCommon {
616
+ type: "Condition";
617
+ kind: string;
618
+ children: CssNodePlain[];
619
+ }
620
+
609
621
  export interface Declaration extends CssNodeCommon {
610
622
  type: "Declaration";
611
623
  important: boolean | string;
@@ -636,6 +648,37 @@ export interface Dimension extends CssNodeCommon {
636
648
  unit: string;
637
649
  }
638
650
 
651
+ export interface Feature extends CssNodeCommon {
652
+ type: "Feature";
653
+ name: string;
654
+ kind: string;
655
+ value: Identifier | NumberNode | Dimension | Ratio | FunctionNode | null;
656
+ }
657
+
658
+ export interface FeatureFunction extends CssNodeCommon {
659
+ type: "FeatureFunction";
660
+ feature: string;
661
+ kind: string;
662
+ value: Declaration | Selector;
663
+ }
664
+
665
+ export interface FeatureFunctionPlain extends CssNodeCommon {
666
+ type: "FeatureFunction";
667
+ feature: string;
668
+ kind: string;
669
+ value: DeclarationPlain | SelectorPlain;
670
+ }
671
+
672
+ export interface FeatureRange extends CssNodeCommon {
673
+ type: "FeatureRange";
674
+ kind: string;
675
+ left: Identifier | NumberNode | Dimension | Ratio | FunctionNode;
676
+ leftComparison: string;
677
+ middle: Identifier | NumberNode | Dimension | Ratio | FunctionNode;
678
+ rightComparison: string | null;
679
+ right: Identifier | NumberNode | Dimension | Ratio | FunctionNode | null;
680
+ }
681
+
639
682
  export interface FunctionNode extends CssNodeCommon {
640
683
  type: "Function";
641
684
  name: string;
@@ -663,6 +706,21 @@ export interface Identifier extends CssNodeCommon {
663
706
  name: string;
664
707
  }
665
708
 
709
+ export interface Layer extends CssNodeCommon {
710
+ type: "Layer";
711
+ name: string;
712
+ }
713
+
714
+ export interface LayerList extends CssNodeCommon {
715
+ type: "LayerList";
716
+ children: List<Layer>;
717
+ }
718
+
719
+ export interface LayerListPlain extends CssNodeCommon {
720
+ type: "LayerList";
721
+ children: Layer[];
722
+ }
723
+
666
724
  export interface MediaFeature extends CssNodeCommon {
667
725
  type: "MediaFeature";
668
726
  name: string;
@@ -807,6 +865,11 @@ export interface StyleSheet extends CssNodeCommon {
807
865
  children: List<CssNode>;
808
866
  }
809
867
 
868
+ export interface SupportsDeclaration extends CssNodeCommon {
869
+ type: "SupportsDeclaration";
870
+ declaration: Declaration | Raw;
871
+ }
872
+
810
873
  export interface StyleSheetPlain extends CssNodeCommon {
811
874
  type: "StyleSheet";
812
875
  children: CssNodePlain[];
@@ -842,6 +905,7 @@ export interface WhiteSpace extends CssNodeCommon {
842
905
  value: string;
843
906
  }
844
907
 
908
+ /* IMPORTANT! If you update this, also update `CssNodePlain` */
845
909
  export type CssNode =
846
910
  | AnPlusB
847
911
  | Atrule
@@ -854,13 +918,19 @@ export type CssNode =
854
918
  | ClassSelector
855
919
  | Combinator
856
920
  | Comment
921
+ | Condition
857
922
  | Declaration
858
923
  | DeclarationList
859
924
  | Dimension
925
+ | Feature
926
+ | FeatureFunction
927
+ | FeatureRange
860
928
  | FunctionNode
861
929
  | Hash
862
930
  | IdSelector
863
931
  | Identifier
932
+ | Layer
933
+ | LayerList
864
934
  | MediaFeature
865
935
  | MediaQuery
866
936
  | MediaQueryList
@@ -879,12 +949,14 @@ export type CssNode =
879
949
  | SelectorList
880
950
  | StringNode
881
951
  | StyleSheet
952
+ | SupportsDeclaration
882
953
  | TypeSelector
883
954
  | UnicodeRange
884
955
  | Url
885
956
  | Value
886
957
  | WhiteSpace;
887
958
 
959
+ /* IMPORTANT! If you update this, also update `CssNode` */
888
960
  export type CssNodePlain =
889
961
  | AnPlusB
890
962
  | AtrulePlain
@@ -897,16 +969,23 @@ export type CssNodePlain =
897
969
  | ClassSelector
898
970
  | Combinator
899
971
  | Comment
972
+ | ConditionPlain
900
973
  | DeclarationPlain
901
974
  | DeclarationListPlain
902
975
  | Dimension
976
+ | Feature
977
+ | FeatureFunctionPlain
978
+ | FeatureRange
903
979
  | FunctionNodePlain
904
980
  | Hash
905
981
  | IdSelector
906
982
  | Identifier
983
+ | Layer
984
+ | LayerListPlain
907
985
  | MediaFeature
908
986
  | MediaQueryPlain
909
987
  | MediaQueryListPlain
988
+ | NestingSelector
910
989
  | NthPlain
911
990
  | NumberNode
912
991
  | Operator
@@ -921,54 +1000,16 @@ export type CssNodePlain =
921
1000
  | SelectorListPlain
922
1001
  | StringNode
923
1002
  | StyleSheetPlain
1003
+ | SupportsDeclaration
924
1004
  | TypeSelector
925
1005
  | UnicodeRange
926
1006
  | Url
927
1007
  | ValuePlain
928
1008
  | WhiteSpace;
929
1009
 
930
- type CssNodeNames =
931
- | "AnPlusB"
932
- | "Atrule"
933
- | "AtrulePrelude"
934
- | "AttributeSelector"
935
- | "Block"
936
- | "Brackets"
937
- | "CDC"
938
- | "CDO"
939
- | "ClassSelector"
940
- | "Combinator"
941
- | "Comment"
942
- | "Declaration"
943
- | "DeclarationList"
944
- | "Dimension"
945
- | "Function"
946
- | "Hash"
947
- | "IdSelector"
948
- | "Identifier"
949
- | "MediaFeature"
950
- | "MediaQuery"
951
- | "MediaQueryList"
952
- | "NestingSelector"
953
- | "Nth"
954
- | "Number"
955
- | "Operator"
956
- | "Parentheses"
957
- | "Percentage"
958
- | "PseudoClassSelector"
959
- | "PseudoElementSelector"
960
- | "Ratio"
961
- | "Raw"
962
- | "Rule"
963
- | "Selector"
964
- | "SelectorList"
965
- | "String"
966
- | "StyleSheet"
967
- | "TypeSelector"
968
- | "UnicodeRange"
969
- | "Url"
970
- | "Value"
971
- | "WhiteSpace";
1010
+ type CssNodeNames = CssNode["type"];
1011
+
1012
+ type AnyCssNode = CssNode | CssNodePlain;
972
1013
 
973
1014
  // ----------------------------------------------------------
974
1015
  // Tokenizer
@@ -1382,27 +1423,46 @@ export class OffsetToLocation {
1382
1423
  * Represents an error that occurs during CSS parsing. Extends the standard `SyntaxError`
1383
1424
  * to include additional details about the parsing error.
1384
1425
  */
1426
+
1427
+ /**
1428
+ * Represents a syntax error while parsing CSS code. In the actual code,
1429
+ * this is called `SyntaxError`, but that clashes with the global `SyntaxError` class.
1430
+ * This isn't exported separately but rather as a member of the `parse` function.
1431
+ */
1385
1432
  export interface SyntaxParseError extends SyntaxError {
1433
+
1386
1434
  /**
1387
- * The original input string that caused the error.
1435
+ * The source code where the error occurred.
1388
1436
  */
1389
- input: string;
1437
+ source: string;
1390
1438
 
1391
1439
  /**
1392
- * The character offset in the input string where the error occurred.
1440
+ * The character offset in the source code where the error occurred.
1393
1441
  */
1394
1442
  offset: number;
1395
1443
 
1396
1444
  /**
1397
- * The raw error message without formatting.
1445
+ * The line number (1-indexed) in the source code where the error occurred.
1398
1446
  */
1399
- rawMessage: string;
1447
+ line: number;
1448
+
1449
+ /**
1450
+ * The column number (1-indexed) in the source code where the error occurred.
1451
+ */
1452
+ column: number;
1453
+
1454
+ /**
1455
+ * The source code fragment around the error, including a specified number of extra lines.
1456
+ * @param extraLines The number of extra lines to include in the fragment.
1457
+ * @return A string containing the source code fragment around the error.
1458
+ * This fragment includes the error line and the specified number of lines before and after it.
1459
+ */
1460
+ sourceFragment(extraLines: number): string;
1400
1461
 
1401
1462
  /**
1402
- * The formatted error message, including contextual information such as
1403
- * the location in the input string.
1463
+ * The error message formatted with the source fragment.
1404
1464
  */
1405
- formattedMessage: string;
1465
+ readonly formattedMessage: string;
1406
1466
  }
1407
1467
 
1408
1468
  /**
@@ -1506,6 +1566,18 @@ export interface ParseOptions {
1506
1566
  parseCustomProperty?: boolean | undefined;
1507
1567
  }
1508
1568
 
1569
+ /**
1570
+ * Creates a new instance of a parse error.
1571
+ * @param message The error message describing the syntax error.
1572
+ * @param source The source code where the error occurred.
1573
+ * @param offset The character offset in the source code where the error occurred.
1574
+ * @param line The line number (1-indexed) in the source code where the error occurred.
1575
+ * @param column The column number (1-indexed) in the source code where the error occurred.
1576
+ * @param baseLine The base line number (1-indexed) for the error, used for relative positioning.
1577
+ * @param baseColumn The base column number (1-indexed) for the error, used for relative positioning.
1578
+ */
1579
+ export type SyntaxErrorCreator = (message: string, source: string, offset: number, line: number, column: number, baseLine?: number, baseColumn?: number) => SyntaxParseError;
1580
+
1509
1581
  /**
1510
1582
  * A function that parses a CSS string into an abstract syntax tree (AST).
1511
1583
  */
@@ -1523,7 +1595,7 @@ export interface ParseFunction {
1523
1595
  /**
1524
1596
  * The error class used for parsing errors.
1525
1597
  */
1526
- SyntaxError: typeof CSSSyntaxError;
1598
+ SyntaxError: SyntaxErrorCreator;
1527
1599
 
1528
1600
  /**
1529
1601
  * The configuration used by the parser.
@@ -1613,7 +1685,7 @@ export interface GenerateOptions {
1613
1685
  * @param options - Optional configuration for the generator.
1614
1686
  * @returns The generated CSS string.
1615
1687
  */
1616
- export type GenerateFunction = (ast: CssNode, options?: GenerateOptions) => string;
1688
+ export type GenerateFunction = (ast: AnyCssNode, options?: GenerateOptions) => string;
1617
1689
 
1618
1690
  /**
1619
1691
  * Generates a CSS string from an abstract syntax tree (AST).
@@ -1645,7 +1717,7 @@ export interface WalkContext {
1645
1717
  /**
1646
1718
  * The root node of the tree being traversed.
1647
1719
  */
1648
- root: CssNode;
1720
+ root: AnyCssNode;
1649
1721
 
1650
1722
  /**
1651
1723
  * The current stylesheet node being visited, or `null` if not applicable.
@@ -1753,48 +1825,7 @@ export interface WalkOptionsVisit<NodeType extends CssNode = CssNode> {
1753
1825
  /**
1754
1826
  * Combined options for tree-walking, supporting specific node types or general traversal options.
1755
1827
  */
1756
- export type WalkOptions =
1757
- | WalkOptionsVisit<AnPlusB>
1758
- | WalkOptionsVisit<Atrule>
1759
- | WalkOptionsVisit<AtrulePrelude>
1760
- | WalkOptionsVisit<AttributeSelector>
1761
- | WalkOptionsVisit<Block>
1762
- | WalkOptionsVisit<Brackets>
1763
- | WalkOptionsVisit<CDC>
1764
- | WalkOptionsVisit<CDO>
1765
- | WalkOptionsVisit<ClassSelector>
1766
- | WalkOptionsVisit<Combinator>
1767
- | WalkOptionsVisit<Comment>
1768
- | WalkOptionsVisit<Declaration>
1769
- | WalkOptionsVisit<DeclarationList>
1770
- | WalkOptionsVisit<Dimension>
1771
- | WalkOptionsVisit<FunctionNode>
1772
- | WalkOptionsVisit<Hash>
1773
- | WalkOptionsVisit<IdSelector>
1774
- | WalkOptionsVisit<Identifier>
1775
- | WalkOptionsVisit<MediaFeature>
1776
- | WalkOptionsVisit<MediaQuery>
1777
- | WalkOptionsVisit<MediaQueryList>
1778
- | WalkOptionsVisit<Nth>
1779
- | WalkOptionsVisit<NumberNode>
1780
- | WalkOptionsVisit<Operator>
1781
- | WalkOptionsVisit<Parentheses>
1782
- | WalkOptionsVisit<Percentage>
1783
- | WalkOptionsVisit<PseudoClassSelector>
1784
- | WalkOptionsVisit<PseudoElementSelector>
1785
- | WalkOptionsVisit<Ratio>
1786
- | WalkOptionsVisit<Raw>
1787
- | WalkOptionsVisit<Rule>
1788
- | WalkOptionsVisit<Selector>
1789
- | WalkOptionsVisit<SelectorList>
1790
- | WalkOptionsVisit<StringNode>
1791
- | WalkOptionsVisit<StyleSheet>
1792
- | WalkOptionsVisit<TypeSelector>
1793
- | WalkOptionsVisit<UnicodeRange>
1794
- | WalkOptionsVisit<Url>
1795
- | WalkOptionsVisit<Value>
1796
- | WalkOptionsVisit<WhiteSpace>
1797
- | WalkOptionsNoVisit;
1828
+ export type WalkOptions = WalkOptionsVisit<CssNode> | WalkOptionsNoVisit;
1798
1829
 
1799
1830
  /**
1800
1831
  * Walks through a CSS abstract syntax tree (AST) and invokes callback functions on nodes.
@@ -1806,7 +1837,7 @@ export const walk: {
1806
1837
  * @param ast - The CSS abstract syntax tree to traverse.
1807
1838
  * @param options - The options controlling the traversal process.
1808
1839
  */
1809
- (ast: CssNode, options: EnterOrLeaveFn | WalkOptions): void;
1840
+ (ast: AnyCssNode, options: EnterOrLeaveFn | WalkOptions): void;
1810
1841
 
1811
1842
  /**
1812
1843
  * Stops traversal. No visitor function will be invoked once this value is returned by a visitor.
@@ -1828,7 +1859,7 @@ export const walk: {
1828
1859
  * @param list - The list containing the current node.
1829
1860
  * @returns `true` if the node matches the condition; `false` otherwise.
1830
1861
  */
1831
- export type FindFn = (this: WalkContext, node: CssNode, item: ListItem<CssNode>, list: List<CssNode>) => boolean;
1862
+ export type FindFn = (this: WalkContext, node: AnyCssNode, item: ListItem<CssNode>, list: List<CssNode>) => boolean;
1832
1863
 
1833
1864
  /**
1834
1865
  * Finds the first node in the tree that matches the specified predicate function.
@@ -1837,7 +1868,7 @@ export type FindFn = (this: WalkContext, node: CssNode, item: ListItem<CssNode>,
1837
1868
  * @param fn - The predicate function to match nodes.
1838
1869
  * @returns The first matching node, or `null` if no match is found.
1839
1870
  */
1840
- export function find(ast: CssNode, fn: FindFn): CssNode | null;
1871
+ export function find(ast: AnyCssNode, fn: FindFn): AnyCssNode | null;
1841
1872
 
1842
1873
  /**
1843
1874
  * Finds the last node in the tree that matches the specified predicate function.
@@ -1846,7 +1877,7 @@ export function find(ast: CssNode, fn: FindFn): CssNode | null;
1846
1877
  * @param fn - The predicate function to match nodes.
1847
1878
  * @returns The last matching node, or `null` if no match is found.
1848
1879
  */
1849
- export function findLast(ast: CssNode, fn: FindFn): CssNode | null;
1880
+ export function findLast(ast: AnyCssNode, fn: FindFn): AnyCssNode | null;
1850
1881
 
1851
1882
  /**
1852
1883
  * Finds all nodes in the tree that match the specified predicate function.
@@ -1855,7 +1886,7 @@ export function findLast(ast: CssNode, fn: FindFn): CssNode | null;
1855
1886
  * @param fn - The predicate function to match nodes.
1856
1887
  * @returns An array of all matching nodes.
1857
1888
  */
1858
- export function findAll(ast: CssNode, fn: FindFn): CssNode[];
1889
+ export function findAll(ast: AnyCssNode, fn: FindFn): AnyCssNode[];
1859
1890
 
1860
1891
  // ----------------------------------------------------------
1861
1892
  // Name utils
@@ -2266,59 +2297,6 @@ export const url: {
2266
2297
  // https://github.com/csstree/csstree/blob/master/lib/lexer/Lexer.js
2267
2298
  // ----------------------------------------------------------
2268
2299
 
2269
- /**
2270
- * Represents a syntax error while parsing CSS code. In the actual code,
2271
- * this is called `SyntaxError`, but that clashes with the global `SyntaxError` class.
2272
- * This isn't exported separately but rather as a member of the `parse` function.
2273
- */
2274
- declare class CSSSyntaxError extends SyntaxError {
2275
-
2276
- /**
2277
- * Creates a new instance
2278
- * @param message The error message describing the syntax error.
2279
- * @param source The source code where the error occurred.
2280
- * @param offset The character offset in the source code where the error occurred.
2281
- * @param line The line number (1-indexed) in the source code where the error occurred.
2282
- * @param column The column number (1-indexed) in the source code where the error occurred.
2283
- * @param baseLine The base line number (1-indexed) for the error, used for relative positioning.
2284
- * @param baseColumn The base column number (1-indexed) for the error, used for relative positioning.
2285
- */
2286
- constructor(message: string, source: string, offset: number, line: number, column: number, baseLine?: number, baseColumn?: number);
2287
-
2288
- /**
2289
- * The source code where the error occurred.
2290
- */
2291
- source: string;
2292
-
2293
- /**
2294
- * The character offset in the source code where the error occurred.
2295
- */
2296
- offset: number;
2297
-
2298
- /**
2299
- * The line number (1-indexed) in the source code where the error occurred.
2300
- */
2301
- line: number;
2302
-
2303
- /**
2304
- * The column number (1-indexed) in the source code where the error occurred.
2305
- */
2306
- column: number;
2307
-
2308
- /**
2309
- * The source code fragment around the error, including a specified number of extra lines.
2310
- * @param extraLines The number of extra lines to include in the fragment.
2311
- * @return A string containing the source code fragment around the error.
2312
- * This fragment includes the error line and the specified number of lines before and after it.
2313
- */
2314
- sourceFragment(extraLines: number): string;
2315
-
2316
- /**
2317
- * The error message formatted with the source fragment.
2318
- */
2319
- readonly formattedMessage: string;
2320
- }
2321
-
2322
2300
  /**
2323
2301
  * Represents an error that occurs during the syntax matching process.
2324
2302
  * Extends the standard `SyntaxError` with additional properties specific to CSS parsing.
@@ -3055,7 +3033,7 @@ export class Lexer {
3055
3033
  * @param prelude - The prelude content.
3056
3034
  * @returns The match result as a `LexerMatchResult`.
3057
3035
  */
3058
- matchAtrulePrelude(atruleName: string, prelude: CssNode | string): LexerMatchResult;
3036
+ matchAtrulePrelude(atruleName: string, prelude: AnyCssNode | string): LexerMatchResult;
3059
3037
 
3060
3038
  /**
3061
3039
  * Matches an at-rule descriptor value against its syntax definition.
@@ -3065,7 +3043,7 @@ export class Lexer {
3065
3043
  * @param value - The value to match.
3066
3044
  * @returns The match result as a `LexerMatchResult`.
3067
3045
  */
3068
- matchAtruleDescriptor(atruleName: string, descriptorName: string, value: CssNode | string): LexerMatchResult;
3046
+ matchAtruleDescriptor(atruleName: string, descriptorName: string, value: AnyCssNode | string): LexerMatchResult;
3069
3047
 
3070
3048
  /**
3071
3049
  * Matches a declaration node against its syntax definition.
@@ -3073,7 +3051,7 @@ export class Lexer {
3073
3051
  * @param node - The declaration node to match.
3074
3052
  * @returns The match result as a `LexerMatchResult`.
3075
3053
  */
3076
- matchDeclaration(node: CssNode): LexerMatchResult;
3054
+ matchDeclaration(node: AnyCssNode): LexerMatchResult;
3077
3055
 
3078
3056
  /**
3079
3057
  * Matches a property value against its syntax definition.
@@ -3082,7 +3060,7 @@ export class Lexer {
3082
3060
  * @param value - The value to match.
3083
3061
  * @returns The match result as a `LexerMatchResult`.
3084
3062
  */
3085
- matchProperty(propertyName: string, value: CssNode | string): LexerMatchResult;
3063
+ matchProperty(propertyName: string, value: AnyCssNode | string): LexerMatchResult;
3086
3064
 
3087
3065
  /**
3088
3066
  * Matches a type value against its syntax definition.
@@ -3091,7 +3069,7 @@ export class Lexer {
3091
3069
  * @param value - The value to match.
3092
3070
  * @returns The match result as a `LexerMatchResult`.
3093
3071
  */
3094
- matchType(typeName: string, value: CssNode | string): LexerMatchResult;
3072
+ matchType(typeName: string, value: AnyCssNode | string): LexerMatchResult;
3095
3073
 
3096
3074
  /**
3097
3075
  * Matches a generic syntax descriptor against a value.
@@ -3100,7 +3078,7 @@ export class Lexer {
3100
3078
  * @param value - The value to match.
3101
3079
  * @returns The match result as a `LexerMatchResult`.
3102
3080
  */
3103
- match(syntax: SyntaxDescriptor | string, value: CssNode | string): LexerMatchResult;
3081
+ match(syntax: SyntaxDescriptor | string, value: AnyCssNode | string): LexerMatchResult;
3104
3082
 
3105
3083
  /**
3106
3084
  * Finds fragments of a value that match a specific syntax type and name.
@@ -3111,7 +3089,7 @@ export class Lexer {
3111
3089
  * @param name - The name to match.
3112
3090
  * @returns An array of matching fragments.
3113
3091
  */
3114
- findValueFragments(propertyName: string, value: CssNode, type: string, name: string): FragmentMatch<Value>[];
3092
+ findValueFragments(propertyName: string, value: AnyCssNode, type: string, name: string): FragmentMatch<Value>[];
3115
3093
 
3116
3094
  /**
3117
3095
  * Finds fragments of a declaration value that match a specific syntax type and name.
@@ -3131,7 +3109,7 @@ export class Lexer {
3131
3109
  * @param name - The name to match.
3132
3110
  * @returns An array of matching fragments.
3133
3111
  */
3134
- findAllFragments(ast: CssNode, type: string, name: string): FragmentMatch[];
3112
+ findAllFragments(ast: AnyCssNode, type: string, name: string): FragmentMatch[];
3135
3113
 
3136
3114
  /**
3137
3115
  * Retrieves the syntax descriptor for an at-rule.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/css-tree",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "A tool set for CSS: fast detailed parser (CSS → AST), walker (AST traversal), generator (AST → CSS) and lexer (validation and matching) based on specs and browser implementations",
5
5
  "author": "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)",
6
6
  "license": "MIT",