File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed
packages/svelte/src/compiler Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,12 @@ const analysis_visitors = {
73
73
...context . state ,
74
74
rule : node
75
75
} ) ;
76
+
77
+ node . metadata . has_local_selectors = node . prelude . children . some ( ( selector ) => {
78
+ return selector . children . some (
79
+ ( { metadata } ) => ! metadata . is_global && ! metadata . is_host && ! metadata . is_root
80
+ ) ;
81
+ } ) ;
76
82
}
77
83
} ;
78
84
Original file line number Diff line number Diff line change @@ -172,10 +172,20 @@ const visitors = {
172
172
173
173
// if this selector list belongs to a rule, require a specificity bump for the
174
174
// first scoped selector but only if we're at the top level
175
- // TODO this isn't quite right, it would break with `:global(x) {...}`
176
- const parent = path . at ( - 1 ) ;
175
+ let parent = path . at ( - 1 ) ;
177
176
if ( parent ?. type === 'Rule' ) {
178
- specificity = { bumped : ! ! parent . metadata . parent_rule } ;
177
+ specificity = { bumped : false } ;
178
+
179
+ /** @type {import('#compiler').Css.Rule | null } */
180
+ let rule = parent . metadata . parent_rule ;
181
+
182
+ while ( rule ) {
183
+ if ( rule . metadata . has_local_selectors ) {
184
+ specificity = { bumped : true } ;
185
+ break ;
186
+ }
187
+ rule = rule . metadata . parent_rule ;
188
+ }
179
189
}
180
190
181
191
next ( { ...state , specificity } ) ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export interface Rule extends BaseNode {
27
27
block : Block ;
28
28
metadata : {
29
29
parent_rule : null | Rule ;
30
+ has_local_selectors : boolean ;
30
31
} ;
31
32
}
32
33
You can’t perform that action at this time.
0 commit comments