@@ -13,6 +13,7 @@ import {
1313 IDENTIFIER ,
1414 PRELUDE_OPERATOR ,
1515 URL ,
16+ FUNCTION ,
1617} from './arena'
1718
1819describe ( 'At-Rule Prelude Nodes' , ( ) => {
@@ -498,10 +499,74 @@ describe('At-Rule Prelude Nodes', () => {
498499
499500 expect ( children [ 0 ] . type ) . toBe ( CONTAINER_QUERY )
500501
501- const queryChildren = children [ 0 ] . children
502+ const [ ident , media_feature ] = children [ 0 ] . children
502503 // Should have name and feature
503- expect ( queryChildren . some ( ( c ) => c . type === IDENTIFIER ) ) . toBe ( true )
504- expect ( queryChildren . some ( ( c ) => c . type === MEDIA_FEATURE ) ) . toBe ( true )
504+ expect ( ident . type ) . toBe ( IDENTIFIER )
505+ expect ( media_feature . type ) . toBe ( MEDIA_FEATURE )
506+ } )
507+
508+ it ( 'should parse style container query' , ( ) => {
509+ const css = '@container style(--custom: 1) { }'
510+ const ast = parse ( css )
511+ const atRule = ast . first_child
512+ const children = atRule ?. children || [ ]
513+
514+ expect ( children [ 0 ] . type ) . toBe ( CONTAINER_QUERY )
515+
516+ const [ fn ] = children [ 0 ] . children
517+ expect ( fn . type_name ) . toBe ( 'Function' )
518+ expect ( fn . text ) . toBe ( 'style(--custom: 1)' )
519+ expect ( fn . value ) . toBe ( '--custom: 1' )
520+ } )
521+
522+ it ( 'should parse named style container query' , ( ) => {
523+ const css = '@container mytest style(--custom: 1) { }'
524+ const ast = parse ( css )
525+ const atRule = ast . first_child
526+ const children = atRule ?. children || [ ]
527+
528+ expect ( children [ 0 ] . type ) . toBe ( CONTAINER_QUERY )
529+
530+ const [ ident , fn ] = children [ 0 ] . children
531+ expect ( ident . type_name ) . toBe ( 'Identifier' )
532+ expect ( ident . text ) . toBe ( 'mytest' )
533+ expect ( fn . type_name ) . toBe ( 'Function' )
534+ expect ( fn . text ) . toBe ( 'style(--custom: 1)' )
535+ expect ( fn . value ) . toBe ( '--custom: 1' )
536+ } )
537+
538+ it ( 'should handle a very complex container query' , ( ) => {
539+ const css = `@container style(--themeBackground),
540+ not style(background-color: red),
541+ style(color: green) and style(background-color: transparent),
542+ style(--themeColor: blue) or style(--themeColor: purple) {
543+ /* <stylesheet> */
544+ }`
545+ const ast = parse ( css )
546+ const atRule = ast . first_child
547+ const children = atRule ?. children || [ ]
548+ expect ( children [ 0 ] . type ) . toBe ( CONTAINER_QUERY )
549+
550+ const container = children [ 0 ]
551+ const [ style1 , not1 , style2 , style3 , and , style4 , style5 , or , style6 ] = container . children
552+ expect ( style1 . type_name ) . toBe ( 'Function' )
553+ expect ( style1 . name ) . toBe ( 'style' )
554+ expect ( not1 . type_name ) . toBe ( 'Operator' )
555+ expect ( not1 . text ) . toBe ( 'not' )
556+ expect ( style2 . type_name ) . toBe ( 'Function' )
557+ expect ( style2 . name ) . toBe ( 'style' )
558+ expect ( style3 . type_name ) . toBe ( 'Function' )
559+ expect ( style3 . name ) . toBe ( 'style' )
560+ expect ( and . type_name ) . toBe ( 'Operator' )
561+ expect ( and . text ) . toBe ( 'and' )
562+ expect ( style4 . type_name ) . toBe ( 'Function' )
563+ expect ( style4 . name ) . toBe ( 'style' )
564+ expect ( style5 . type_name ) . toBe ( 'Function' )
565+ expect ( style5 . name ) . toBe ( 'style' )
566+ expect ( or . type_name ) . toBe ( 'Operator' )
567+ expect ( or . text ) . toBe ( 'or' )
568+ expect ( style6 . type_name ) . toBe ( 'Function' )
569+ expect ( style6 . name ) . toBe ( 'style' )
505570 } )
506571 } )
507572
0 commit comments