Initial implementation of placeholder selectors
This commit is contained in:
parent
93911c30b0
commit
ed4d19fe96
@ -72,7 +72,11 @@ impl Css {
|
||||
super_selector,
|
||||
rules,
|
||||
}) => {
|
||||
let mut vals = vec![Toplevel::new_rule(super_selector.zip(&selector))];
|
||||
let selector = super_selector.zip(&selector).remove_placeholders();
|
||||
if selector.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut vals = vec![Toplevel::new_rule(selector)];
|
||||
for rule in rules {
|
||||
match rule {
|
||||
Stmt::RuleSet(_) => vals.extend(self.parse_stmt(rule)),
|
||||
|
@ -351,6 +351,34 @@ impl Selector {
|
||||
}
|
||||
Selector(rules)
|
||||
}
|
||||
|
||||
pub fn remove_placeholders(self) -> Selector {
|
||||
let mut selectors = Vec::with_capacity(self.0.len());
|
||||
let mut temp_sels = Vec::new();
|
||||
let mut found_placeholder = false;
|
||||
for sel in self.0 {
|
||||
match sel {
|
||||
SelectorKind::Placeholder => found_placeholder = true,
|
||||
SelectorKind::Multiple => {
|
||||
temp_sels.push(SelectorKind::Multiple);
|
||||
if !found_placeholder {
|
||||
selectors.extend(temp_sels.clone());
|
||||
}
|
||||
temp_sels.clear();
|
||||
found_placeholder = false;
|
||||
}
|
||||
_ => temp_sels.push(sel),
|
||||
}
|
||||
}
|
||||
if !found_placeholder {
|
||||
selectors.extend(temp_sels);
|
||||
}
|
||||
Selector(selectors)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
|
@ -277,3 +277,19 @@ test!(
|
||||
// "a,, {\n b {\n color: /**/red;\n }\n}\n",
|
||||
// "a b {\n color: red;\n}\n"
|
||||
// );
|
||||
test!(simple_placeholder, "%a {\n color: red;\n}\n", "");
|
||||
test!(
|
||||
placeholder_first,
|
||||
"%a, b {\n color: red;\n}\n",
|
||||
"b {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
placeholder_last,
|
||||
"a, %b {\n color: red;\n}\n",
|
||||
"a {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
placeholder_middle,
|
||||
"a, %b, c {\n color: red;\n}\n",
|
||||
"a, c {\n color: red;\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user