@eslint/css-tree 3.5.4 → 3.6.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/dist/data.cjs CHANGED
@@ -526,8 +526,7 @@ module.exports = {
526
526
  "inset-area": "[[left|center|right|span-left|span-right|x-start|x-end|span-x-start|span-x-end|x-self-start|x-self-end|span-x-self-start|span-x-self-end|span-all]||[top|center|bottom|span-top|span-bottom|y-start|y-end|span-y-start|span-y-end|y-self-start|y-self-end|span-y-self-start|span-y-self-end|span-all]|[block-start|center|block-end|span-block-start|span-block-end|span-all]||[inline-start|center|inline-end|span-inline-start|span-inline-end|span-all]|[self-block-start|self-block-end|span-self-block-start|span-self-block-end|span-all]||[self-inline-start|self-inline-end|span-self-inline-start|span-self-inline-end|span-all]|[start|center|end|span-start|span-end|span-all]{1,2}|[self-start|center|self-end|span-self-start|span-self-end|span-all]{1,2}]",
527
527
  "font-variant-css2": "normal|small-caps",
528
528
  "font-width-css3": "normal|ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded",
529
- "system-family-name": "caption|icon|menu|message-box|small-caption|status-bar",
530
- "parentheses-block": "( <any-value>* )"
529
+ "system-family-name": "caption|icon|menu|message-box|small-caption|status-bar"
531
530
  },
532
531
  "properties": {
533
532
  "--*": "<declaration-value>",
@@ -1198,7 +1197,7 @@ module.exports = {
1198
1197
  "counter-style": {
1199
1198
  "prelude": "<counter-style-name>",
1200
1199
  "descriptors": {
1201
- "additive-symbols": "[<integer>&&<symbol>]#",
1200
+ "additive-symbols": "[<integer [0,∞]>&&<symbol>]#",
1202
1201
  "fallback": "<counter-style-name>",
1203
1202
  "negative": "<symbol> <symbol>?",
1204
1203
  "pad": "<integer>&&<symbol>",
@@ -1274,7 +1273,7 @@ module.exports = {
1274
1273
  "bleed": "auto|<length>",
1275
1274
  "marks": "none|[crop||cross]",
1276
1275
  "page-orientation": "upright|rotate-left|rotate-right",
1277
- "size": "<length>{1,2}|auto|[<page-size>||[portrait|landscape]]"
1276
+ "size": "<length [0,∞]>{1,2}|auto|[<page-size>||[portrait|landscape]]"
1278
1277
  }
1279
1278
  },
1280
1279
  "position-try": {
package/dist/data.js CHANGED
@@ -526,8 +526,7 @@ export default {
526
526
  "inset-area": "[[left|center|right|span-left|span-right|x-start|x-end|span-x-start|span-x-end|x-self-start|x-self-end|span-x-self-start|span-x-self-end|span-all]||[top|center|bottom|span-top|span-bottom|y-start|y-end|span-y-start|span-y-end|y-self-start|y-self-end|span-y-self-start|span-y-self-end|span-all]|[block-start|center|block-end|span-block-start|span-block-end|span-all]||[inline-start|center|inline-end|span-inline-start|span-inline-end|span-all]|[self-block-start|self-block-end|span-self-block-start|span-self-block-end|span-all]||[self-inline-start|self-inline-end|span-self-inline-start|span-self-inline-end|span-all]|[start|center|end|span-start|span-end|span-all]{1,2}|[self-start|center|self-end|span-self-start|span-self-end|span-all]{1,2}]",
527
527
  "font-variant-css2": "normal|small-caps",
528
528
  "font-width-css3": "normal|ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded",
529
- "system-family-name": "caption|icon|menu|message-box|small-caption|status-bar",
530
- "parentheses-block": "( <any-value>* )"
529
+ "system-family-name": "caption|icon|menu|message-box|small-caption|status-bar"
531
530
  },
532
531
  "properties": {
533
532
  "--*": "<declaration-value>",
@@ -1198,7 +1197,7 @@ export default {
1198
1197
  "counter-style": {
1199
1198
  "prelude": "<counter-style-name>",
1200
1199
  "descriptors": {
1201
- "additive-symbols": "[<integer>&&<symbol>]#",
1200
+ "additive-symbols": "[<integer [0,∞]>&&<symbol>]#",
1202
1201
  "fallback": "<counter-style-name>",
1203
1202
  "negative": "<symbol> <symbol>?",
1204
1203
  "pad": "<integer>&&<symbol>",
@@ -1274,7 +1273,7 @@ export default {
1274
1273
  "bleed": "auto|<length>",
1275
1274
  "marks": "none|[crop||cross]",
1276
1275
  "page-orientation": "upright|rotate-left|rotate-right",
1277
- "size": "<length>{1,2}|auto|[<page-size>||[portrait|landscape]]"
1276
+ "size": "<length [0,∞]>{1,2}|auto|[<page-size>||[portrait|landscape]]"
1278
1277
  }
1279
1278
  },
1280
1279
  "position-try": {
package/dist/version.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = "3.5.4";
1
+ module.exports = "3.6.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "3.5.4";
1
+ export const version = "3.6.1";
package/lib/index.d.ts CHANGED
@@ -525,6 +525,22 @@ export interface CssNodeCommon {
525
525
  loc?: CssLocationRange | null;
526
526
  }
527
527
 
528
+ export interface CssParentNodeCommon<T extends CssNode = CssNode> extends CssNodeCommon {
529
+ children: List<T>;
530
+ }
531
+
532
+ export interface CssParentNodeCommonPlain<T extends CssNodePlain = CssNodePlain> extends CssNodeCommon {
533
+ children: T[];
534
+ }
535
+
536
+ export interface CssOptionalParentNodeCommon<T extends CssNode = CssNode> extends CssNodeCommon {
537
+ children: List<T> | null;
538
+ }
539
+
540
+ export interface CssOptionalParentNodeCommonPlain<T extends CssNodePlain = CssNodePlain> extends CssNodeCommon {
541
+ children: T[] | null;
542
+ }
543
+
528
544
  export interface AnPlusB extends CssNodeCommon {
529
545
  type: "AnPlusB";
530
546
  a: string | null;
@@ -545,14 +561,12 @@ export interface AtrulePlain extends CssNodeCommon {
545
561
  block: BlockPlain | null;
546
562
  }
547
563
 
548
- export interface AtrulePrelude extends CssNodeCommon {
564
+ export interface AtrulePrelude extends CssParentNodeCommon {
549
565
  type: "AtrulePrelude";
550
- children: List<CssNode>;
551
566
  }
552
567
 
553
- export interface AtrulePreludePlain extends CssNodeCommon {
568
+ export interface AtrulePreludePlain extends CssParentNodeCommonPlain {
554
569
  type: "AtrulePrelude";
555
- children: CssNodePlain[];
556
570
  }
557
571
 
558
572
  export interface AttributeSelector extends CssNodeCommon {
@@ -563,24 +577,20 @@ export interface AttributeSelector extends CssNodeCommon {
563
577
  flags: string | null;
564
578
  }
565
579
 
566
- export interface Block extends CssNodeCommon {
580
+ export interface Block extends CssParentNodeCommon {
567
581
  type: "Block";
568
- children: List<CssNode>;
569
582
  }
570
583
 
571
- export interface BlockPlain extends CssNodeCommon {
584
+ export interface BlockPlain extends CssParentNodeCommonPlain {
572
585
  type: "Block";
573
- children: CssNodePlain[];
574
586
  }
575
587
 
576
- export interface Brackets extends CssNodeCommon {
588
+ export interface Brackets extends CssParentNodeCommon {
577
589
  type: "Brackets";
578
- children: List<CssNode>;
579
590
  }
580
591
 
581
- export interface BracketsPlain extends CssNodeCommon {
592
+ export interface BracketsPlain extends CssParentNodeCommonPlain {
582
593
  type: "Brackets";
583
- children: CssNodePlain[];
584
594
  }
585
595
 
586
596
  export interface CDC extends CssNodeCommon {
@@ -606,16 +616,14 @@ export interface Comment extends CssNodeCommon {
606
616
  value: string;
607
617
  }
608
618
 
609
- export interface Condition extends CssNodeCommon {
619
+ export interface Condition extends CssParentNodeCommon {
610
620
  type: "Condition";
611
621
  kind: string;
612
- children: List<CssNode>;
613
622
  }
614
623
 
615
- export interface ConditionPlain extends CssNodeCommon {
624
+ export interface ConditionPlain extends CssParentNodeCommonPlain {
616
625
  type: "Condition";
617
626
  kind: string;
618
- children: CssNodePlain[];
619
627
  }
620
628
 
621
629
  export interface Declaration extends CssNodeCommon {
@@ -632,14 +640,12 @@ export interface DeclarationPlain extends CssNodeCommon {
632
640
  value: ValuePlain | Raw;
633
641
  }
634
642
 
635
- export interface DeclarationList extends CssNodeCommon {
643
+ export interface DeclarationList extends CssParentNodeCommon {
636
644
  type: "DeclarationList";
637
- children: List<CssNode>;
638
645
  }
639
646
 
640
- export interface DeclarationListPlain extends CssNodeCommon {
647
+ export interface DeclarationListPlain extends CssParentNodeCommonPlain {
641
648
  type: "DeclarationList";
642
- children: CssNodePlain[];
643
649
  }
644
650
 
645
651
  export interface Dimension extends CssNodeCommon {
@@ -679,16 +685,14 @@ export interface FeatureRange extends CssNodeCommon {
679
685
  right: Identifier | NumberNode | Dimension | Ratio | FunctionNode | null;
680
686
  }
681
687
 
682
- export interface FunctionNode extends CssNodeCommon {
688
+ export interface FunctionNode extends CssParentNodeCommon {
683
689
  type: "Function";
684
690
  name: string;
685
- children: List<CssNode>;
686
691
  }
687
692
 
688
- export interface FunctionNodePlain extends CssNodeCommon {
693
+ export interface FunctionNodePlain extends CssParentNodeCommonPlain {
689
694
  type: "Function";
690
695
  name: string;
691
- children: CssNodePlain[];
692
696
  }
693
697
 
694
698
  export interface Hash extends CssNodeCommon {
@@ -711,14 +715,12 @@ export interface Layer extends CssNodeCommon {
711
715
  name: string;
712
716
  }
713
717
 
714
- export interface LayerList extends CssNodeCommon {
718
+ export interface LayerList extends CssParentNodeCommon<Layer> {
715
719
  type: "LayerList";
716
- children: List<Layer>;
717
720
  }
718
721
 
719
- export interface LayerListPlain extends CssNodeCommon {
722
+ export interface LayerListPlain extends CssParentNodeCommonPlain<Layer> {
720
723
  type: "LayerList";
721
- children: Layer[];
722
724
  }
723
725
 
724
726
  export interface MediaFeature extends CssNodeCommon {
@@ -727,24 +729,20 @@ export interface MediaFeature extends CssNodeCommon {
727
729
  value: Identifier | NumberNode | Dimension | Ratio | null;
728
730
  }
729
731
 
730
- export interface MediaQuery extends CssNodeCommon {
732
+ export interface MediaQuery extends CssParentNodeCommon {
731
733
  type: "MediaQuery";
732
- children: List<CssNode>;
733
734
  }
734
735
 
735
- export interface MediaQueryPlain extends CssNodeCommon {
736
+ export interface MediaQueryPlain extends CssParentNodeCommonPlain {
736
737
  type: "MediaQuery";
737
- children: CssNodePlain[];
738
738
  }
739
739
 
740
- export interface MediaQueryList extends CssNodeCommon {
740
+ export interface MediaQueryList extends CssParentNodeCommon<MediaQuery> {
741
741
  type: "MediaQueryList";
742
- children: List<CssNode>;
743
742
  }
744
743
 
745
- export interface MediaQueryListPlain extends CssNodeCommon {
744
+ export interface MediaQueryListPlain extends CssParentNodeCommonPlain<MediaQueryPlain> {
746
745
  type: "MediaQueryList";
747
- children: CssNodePlain[];
748
746
  }
749
747
 
750
748
  export interface NestingSelector extends CssNodeCommon {
@@ -773,14 +771,12 @@ export interface Operator extends CssNodeCommon {
773
771
  value: string;
774
772
  }
775
773
 
776
- export interface Parentheses extends CssNodeCommon {
774
+ export interface Parentheses extends CssParentNodeCommon {
777
775
  type: "Parentheses";
778
- children: List<CssNode>;
779
776
  }
780
777
 
781
- export interface ParenthesesPlain extends CssNodeCommon {
778
+ export interface ParenthesesPlain extends CssParentNodeCommonPlain {
782
779
  type: "Parentheses";
783
- children: CssNodePlain[];
784
780
  }
785
781
 
786
782
  export interface Percentage extends CssNodeCommon {
@@ -788,28 +784,24 @@ export interface Percentage extends CssNodeCommon {
788
784
  value: string;
789
785
  }
790
786
 
791
- export interface PseudoClassSelector extends CssNodeCommon {
787
+ export interface PseudoClassSelector extends CssOptionalParentNodeCommon {
792
788
  type: "PseudoClassSelector";
793
789
  name: string;
794
- children: List<CssNode> | null;
795
790
  }
796
791
 
797
- export interface PseudoClassSelectorPlain extends CssNodeCommon {
792
+ export interface PseudoClassSelectorPlain extends CssOptionalParentNodeCommonPlain {
798
793
  type: "PseudoClassSelector";
799
794
  name: string;
800
- children: CssNodePlain[] | null;
801
795
  }
802
796
 
803
- export interface PseudoElementSelector extends CssNodeCommon {
797
+ export interface PseudoElementSelector extends CssOptionalParentNodeCommon {
804
798
  type: "PseudoElementSelector";
805
799
  name: string;
806
- children: List<CssNode> | null;
807
800
  }
808
801
 
809
- export interface PseudoElementSelectorPlain extends CssNodeCommon {
802
+ export interface PseudoElementSelectorPlain extends CssOptionalParentNodeCommonPlain {
810
803
  type: "PseudoElementSelector";
811
804
  name: string;
812
- children: CssNodePlain[] | null;
813
805
  }
814
806
 
815
807
  export interface Ratio extends CssNodeCommon {
@@ -835,24 +827,20 @@ export interface RulePlain extends CssNodeCommon {
835
827
  block: BlockPlain;
836
828
  }
837
829
 
838
- export interface Selector extends CssNodeCommon {
830
+ export interface Selector extends CssParentNodeCommon {
839
831
  type: "Selector";
840
- children: List<CssNode>;
841
832
  }
842
833
 
843
- export interface SelectorPlain extends CssNodeCommon {
834
+ export interface SelectorPlain extends CssParentNodeCommonPlain {
844
835
  type: "Selector";
845
- children: CssNodePlain[];
846
836
  }
847
837
 
848
- export interface SelectorList extends CssNodeCommon {
838
+ export interface SelectorList extends CssParentNodeCommon {
849
839
  type: "SelectorList";
850
- children: List<CssNode>;
851
840
  }
852
841
 
853
- export interface SelectorListPlain extends CssNodeCommon {
842
+ export interface SelectorListPlain extends CssParentNodeCommonPlain {
854
843
  type: "SelectorList";
855
- children: CssNodePlain[];
856
844
  }
857
845
 
858
846
  export interface StringNode extends CssNodeCommon {
@@ -860,9 +848,8 @@ export interface StringNode extends CssNodeCommon {
860
848
  value: string;
861
849
  }
862
850
 
863
- export interface StyleSheet extends CssNodeCommon {
851
+ export interface StyleSheet extends CssParentNodeCommon {
864
852
  type: "StyleSheet";
865
- children: List<CssNode>;
866
853
  }
867
854
 
868
855
  export interface SupportsDeclaration extends CssNodeCommon {
@@ -870,9 +857,8 @@ export interface SupportsDeclaration extends CssNodeCommon {
870
857
  declaration: Declaration | Raw;
871
858
  }
872
859
 
873
- export interface StyleSheetPlain extends CssNodeCommon {
860
+ export interface StyleSheetPlain extends CssParentNodeCommonPlain {
874
861
  type: "StyleSheet";
875
- children: CssNodePlain[];
876
862
  }
877
863
 
878
864
  export interface TypeSelector extends CssNodeCommon {
@@ -890,14 +876,12 @@ export interface Url extends CssNodeCommon {
890
876
  value: string;
891
877
  }
892
878
 
893
- export interface Value extends CssNodeCommon {
879
+ export interface Value extends CssParentNodeCommon {
894
880
  type: "Value";
895
- children: List<CssNode>;
896
881
  }
897
882
 
898
- export interface ValuePlain extends CssNodeCommon {
883
+ export interface ValuePlain extends CssParentNodeCommonPlain {
899
884
  type: "Value";
900
- children: CssNodePlain[];
901
885
  }
902
886
 
903
887
  export interface WhiteSpace extends CssNodeCommon {
@@ -1331,7 +1315,7 @@ export class TokenStream {
1331
1315
  * @param offset - The offset from the current token's starting index (optional). If provided, the function checks the token at the specified offset instead of the current token.
1332
1316
  * @returns True if the token is a delimiter with the specified character code, false otherwise.
1333
1317
  */
1334
- isDelim(code: number, offset: number): boolean;
1318
+ isDelim(code: number, offset?: number): boolean;
1335
1319
 
1336
1320
  /**
1337
1321
  * Skips a specified number of tokens forward in the stream.
@@ -1700,6 +1684,37 @@ export type GenerateFunction = (ast: AnyCssNode, options?: GenerateOptions) => s
1700
1684
  */
1701
1685
  export const generate: GenerateFunction;
1702
1686
 
1687
+ /**
1688
+ * Represents the context object passed to a Node's `generate` function.
1689
+ * @see https://github.com/csstree/csstree/blob/56afb6dd761149099cd3cdfb0a38e15e8cc0a71a/lib/generator/create.js#L86-L91
1690
+ */
1691
+ export interface GeneratorContext {
1692
+ /**
1693
+ * Tokenizes a string or node.
1694
+ * @param value - The value to tokenize.
1695
+ */
1696
+ tokenize(value: string): void;
1697
+
1698
+ /**
1699
+ * Processes a child node.
1700
+ * @param node - The child node to process.
1701
+ */
1702
+ node(node: CssNode): void;
1703
+
1704
+ /**
1705
+ * Processes all children of a node.
1706
+ * @param node - The parent node whose children are processed.
1707
+ */
1708
+ children(node: CssNode): void;
1709
+
1710
+ /**
1711
+ * Emits a token with a specific type and value.
1712
+ * @param type - The type of the token.
1713
+ * @param value - The value of the token.
1714
+ */
1715
+ token(type: number, value: string): void;
1716
+ }
1717
+
1703
1718
  // ----------------------------------------------------------
1704
1719
  // Walker
1705
1720
  // ----------------------------------------------------------
@@ -2698,10 +2713,13 @@ type ParseConfig = {
2698
2713
  } & Pick<SyntaxConfig, 'features' | 'scope'>;
2699
2714
 
2700
2715
  // https://github.com/csstree/csstree/blob/9de5189fadd6fb4e3a149eec0e80d6ed0d0541e5/lib/parser/create.js#L90
2701
- type ParserContext = TokenStream
2716
+ type ParserContext<AvailableNodes extends CssNodeCommon = CssNode> = TokenStream
2702
2717
  & ParseConfig
2703
2718
  & { config: ParseConfig }
2704
2719
  & Parser
2720
+ & {
2721
+ [K in AvailableNodes["type"]]: (this: ParserContext, ...args: unknown[]) => Extract<AvailableNodes, { type: K }>;
2722
+ }
2705
2723
  & {
2706
2724
  // Anything else
2707
2725
  [key: string]: unknown;
@@ -2720,7 +2738,7 @@ interface NodeSyntaxConfig<T extends CssNodeCommon = CssNodeCommon> {
2720
2738
  name: string;
2721
2739
  structure: StructureDefinition;
2722
2740
  parse(this: ParserContext, ...args:Array<unknown>): T;
2723
- generate(this: ParserContext, node: T): void;
2741
+ generate(this: GeneratorContext, node: T): void;
2724
2742
  walkContext?: string;
2725
2743
  }
2726
2744
 
@@ -34,7 +34,91 @@ import {
34
34
  RightCurlyBracket
35
35
  } from '../tokenizer/index.js';
36
36
 
37
- const calcFunctionNames = ['calc(', '-moz-calc(', '-webkit-calc('];
37
+ // CSS mathematical functions categorized by return type behavior
38
+ // See: https://www.w3.org/TR/css-values-4/#math
39
+
40
+ // Calculation functions that return different types depending on input
41
+ const calcFunctionNames = [
42
+ 'calc(',
43
+ '-moz-calc(',
44
+ '-webkit-calc('
45
+ ];
46
+
47
+ // Comparison functions that return different types depending on input
48
+ const comparisonFunctionNames = [
49
+ 'min(',
50
+ 'max(',
51
+ 'clamp('
52
+ ];
53
+
54
+ // Functions that return a stepped value, i.e. a value that is rounded to the nearest step
55
+ const steppedValueFunctionNames = [
56
+ 'round(',
57
+ 'mod(',
58
+ 'rem('
59
+ ];
60
+
61
+ // Trigonometrical functions that return a <number>
62
+ const trigNumberFunctionNames = [
63
+ 'sin(',
64
+ 'cos(',
65
+ 'tan('
66
+ ];
67
+
68
+ // Trigonometrical functions that return a <angle>
69
+ const trigAngleFunctionNames = [
70
+ 'asin(',
71
+ 'acos(',
72
+ 'atan(',
73
+ 'atan2('
74
+ ];
75
+
76
+ // Other functions that return a <number>
77
+ const otherNumberFunctionNames = [
78
+ 'pow(',
79
+ 'sqrt(',
80
+ 'log(',
81
+ 'exp(',
82
+ 'sign('
83
+ ];
84
+
85
+ // Exponential functions that return a <number> or <dimension> or <percentage>
86
+ const expNumberDimensionPercentageFunctionNames = [
87
+ 'hypot('
88
+ ];
89
+
90
+ // Return the same type as the input
91
+ const signFunctionNames = [
92
+ 'abs('
93
+ ];
94
+
95
+ const numberFunctionNames = [
96
+ ...calcFunctionNames,
97
+ ...comparisonFunctionNames,
98
+ ...steppedValueFunctionNames,
99
+ ...trigNumberFunctionNames,
100
+ ...otherNumberFunctionNames,
101
+ ...expNumberDimensionPercentageFunctionNames,
102
+ ...signFunctionNames
103
+ ];
104
+
105
+ const percentageFunctionNames = [
106
+ ...calcFunctionNames,
107
+ ...comparisonFunctionNames,
108
+ ...steppedValueFunctionNames,
109
+ ...expNumberDimensionPercentageFunctionNames,
110
+ ...signFunctionNames
111
+ ];
112
+
113
+ const dimensionFunctionNames = [
114
+ ...calcFunctionNames,
115
+ ...comparisonFunctionNames,
116
+ ...steppedValueFunctionNames,
117
+ ...trigAngleFunctionNames,
118
+ ...expNumberDimensionPercentageFunctionNames,
119
+ ...signFunctionNames
120
+ ];
121
+
38
122
  const balancePair = new Map([
39
123
  [FunctionToken, RightParenthesis],
40
124
  [LeftParenthesis, RightParenthesis],
@@ -141,16 +225,17 @@ function consumeFunction(token, getNextToken) {
141
225
  return length;
142
226
  }
143
227
 
228
+
144
229
  // TODO: implement
145
230
  // can be used wherever <length>, <frequency>, <angle>, <time>, <percentage>, <number>, or <integer> values are allowed
146
231
  // https://drafts.csswg.org/css-values/#calc-notation
147
- function calc(next) {
232
+ function math(next, functionNames) {
148
233
  return function(token, getNextToken, opts) {
149
234
  if (token === null) {
150
235
  return 0;
151
236
  }
152
237
 
153
- if (token.type === FunctionToken && eqStrAny(token.value, calcFunctionNames)) {
238
+ if (token.type === FunctionToken && eqStrAny(token.value, functionNames)) {
154
239
  return consumeFunction(token, getNextToken);
155
240
  }
156
241
 
@@ -557,12 +642,12 @@ export const productionTypes = {
557
642
  'ident': tokenType(Ident),
558
643
 
559
644
  // percentage
560
- 'percentage': calc(percentage),
645
+ 'percentage': math(percentage, percentageFunctionNames),
561
646
 
562
647
  // numeric
563
648
  'zero': zero(),
564
- 'number': calc(number),
565
- 'integer': calc(integer),
649
+ 'number': math(number, numberFunctionNames),
650
+ 'integer': math(integer, numberFunctionNames),
566
651
 
567
652
  // complex types
568
653
  'custom-ident': customIdent,
@@ -601,15 +686,15 @@ export function createDemensionTypes(units) {
601
686
  } = units || {};
602
687
 
603
688
  return {
604
- 'dimension': calc(dimension(null)),
605
- 'angle': calc(dimension(angle)),
606
- 'decibel': calc(dimension(decibel)),
607
- 'frequency': calc(dimension(frequency)),
608
- 'flex': calc(dimension(flex)),
609
- 'length': calc(zero(dimension(length))),
610
- 'resolution': calc(dimension(resolution)),
611
- 'semitones': calc(dimension(semitones)),
612
- 'time': calc(dimension(time))
689
+ 'dimension': math(dimension(null), dimensionFunctionNames),
690
+ 'angle': math(dimension(angle), dimensionFunctionNames),
691
+ 'decibel': math(dimension(decibel), dimensionFunctionNames),
692
+ 'frequency': math(dimension(frequency), dimensionFunctionNames),
693
+ 'flex': math(dimension(flex), dimensionFunctionNames),
694
+ 'length': math(zero(dimension(length)), dimensionFunctionNames),
695
+ 'resolution': math(dimension(resolution), dimensionFunctionNames),
696
+ 'semitones': math(dimension(semitones), dimensionFunctionNames),
697
+ 'time': math(dimension(time), dimensionFunctionNames)
613
698
  };
614
699
  }
615
700
 
@@ -5,6 +5,7 @@ import {
5
5
  Semicolon,
6
6
  Hash,
7
7
  Colon,
8
+ Ident,
8
9
  AtKeyword,
9
10
  LeftSquareBracket,
10
11
  LeftCurlyBracket,
@@ -44,10 +45,24 @@ function consumeDeclaration() {
44
45
  return node;
45
46
  }
46
47
 
48
+ function isElementSelectorStart() {
49
+ if (this.tokenType !== Ident) {
50
+ return false;
51
+ }
52
+
53
+ const nextTokenType = this.lookupTypeNonSC(1);
54
+
55
+ if (nextTokenType !== Colon && nextTokenType !== Semicolon && nextTokenType !== RightCurlyBracket) {
56
+ return true;
57
+ }
58
+
59
+ return false;
60
+ }
61
+
47
62
  function isSelectorStart() {
48
63
  return this.tokenType === Delim && selectorStarts.has(this.source.charCodeAt(this.tokenStart)) ||
49
64
  this.tokenType === Hash || this.tokenType === LeftSquareBracket ||
50
- this.tokenType === Colon;
65
+ this.tokenType === Colon || isElementSelectorStart.call(this);
51
66
  }
52
67
 
53
68
  export const name = 'Block';
@@ -60,8 +75,7 @@ export const structure = {
60
75
  ]]
61
76
  };
62
77
 
63
- export function parse(isStyleBlock) {
64
- const consumer = isStyleBlock ? consumeDeclaration : consumeRule;
78
+ export function parse(isStyleBlock, { allowNestedRules = false } = {}) {
65
79
  const start = this.tokenStart;
66
80
  let children = this.createList();
67
81
 
@@ -83,10 +97,16 @@ export function parse(isStyleBlock) {
83
97
  break;
84
98
 
85
99
  default:
86
- if (isStyleBlock && isSelectorStart.call(this)) {
87
- children.push(consumeRule.call(this));
100
+ if (isStyleBlock) {
101
+
102
+ if (allowNestedRules && isSelectorStart.call(this)) {
103
+ children.push(consumeRule.call(this));
104
+ } else {
105
+ children.push(consumeDeclaration.call(this));
106
+ }
107
+
88
108
  } else {
89
- children.push(consumer.call(this));
109
+ children.push(consumeRule.call(this));
90
110
  }
91
111
  }
92
112
  }
@@ -35,7 +35,7 @@ export function parse() {
35
35
  prelude = consumeRaw.call(this, startToken);
36
36
  }
37
37
 
38
- block = this.Block(true);
38
+ block = this.Block(true, { allowNestedRules: true });
39
39
 
40
40
  return {
41
41
  type: 'Rule',
@@ -48,4 +48,3 @@ export function generate(node) {
48
48
  this.node(node.prelude);
49
49
  this.node(node.block);
50
50
  }
51
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/css-tree",
3
- "version": "3.5.4",
3
+ "version": "3.6.1",
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",
@@ -107,7 +107,7 @@
107
107
  "test:types": "tsc -p tests/types/tsconfig.json"
108
108
  },
109
109
  "dependencies": {
110
- "mdn-data": "2.20.0",
110
+ "mdn-data": "2.21.0",
111
111
  "source-map-js": "^1.0.1"
112
112
  },
113
113
  "devDependencies": {