better handle maps, arglists, and mul units in @debug

This commit is contained in:
Connor Skees 2020-07-05 07:31:10 -04:00
parent 91ef5dcfd5
commit dbfd90d444
2 changed files with 35 additions and 6 deletions

View File

@ -282,15 +282,23 @@ impl Value {
Value::Map(map) => Cow::owned(format!(
"({})",
map.iter()
.map(|(k, v)| Ok(format!(
"{}: {}",
k.to_css_string(span)?,
v.to_css_string(span)?
)))
.map(|(k, v)| Ok(format!("{}: {}", k.inspect(span)?, v.inspect(span)?)))
.collect::<SassResult<Vec<String>>>()?
.join(", ")
)),
v => v.to_css_string(span)?,
Value::Dimension(num, unit) => Cow::owned(format!("{}{}", num, unit)),
Value::ArgList(args) => Cow::owned(
args.iter()
.filter(|x| !x.is_null())
.map(|a| Ok(a.node.inspect(span)?))
.collect::<SassResult<Vec<Cow<'static, str>>>>()?
.join(", "),
),
Value::Important
| Value::True
| Value::False
| Value::Color(..)
| Value::String(..) => self.to_css_string(span)?,
})
}

View File

@ -110,3 +110,24 @@ test!(
"a {\n color: inspect((((a))));\n}\n",
"a {\n color: a;\n}\n"
);
test!(
inspect_mul_units,
"a {\n color: inspect(1em * 1px);\n}\n",
"a {\n color: 1em*px;\n}\n"
);
test!(
inspect_map_with_map_key_and_value,
"a {\n color: inspect(((a: b): (c: d)));\n}\n",
"a {\n color: ((a: b): (c: d));\n}\n"
);
test!(
inspect_map_in_arglist,
"@function foo($a...) {
@return inspect($a);
}
a {
color: foo((a: b));
}",
"a {\n color: (a: b);\n}\n"
);