encountering placeholder selector resets has_written

This commit is contained in:
Connor Skees 2021-07-23 03:28:41 -04:00
parent ec4fe9164d
commit 548a5921e6
3 changed files with 63 additions and 1 deletions

View File

@ -125,7 +125,7 @@ impl Css {
let selector = selector.into_selector().remove_placeholders();
if selector.is_empty() {
return Ok(Vec::new());
return Ok(vec![Toplevel::new_rule(selector)]);
}
let mut vals = vec![Toplevel::new_rule(selector)];
@ -494,6 +494,11 @@ impl Formatter for ExpandedFormatter {
for block in css.blocks {
match block {
Toplevel::RuleSet(selector, styles) => {
if selector.is_empty() {
has_written = false;
continue;
}
if styles.is_empty() {
continue;
}

View File

@ -98,3 +98,45 @@ test!(
/**/",
"/**/\n/**/\n"
);
test!(
no_extra_newline_when_after_placeholder_selector,
r"a {
color: red;
%b {
color: red;
}
}
/**/
c {
color: red;
}
/**/",
"a {\n color: red;\n}\n/**/\nc {\n color: red;\n}\n\n/**/\n"
);
test!(
extra_newline_when_after_regular_selector_after_placeholder_selector,
r"a {
color: red;
%b {
color: red;
}
d {
color: red;
}
}
/**/
c {
color: red;
}
/**/",
"a {\n color: red;\n}\na d {\n color: red;\n}\n\n/**/\nc {\n color: red;\n}\n\n/**/\n"
);

View File

@ -829,6 +829,21 @@ test!(
"[a=\"a\\\\66 \"] {\n color: &;\n}\n",
"[a=\"a\\\\66 \"] {\n color: [a=\"a\\\\66 \"];\n}\n"
);
test!(
no_newline_between_styles_when_last_style_was_placeholder,
"a {
color: red;
%b {
color: red;
}
}
c {
color: red;
}",
"a {\n color: red;\n}\nc {\n color: red;\n}\n"
);
error!(
a_n_plus_b_n_invalid_odd,
":nth-child(ofdd) {\n color: &;\n}\n", "Error: Expected \"odd\"."