toplevel atrules within selectors
This commit is contained in:
parent
62f9f7da4f
commit
c017ccfeb4
@ -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 {
|
||||
if super_selector.is_empty() {
|
||||
body.append(&mut rules);
|
||||
} else {
|
||||
body = vec![Spanned {
|
||||
node: Stmt::RuleSet(RuleSet {
|
||||
selector: super_selector.clone(),
|
||||
rules,
|
||||
rules: body,
|
||||
super_selector: Selector::new(),
|
||||
}),
|
||||
span: kind_span,
|
||||
};
|
||||
}];
|
||||
body.append(&mut rules);
|
||||
}
|
||||
|
||||
Ok(UnknownAtRule {
|
||||
name: name.to_owned(),
|
||||
|
10
src/lib.rs
10
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)]
|
||||
|
@ -11,6 +11,7 @@ enum Toplevel {
|
||||
MultilineComment(String),
|
||||
AtRule(AtRule),
|
||||
Newline,
|
||||
Style(Box<Style>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -98,7 +99,7 @@ impl Css {
|
||||
vals
|
||||
}
|
||||
Stmt::MultilineComment(s) => vec![Toplevel::MultilineComment(s)],
|
||||
Stmt::Style(_) => panic!("expected toplevel element, found style"),
|
||||
Stmt::Style(s) => vec![Toplevel::Style(s)],
|
||||
Stmt::AtRule(r) => vec![Toplevel::AtRule(r)],
|
||||
})
|
||||
}
|
||||
@ -165,6 +166,9 @@ impl Css {
|
||||
}
|
||||
_ => todo!("at-rule other than unknown at toplevel"),
|
||||
},
|
||||
Toplevel::Style(s) => {
|
||||
writeln!(buf, "{}{}", padding, s.to_string()?)?;
|
||||
}
|
||||
Toplevel::Newline => {
|
||||
if has_written {
|
||||
writeln!(buf)?
|
||||
|
@ -20,3 +20,4 @@ test!(
|
||||
basic_unknown_at_rule,
|
||||
"@foo {\n a {\n color: red;\n }\n}\n"
|
||||
);
|
||||
test!(unknown_at_rule_no_selector, "@foo {\n color: red;\n}\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user