at-root with nothing contains super selector

This commit is contained in:
ConnorSkees 2020-04-06 13:30:36 -04:00
parent 648dc04c33
commit 8802a92f9b
3 changed files with 27 additions and 10 deletions

View File

@ -126,6 +126,20 @@ impl AtRule {
styles.push(s);
None
}
Stmt::RuleSet(RuleSet {
selector: mut selector2,
rules,
super_selector: super_selector2,
}) => {
if selector.is_empty() {
selector2 = Selector::replace(super_selector.clone(), selector2);
}
Some(Stmt::RuleSet(RuleSet {
selector: selector2,
rules,
super_selector: super_selector2,
}))
}
_ => Some(s),
})
.collect::<Vec<Stmt>>();

View File

@ -18,16 +18,6 @@ mod attribute;
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct Selector(Vec<SelectorPart>);
impl Selector {
pub const fn new() -> Selector {
Selector(Vec::new())
}
pub fn contains_super_selector(&self) -> bool {
self.0.iter().any(|s| s.contains_super_selector)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
struct SelectorPart {
pub inner: Vec<SelectorKind>,
@ -543,4 +533,12 @@ impl Selector {
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub const fn new() -> Selector {
Selector(Vec::new())
}
pub fn contains_super_selector(&self) -> bool {
self.0.iter().any(|s| s.contains_super_selector)
}
}

View File

@ -33,3 +33,8 @@ test!(
".foo {\n @at-root .bar {\n a: b;\n c {\n d: e;\n foo {\n bar: baz;\n }\n h: j;\n }\n f: g;\n }\n}\n",
".bar {\n a: b;\n f: g;\n}\n.bar c {\n d: e;\n h: j;\n}\n.bar c foo {\n bar: baz;\n}\n"
);
test!(
super_selector_inside_with_nothing,
"foo {\n @at-root {\n & {\n color: bar;\n }\n }\n}\n",
"foo {\n color: bar;\n}\n"
);