Correctly print whitespace when no params in at rule

This commit is contained in:
ConnorSkees 2020-02-22 17:09:15 -05:00
parent 260b357bba
commit bf0ce2fe1a
2 changed files with 9 additions and 1 deletions

View File

@ -134,7 +134,11 @@ impl Css {
} }
Toplevel::AtRule(r) => match r { Toplevel::AtRule(r) => match r {
AtRule::Unknown(u) => { AtRule::Unknown(u) => {
if u.params.is_empty() {
writeln!(buf, "{}@{} {{", padding, u.name)?;
} else {
writeln!(buf, "{}@{} {} {{", padding, u.name, u.params)?; writeln!(buf, "{}@{} {} {{", padding, u.name, u.params)?;
}
Css::from_stylesheet(StyleSheet::from_stmts(u.body.clone())) Css::from_stylesheet(StyleSheet::from_stmts(u.body.clone()))
.pretty_print(buf, nesting + 1) .pretty_print(buf, nesting + 1)
.unwrap(); .unwrap();

View File

@ -7,6 +7,10 @@ test!(
basic_toplevel, basic_toplevel,
"@media foo {\n a {\n color: red;\n }\n}\n" "@media foo {\n a {\n color: red;\n }\n}\n"
); );
test!(
toplevel_no_params,
"@media {\n a {\n color: red;\n }\n}\n"
);
test!( test!(
basic_nested, basic_nested,
"a {\n @media foo {\n color: red;\n }\n}\n", "a {\n @media foo {\n color: red;\n }\n}\n",