@@ -59,25 +59,15 @@ export default class Selector {
59
59
this . selector_list = group_selectors ( node , parent_selector_list ) ;
60
60
61
61
this . local_selector_list = this . selector_list . map ( ( complex_selector ) => {
62
- const i = complex_selector . findLastIndex ( ( block ) => ! block . global ) ;
62
+ const i = complex_selector . findLastIndex ( ( block ) => ! block . can_ignore ( ) ) ;
63
63
return complex_selector . slice ( 0 , i + 1 ) ;
64
64
} ) ;
65
65
66
- // Determine `used` based on the processed local_selector_list
67
- let host_only = false ;
68
- let root_only = false ;
69
-
70
- // Check if there's exactly one group and one block within that group, and if it's host or root
71
- if ( this . local_selector_list . length === 1 && this . local_selector_list [ 0 ] . length === 1 ) {
72
- const single_block = this . local_selector_list [ 0 ] [ 0 ] ;
73
- host_only = single_block . compound . host ;
74
- root_only = single_block . compound . root ;
75
- }
76
-
77
- // Check if there are no local blocks across all groups, or if there's a host_only or root_only situation
78
- const no_local_blocks = this . local_selector_list . every ( ( group ) => group . length === 0 ) ;
79
- this . used = no_local_blocks || host_only || root_only ;
66
+ // if we have a `:root {...}` or `:global(...) {...}` selector, we need to mark
67
+ // this selector as `used` even if the component doesn't contain any nodes
68
+ this . used = this . local_selector_list . some ( ( blocks ) => blocks . length === 0 ) ;
80
69
}
70
+
81
71
/**
82
72
* Determines whether the given selector is used within the component's nodes
83
73
* and marks the corresponding blocks for encapsulation if so.
@@ -108,7 +98,9 @@ export default class Selector {
108
98
*/
109
99
apply ( node ) {
110
100
for ( const complex_selector of this . local_selector_list ) {
111
- if ( apply_selector ( complex_selector . slice ( ) , node , this . stylesheet ) ) {
101
+ if ( complex_selector . length === 0 ) {
102
+ this . used = true ;
103
+ } else if ( apply_selector ( complex_selector . slice ( ) , node , this . stylesheet ) ) {
112
104
this . used = true ;
113
105
}
114
106
}
@@ -890,22 +882,21 @@ class RelativeSelector {
890
882
this . compound . add ( selector ) ;
891
883
}
892
884
885
+ can_ignore ( ) {
886
+ return this . compound . global || this . compound . host || this . compound . root ;
887
+ }
888
+
893
889
get global ( ) {
894
890
return this . compound . global ;
895
891
}
892
+
896
893
get host ( ) {
897
894
return this . compound . host ;
898
895
}
896
+
899
897
get root ( ) {
900
898
return this . compound . root ;
901
899
}
902
- get end ( ) {
903
- return this . compound . end ;
904
- }
905
- get start ( ) {
906
- if ( this . combinator ) return this . combinator . start ;
907
- return this . compound . start ;
908
- }
909
900
910
901
get contains_invisible_selectors ( ) {
911
902
return this . compound . selectors . some ( ( selector ) => ! selector . visible ) ;
0 commit comments