@@ -901,22 +901,23 @@ describe("Tailwind 4", function () {
901901 } ) ;
902902
903903 describe ( "@custom-variant" , ( ) => {
904- it ( "should parse @custom-variant with an inline selector" , ( ) => {
905- const tree = toPlainObject ( parse ( "@custom-variant theme-midnight (&:where([data-theme='midnight' ] *));" ) ) ;
904+ it ( "should parse @custom-variant with an inline selector list " , ( ) => {
905+ const tree = toPlainObject ( parse ( "@custom-variant dark (&:where([data-theme=dark], [data-theme=dark ] *));" ) ) ;
906906 const atrule = tree . children [ 0 ] ;
907907
908908 assert . equal ( atrule . type , "Atrule" ) ;
909909 assert . equal ( atrule . name , "custom-variant" ) ;
910910 assert . equal ( atrule . block , null ) ;
911- assert . equal ( atrule . prelude . type , "Raw" ) ;
911+ assert . equal ( atrule . prelude . type , "AtrulePrelude" ) ;
912+ assert . equal ( atrule . prelude . children . length , 2 ) ;
912913 assert . equal (
913- atrule . prelude . value ,
914- "theme-midnight (&:where([data-theme='midnight' ] *))" ,
914+ atrule . prelude . children [ 1 ] . value ,
915+ "(&:where([data-theme=dark], [data-theme=dark ] *))" ,
915916 ) ;
916917 } ) ;
917918
918919 it ( "should parse @custom-variant with a block body using @slot" , ( ) => {
919- const tree = toPlainObject ( parse ( " @custom-variant theme-midnight { &:where([data-theme=' midnight' ] *) { @slot; } }" ) ) ;
920+ const tree = toPlainObject ( parse ( ' @custom-variant theme-midnight { &:where([data-theme=" midnight" ] *) { @slot; } }' ) ) ;
920921 const atrule = tree . children [ 0 ] ;
921922
922923 assert . equal ( atrule . type , "Atrule" ) ;
@@ -927,12 +928,38 @@ describe("Tailwind 4", function () {
927928 assert . equal ( atrule . block . children [ 0 ] . block . children [ 0 ] . name , "slot" ) ;
928929 } ) ;
929930
931+ it ( "should parse @custom-variant with a single inline selector" , ( ) => {
932+ const tree = toPlainObject ( parse ( '@custom-variant theme-midnight (&:where([data-theme="midnight"] *));' ) ) ;
933+ const atrule = tree . children [ 0 ] ;
934+
935+ assert . equal ( atrule . type , "Atrule" ) ;
936+ assert . equal ( atrule . name , "custom-variant" ) ;
937+ assert . equal ( atrule . block , null ) ;
938+ assert . equal ( atrule . prelude . type , "AtrulePrelude" ) ;
939+ assert . equal ( atrule . prelude . children . length , 2 ) ;
940+ assert . equal ( atrule . prelude . children [ 1 ] . value , '(&:where([data-theme="midnight"] *))' ) ;
941+ } ) ;
942+
943+ it ( "should parse @custom-variant with nested at-rules in a block body" , ( ) => {
944+ const tree = toPlainObject ( parse ( "@custom-variant any-hover { @media (any-hover: hover) { &:hover { @slot; } } }" ) ) ;
945+ const atrule = tree . children [ 0 ] ;
946+
947+ assert . equal ( atrule . type , "Atrule" ) ;
948+ assert . equal ( atrule . name , "custom-variant" ) ;
949+ assert . equal ( atrule . prelude . type , "AtrulePrelude" ) ;
950+ assert . equal ( atrule . prelude . children [ 0 ] . name , "any-hover" ) ;
951+ assert . equal ( atrule . block . children [ 0 ] . name , "media" ) ;
952+ assert . equal ( atrule . block . children [ 0 ] . block . children [ 0 ] . type , "Rule" ) ;
953+ } ) ;
954+
930955 describe ( "Validation" , ( ) => {
931956 [
932- "@custom-variant theme-midnight (&:where([data-theme='midnight'] *));" ,
933- "@custom-variant theme-midnight { &:where([data-theme='midnight'] *) { @slot; } }" ,
957+ "@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));" ,
958+ '@custom-variant theme-midnight { &:where([data-theme="midnight"] *) { @slot; } }' ,
959+ '@custom-variant theme-midnight (&:where([data-theme="midnight"] *));' ,
960+ "@custom-variant any-hover { @media (any-hover: hover) { &:hover { @slot; } } }" ,
934961 ] . forEach ( ( cssRule ) => {
935- it ( " should allow valid prelude" , ( ) => {
962+ it ( ` should allow valid prelude: ${ cssRule } ` , ( ) => {
936963 const tree = toPlainObject ( parse ( cssRule ) ) ;
937964 const { error } = lexer . matchAtrulePrelude ( "custom-variant" , tree . children [ 0 ] . prelude ) ;
938965 assert . equal ( error , null ) ;
0 commit comments