@@ -643,7 +643,7 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for Ne
643643 loc,
644644 } ) ) ,
645645 AtRulePrelude :: Custom ( prelude) => {
646- parse_custom_at_rule_body ( prelude, input, start, self . options , self . at_rule_parser )
646+ parse_custom_at_rule_body ( prelude, input, start, self . options , self . at_rule_parser , false )
647647 }
648648 }
649649 }
@@ -670,7 +670,7 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for Ne
670670 loc,
671671 } ) ) ,
672672 AtRulePrelude :: Custom ( prelude) => {
673- parse_custom_at_rule_without_block ( prelude, start, self . options , self . at_rule_parser )
673+ parse_custom_at_rule_without_block ( prelude, start, self . options , self . at_rule_parser , false )
674674 }
675675 _ => Err ( ( ) ) ,
676676 }
@@ -703,7 +703,7 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> QualifiedRuleParser<'i>
703703 ) -> Result < CssRule < ' i , T :: AtRule > , ParseError < ' i , Self :: Error > > {
704704 let loc = self . loc ( start) ;
705705 let ( declarations, rules) = if self . options . flags . contains ( ParserFlags :: NESTING ) {
706- parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser ) ?
706+ parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser , true ) ?
707707 } else {
708708 ( DeclarationBlock :: parse ( input, self . options ) ?, CssRuleList ( vec ! [ ] ) )
709709 } ;
@@ -752,9 +752,10 @@ fn parse_custom_at_rule_body<'i, 't, T: crate::traits::AtRuleParser<'i>>(
752752 start : & ParserState ,
753753 options : & ParserOptions < ' _ , ' i > ,
754754 at_rule_parser : & mut T ,
755+ is_nested : bool ,
755756) -> Result < CssRule < ' i , T :: AtRule > , ParseError < ' i , ParserError < ' i > > > {
756757 at_rule_parser
757- . parse_block ( prelude, start, input, options)
758+ . parse_block ( prelude, start, input, options, is_nested )
758759 . map ( |prelude| CssRule :: Custom ( prelude) )
759760 . map_err ( |err| match & err. kind {
760761 ParseErrorKind :: Basic ( kind) => ParseError {
@@ -770,16 +771,18 @@ fn parse_custom_at_rule_without_block<'i, 't, T: crate::traits::AtRuleParser<'i>
770771 start : & ParserState ,
771772 options : & ParserOptions < ' _ , ' i > ,
772773 at_rule_parser : & mut T ,
774+ is_nested : bool ,
773775) -> Result < CssRule < ' i , T :: AtRule > , ( ) > {
774776 at_rule_parser
775- . rule_without_block ( prelude, start, options)
777+ . rule_without_block ( prelude, start, options, is_nested )
776778 . map ( |prelude| CssRule :: Custom ( prelude) )
777779}
778780
779781fn parse_declarations_and_nested_rules < ' a , ' o , ' i , ' t , T : crate :: traits:: AtRuleParser < ' i > > (
780782 input : & mut Parser < ' i , ' t > ,
781783 options : & ' a ParserOptions < ' o , ' i > ,
782784 at_rule_parser : & mut T ,
785+ is_nested : bool ,
783786) -> Result < ( DeclarationBlock < ' i > , CssRuleList < ' i , T :: AtRule > ) , ParseError < ' i , ParserError < ' i > > > {
784787 let mut important_declarations = DeclarationList :: new ( ) ;
785788 let mut declarations = DeclarationList :: new ( ) ;
@@ -790,6 +793,7 @@ fn parse_declarations_and_nested_rules<'a, 'o, 'i, 't, T: crate::traits::AtRuleP
790793 important_declarations : & mut important_declarations,
791794 rules : & mut rules,
792795 at_rule_parser,
796+ is_nested,
793797 } ;
794798
795799 // In the v2 nesting spec, declarations and nested rules may be mixed.
@@ -840,6 +844,7 @@ pub struct StyleRuleParser<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> {
840844 important_declarations : & ' a mut DeclarationList < ' i > ,
841845 rules : & ' a mut CssRuleList < ' i , T :: AtRule > ,
842846 at_rule_parser : & ' a mut T ,
847+ is_nested : bool ,
843848}
844849
845850/// Parse a declaration within {} block: `color: blue`
@@ -925,15 +930,15 @@ impl<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for StyleR
925930 AtRulePrelude :: Media ( query) => {
926931 self . rules . 0 . push ( CssRule :: Media ( MediaRule {
927932 query,
928- rules : parse_nested_at_rule ( input, self . options , self . at_rule_parser ) ?,
933+ rules : parse_style_block ( input, self . options , self . at_rule_parser , true ) ?,
929934 loc,
930935 } ) ) ;
931936 Ok ( ( ) )
932937 }
933938 AtRulePrelude :: Supports ( condition) => {
934939 self . rules . 0 . push ( CssRule :: Supports ( SupportsRule {
935940 condition,
936- rules : parse_nested_at_rule ( input, self . options , self . at_rule_parser ) ?,
941+ rules : parse_style_block ( input, self . options , self . at_rule_parser , true ) ?,
937942 loc,
938943 } ) ) ;
939944 Ok ( ( ) )
@@ -942,28 +947,29 @@ impl<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for StyleR
942947 self . rules . 0 . push ( CssRule :: Container ( ContainerRule {
943948 name,
944949 condition,
945- rules : parse_nested_at_rule ( input, self . options , self . at_rule_parser ) ?,
950+ rules : parse_style_block ( input, self . options , self . at_rule_parser , true ) ?,
946951 loc,
947952 } ) ) ;
948953 Ok ( ( ) )
949954 }
950955 AtRulePrelude :: LayerBlock ( name) => {
951956 self . rules . 0 . push ( CssRule :: LayerBlock ( LayerBlockRule {
952957 name,
953- rules : parse_nested_at_rule ( input, self . options , self . at_rule_parser ) ?,
958+ rules : parse_style_block ( input, self . options , self . at_rule_parser , true ) ?,
954959 loc,
955960 } ) ) ;
956961 Ok ( ( ) )
957962 }
958963 AtRulePrelude :: StartingStyle => {
959964 self . rules . 0 . push ( CssRule :: StartingStyle ( StartingStyleRule {
960- rules : parse_nested_at_rule ( input, self . options , self . at_rule_parser ) ?,
965+ rules : parse_style_block ( input, self . options , self . at_rule_parser , true ) ?,
961966 loc,
962967 } ) ) ;
963968 Ok ( ( ) )
964969 }
965970 AtRulePrelude :: Nest ( selectors) => {
966- let ( declarations, rules) = parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser ) ?;
971+ let ( declarations, rules) =
972+ parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser , true ) ?;
967973 self . rules . 0 . push ( CssRule :: Nesting ( NestingRule {
968974 style : StyleRule {
969975 selectors,
@@ -992,6 +998,7 @@ impl<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for StyleR
992998 start,
993999 self . options ,
9941000 self . at_rule_parser ,
1001+ true ,
9951002 ) ?) ;
9961003 Ok ( ( ) )
9971004 }
@@ -1021,6 +1028,7 @@ impl<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for StyleR
10211028 start,
10221029 self . options ,
10231030 self . at_rule_parser ,
1031+ true ,
10241032 ) ?) ;
10251033 Ok ( ( ) )
10261034 }
@@ -1029,10 +1037,11 @@ impl<'a, 'o, 'i, T: crate::traits::AtRuleParser<'i>> AtRuleParser<'i> for StyleR
10291037 }
10301038}
10311039
1032- pub fn parse_nested_at_rule < ' a , ' o , ' i , ' t , T : crate :: traits:: AtRuleParser < ' i > > (
1040+ pub fn parse_style_block < ' a , ' o , ' i , ' t , T : crate :: traits:: AtRuleParser < ' i > > (
10331041 input : & mut Parser < ' i , ' t > ,
10341042 options : & ' a ParserOptions < ' o , ' i > ,
10351043 at_rule_parser : & mut T ,
1044+ is_nested : bool ,
10361045) -> Result < CssRuleList < ' i , T :: AtRule > , ParseError < ' i , ParserError < ' i > > > {
10371046 let loc = input. current_source_location ( ) ;
10381047 let loc = Location {
@@ -1043,7 +1052,7 @@ pub fn parse_nested_at_rule<'a, 'o, 'i, 't, T: crate::traits::AtRuleParser<'i>>(
10431052
10441053 // Declarations can be immediately within @media and @supports blocks that are nested within a parent style rule.
10451054 // These act the same way as if they were nested within a `& { ... }` block.
1046- let ( declarations, mut rules) = parse_declarations_and_nested_rules ( input, options, at_rule_parser) ?;
1055+ let ( declarations, mut rules) = parse_declarations_and_nested_rules ( input, options, at_rule_parser, is_nested ) ?;
10471056
10481057 if declarations. len ( ) > 0 {
10491058 rules. 0 . insert (
@@ -1073,10 +1082,14 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> QualifiedRuleParser<'i>
10731082 input : & mut Parser < ' i , ' t > ,
10741083 ) -> Result < Self :: Prelude , ParseError < ' i , Self :: Error > > {
10751084 let selector_parser = SelectorParser {
1076- is_nesting_allowed : true ,
1085+ is_nesting_allowed : self . options . flags . contains ( ParserFlags :: NESTING ) ,
10771086 options : & self . options ,
10781087 } ;
1079- SelectorList :: parse_relative ( & selector_parser, input, NestingRequirement :: Implicit )
1088+ if self . is_nested {
1089+ SelectorList :: parse_relative ( & selector_parser, input, NestingRequirement :: Implicit )
1090+ } else {
1091+ SelectorList :: parse ( & selector_parser, input, NestingRequirement :: None )
1092+ }
10801093 }
10811094
10821095 fn parse_block < ' t > (
@@ -1086,7 +1099,8 @@ impl<'a, 'o, 'b, 'i, T: crate::traits::AtRuleParser<'i>> QualifiedRuleParser<'i>
10861099 input : & mut Parser < ' i , ' t > ,
10871100 ) -> Result < ( ) , ParseError < ' i , Self :: Error > > {
10881101 let loc = start. source_location ( ) ;
1089- let ( declarations, rules) = parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser ) ?;
1102+ let ( declarations, rules) =
1103+ parse_declarations_and_nested_rules ( input, self . options , self . at_rule_parser , true ) ?;
10901104 self . rules . 0 . push ( CssRule :: Style ( StyleRule {
10911105 selectors,
10921106 vendor_prefix : VendorPrefix :: empty ( ) ,
0 commit comments