more robustly emit empty arglists

This commit is contained in:
Connor Skees 2020-07-06 18:10:22 -04:00
parent 9936656077
commit 22cc36b578
2 changed files with 26 additions and 1 deletions

View File

@ -185,6 +185,9 @@ impl Value {
Value::True => Cow::const_str("true"), Value::True => Cow::const_str("true"),
Value::False => Cow::const_str("false"), Value::False => Cow::const_str("false"),
Value::Null => Cow::const_str(""), Value::Null => Cow::const_str(""),
Value::ArgList(args) if args.is_empty() => {
return Err(("() isn't a valid CSS value.", span).into());
}
Value::ArgList(args) => Cow::owned( Value::ArgList(args) => Cow::owned(
args.iter() args.iter()
.filter(|x| !x.is_null()) .filter(|x| !x.is_null())
@ -287,6 +290,7 @@ impl Value {
.join(", ") .join(", ")
)), )),
Value::Dimension(num, unit) => Cow::owned(format!("{}{}", num, unit)), Value::Dimension(num, unit) => Cow::owned(format!("{}{}", num, unit)),
Value::ArgList(args) if args.is_empty() => Cow::const_str("()"),
Value::ArgList(args) => Cow::owned( Value::ArgList(args) => Cow::owned(
args.iter() args.iter()
.filter(|x| !x.is_null()) .filter(|x| !x.is_null())

View File

@ -21,7 +21,6 @@ test!(
@each $number in $numbers { @each $number in $numbers {
$sum: $sum + $number; $sum: $sum + $number;
} }
@return $sum; @return $sum;
} }
@ -30,3 +29,25 @@ test!(
}", }",
"a {\n width: 180px;\n}\n" "a {\n width: 180px;\n}\n"
); );
error!(
emit_empty_arglist,
"@function foo($a...) {
@return $a;
}
a {
color: foo();
}",
"Error: () isn't a valid CSS value."
);
test!(
inspect_empty_arglist,
"@function foo($a...) {
@return inspect($a);
}
a {
color: foo();
}",
"a {\n color: ();\n}\n"
);