do not emit newline between media query and ruleset

This commit is contained in:
Connor Skees 2021-07-23 03:08:23 -04:00
parent 5c4f11e63d
commit ec4fe9164d
2 changed files with 34 additions and 2 deletions

View File

@ -264,7 +264,9 @@ impl Css {
last_toplevel = ToplevelKind::Other;
}
_ => {
if last_toplevel != ToplevelKind::Comment {
if last_toplevel != ToplevelKind::Comment
&& last_toplevel != ToplevelKind::Media
{
self.blocks.push(Toplevel::Newline);
}
@ -624,7 +626,7 @@ impl Formatter for ExpandedFormatter {
continue;
}
if should_emit_newline {
if should_emit_newline && has_written {
should_emit_newline = false;
writeln!(buf)?;
}

View File

@ -189,6 +189,36 @@ test!(
}",
"a {\n color: red;\n}\n\n@media (min-width: 0px) {\n a {\n color: red;\n }\n}\n@media (min-width: 0px) {\n a {\n color: red;\n }\n}\n"
);
test!(
no_newline_after_media_after_ruleset,
"a {
color: red;
}
@media (min-width: 0px) {
b {
color: red;
}
}
d {
color: red;
}",
"a {\n color: red;\n}\n\n@media (min-width: 0px) {\n b {\n color: red;\n }\n}\nd {\n color: red;\n}\n"
);
test!(
no_newline_after_media,
"@media (min-width: 0px) {
b {
color: red;
}
}
d {
color: red;
}",
"@media (min-width: 0px) {\n b {\n color: red;\n }\n}\nd {\n color: red;\n}\n"
);
error!(
media_feature_missing_closing_paren,