From ec4fe9164d9629b58c27ee156b32b8ddd21003a2 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Fri, 23 Jul 2021 03:08:23 -0400 Subject: [PATCH] do not emit newline between media query and ruleset --- src/output.rs | 6 ++++-- tests/media.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/output.rs b/src/output.rs index fce2fdf..3f9f848 100644 --- a/src/output.rs +++ b/src/output.rs @@ -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)?; } diff --git a/tests/media.rs b/tests/media.rs index b4dea5f..0e87f41 100644 --- a/tests/media.rs +++ b/tests/media.rs @@ -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,