@@ -48,15 +48,7 @@ export default class Selector {
48
48
this . node = node ;
49
49
this . stylesheet = stylesheet ;
50
50
51
- let parent_selector_list = null ;
52
-
53
- if ( parent . parent instanceof Rule ) {
54
- parent_selector_list = parent . parent . selectors
55
- . map ( ( selector ) => selector . selector_list )
56
- . flat ( ) ;
57
- }
58
-
59
- this . selector_list = group_selectors ( node , parent_selector_list ) ;
51
+ this . selector_list = group_selectors ( node , parent ) ;
60
52
61
53
this . local_selector_list = this . selector_list . map ( ( complex_selector ) => {
62
54
const i = complex_selector . findLastIndex ( ( block ) => ! block . can_ignore ( ) ) ;
@@ -943,23 +935,27 @@ class CompoundSelector {
943
935
* Groups selectors and inserts parent blocks into nested rules.
944
936
*
945
937
* @param {import('#compiler').Css.Selector } selector - The selector to group and analyze.
946
- * @param {SelectorList | null } parent_selector_list - The parent blocks group to insert into nested rules.
938
+ * @param {Rule } rule
947
939
* @returns {SelectorList } - The grouped selectors with parent's blocks inserted if nested.
948
940
*/
949
- function group_selectors ( selector , parent_selector_list ) {
950
- // If it isn't a nested rule, then we add an empty block group
951
- if ( parent_selector_list === null ) {
952
- return [ selector_to_blocks ( [ ...selector . children ] , null ) ] ;
953
- }
941
+ function group_selectors ( selector , rule ) {
942
+ // TODO this logic isn't quite right, as it doesn't properly account for atrules
943
+ if ( rule . parent instanceof Rule ) {
944
+ const parent_selector_list = rule . parent . selectors
945
+ . map ( ( selector ) => selector . selector_list )
946
+ . flat ( ) ;
947
+
948
+ return parent_selector_list . map ( ( parent_complex_selector ) => {
949
+ const block_group = selector_to_blocks (
950
+ [ ...selector . children ] ,
951
+ [ ...parent_complex_selector ] // Clone the parent's blocks to avoid modifying the original array
952
+ ) ;
954
953
955
- return parent_selector_list . map ( ( parent_complex_selector ) => {
956
- const block_group = selector_to_blocks (
957
- [ ...selector . children ] ,
958
- [ ...parent_complex_selector ] // Clone the parent's blocks to avoid modifying the original array
959
- ) ;
954
+ return block_group ;
955
+ } ) ;
956
+ }
960
957
961
- return block_group ;
962
- } ) ;
958
+ return [ selector_to_blocks ( [ ...selector . children ] , null ) ] ;
963
959
}
964
960
965
961
/**
0 commit comments