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 = {
7373 ...context . state ,
7474 rule : node
7575 } ) ;
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+ } ) ;
7682 }
7783} ;
7884
Original file line number Diff line number Diff line change @@ -172,10 +172,20 @@ const visitors = {
172172
173173 // if this selector list belongs to a rule, require a specificity bump for the
174174 // 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 ) ;
177176 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+ }
179189 }
180190
181191 next ( { ...state , specificity } ) ;
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export interface Rule extends BaseNode {
2727 block : Block ;
2828 metadata : {
2929 parent_rule : null | Rule ;
30+ has_local_selectors : boolean ;
3031 } ;
3132}
3233
You can’t perform that action at this time.
0 commit comments