From c017ccfeb40d30aedf90a23e53c1f3c2d0ec445d Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 12 Apr 2020 21:47:32 -0400 Subject: [PATCH] toplevel atrules within selectors --- src/atrule/unknown.rs | 34 ++++++++++++++++++---------------- src/lib.rs | 10 ---------- src/output.rs | 6 +++++- tests/media.rs | 1 + 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/atrule/unknown.rs b/src/atrule/unknown.rs index 088b18c..bfd0079 100644 --- a/src/atrule/unknown.rs +++ b/src/atrule/unknown.rs @@ -50,27 +50,29 @@ impl UnknownAtRule { } let raw_body = eat_stmts(toks, scope, super_selector)?; - let mut body = Vec::with_capacity(raw_body.len()); - body.push(Spanned { - node: Stmt::RuleSet(RuleSet::new()), - span: kind_span, - }); - let mut rules = Vec::new(); + let mut rules = Vec::with_capacity(raw_body.len()); + let mut body = Vec::new(); + for stmt in raw_body { match stmt.node { - Stmt::Style(..) => rules.push(stmt), - _ => body.push(stmt), + Stmt::Style(..) => body.push(stmt), + _ => rules.push(stmt), } } - body[0] = Spanned { - node: Stmt::RuleSet(RuleSet { - selector: super_selector.clone(), - rules, - super_selector: Selector::new(), - }), - span: kind_span, - }; + if super_selector.is_empty() { + body.append(&mut rules); + } else { + body = vec![Spanned { + node: Stmt::RuleSet(RuleSet { + selector: super_selector.clone(), + rules: body, + super_selector: Selector::new(), + }), + span: kind_span, + }]; + body.append(&mut rules); + } Ok(UnknownAtRule { name: name.to_owned(), diff --git a/src/lib.rs b/src/lib.rs index ef9bf36..cbae5c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,16 +160,6 @@ pub(crate) struct RuleSet { super_selector: Selector, } -impl RuleSet { - pub(crate) const fn new() -> RuleSet { - RuleSet { - selector: Selector::new(), - rules: Vec::new(), - super_selector: Selector::new(), - } - } -} - /// An intermediate representation of what are essentially single lines /// todo! rename this #[derive(Clone, Debug)] diff --git a/src/output.rs b/src/output.rs index 3214751..ccb2ccd 100644 --- a/src/output.rs +++ b/src/output.rs @@ -11,6 +11,7 @@ enum Toplevel { MultilineComment(String), AtRule(AtRule), Newline, + Style(Box