From 8802a92f9b0ee78586532746d0c2a4b6a2cc2fa1 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Mon, 6 Apr 2020 13:30:36 -0400 Subject: [PATCH] at-root with nothing contains super selector --- src/atrule/mod.rs | 14 ++++++++++++++ src/selector/mod.rs | 18 ++++++++---------- tests/at-root.rs | 5 +++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index d14fdc0..c4aa61d 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -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::>(); diff --git a/src/selector/mod.rs b/src/selector/mod.rs index 4c67e59..6ac47c8 100644 --- a/src/selector/mod.rs +++ b/src/selector/mod.rs @@ -18,16 +18,6 @@ mod attribute; #[derive(Clone, Debug, Eq, PartialEq)] pub(crate) struct Selector(Vec); -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, @@ -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) + } } diff --git a/tests/at-root.rs b/tests/at-root.rs index 3aeb444..6bde249 100644 --- a/tests/at-root.rs +++ b/tests/at-root.rs @@ -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" +);