mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(css/modules): Fix interop of &
and :global
(#6900)
This commit is contained in:
parent
c293c14aaa
commit
f85ea9cb57
@ -374,7 +374,7 @@ where
|
||||
|
||||
'complex: for mut n in n.children.take() {
|
||||
if let ComplexSelectorChildren::CompoundSelector(selector) = &mut n {
|
||||
for sel in &mut selector.subclass_selectors {
|
||||
for (sel_index, sel) in selector.subclass_selectors.iter_mut().enumerate() {
|
||||
match sel {
|
||||
SubclassSelector::Class(..) | SubclassSelector::Id(..) => {
|
||||
if !self.data.is_global_mode {
|
||||
@ -402,7 +402,17 @@ where
|
||||
|
||||
complex_selector.visit_mut_with(self);
|
||||
|
||||
new_children.extend(complex_selector.children.clone());
|
||||
let mut complex_selector_children =
|
||||
complex_selector.children.clone();
|
||||
prepend_left_subclass_selectors(
|
||||
&mut complex_selector_children,
|
||||
selector
|
||||
.subclass_selectors
|
||||
.split_at(sel_index)
|
||||
.0
|
||||
.to_vec(),
|
||||
);
|
||||
new_children.extend(complex_selector_children);
|
||||
|
||||
self.data.is_global_mode = old_is_global_mode;
|
||||
self.data.is_in_local_pseudo_class = old_inside;
|
||||
@ -419,7 +429,17 @@ where
|
||||
complex_selector,
|
||||
)) = children.get_mut(0)
|
||||
{
|
||||
new_children.extend(complex_selector.children.clone());
|
||||
let mut complex_selector_children =
|
||||
complex_selector.children.clone();
|
||||
prepend_left_subclass_selectors(
|
||||
&mut complex_selector_children,
|
||||
selector
|
||||
.subclass_selectors
|
||||
.split_at(sel_index)
|
||||
.0
|
||||
.to_vec(),
|
||||
);
|
||||
new_children.extend(complex_selector_children);
|
||||
}
|
||||
} else {
|
||||
self.data.is_global_mode = true;
|
||||
@ -523,3 +543,14 @@ fn process_local<C>(
|
||||
SubclassSelector::PseudoElement(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn prepend_left_subclass_selectors(
|
||||
complex_selector_children: &mut [ComplexSelectorChildren],
|
||||
left_sels: Vec<SubclassSelector>,
|
||||
) {
|
||||
if let Some(ComplexSelectorChildren::CompoundSelector(first)) =
|
||||
complex_selector_children.get_mut(0)
|
||||
{
|
||||
first.subclass_selectors = [left_sels, first.subclass_selectors.take()].concat();
|
||||
}
|
||||
}
|
||||
|
@ -5,3 +5,9 @@
|
||||
.global {
|
||||
color: blue;
|
||||
}
|
||||
.__local__local.global {
|
||||
color: green;
|
||||
}
|
||||
.__local__local.__local__local {
|
||||
color: yellow;
|
||||
}
|
||||
|
@ -6,3 +6,11 @@
|
||||
:global(.global) {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.local:global(.global) {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.local:local(.local) {
|
||||
color: yellow;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ div:not(.__local__a) {
|
||||
.__local__😓 .__local__a {
|
||||
color: red;
|
||||
}
|
||||
.__local__a {
|
||||
.__local__😓.__local__a {
|
||||
color: red;
|
||||
}
|
||||
.__local__a > .__local__b > .__local__c {
|
||||
|
Loading…
Reference in New Issue
Block a user