handle non-string keys in splatted map

This commit is contained in:
Connor Skees 2020-07-06 17:54:55 -04:00
parent 7c320ae9a2
commit 9936656077
2 changed files with 39 additions and 2 deletions

View File

@ -231,8 +231,24 @@ impl<'a> Parser<'a> {
}
}
Value::Map(v) => {
for (name, arg) in v.entries() {
let name = name.to_css_string(val.span)?.to_string();
// NOTE: we clone the map here because it is used
// later for error reporting. perhaps there is
// some way around this?
for (name, arg) in v.clone().entries() {
let name = match name {
Value::String(s, ..) => s,
_ => {
return Err((
format!(
"{} is not a string in {}.",
name.inspect(val.span)?,
Value::Map(v).inspect(val.span)?
),
val.span,
)
.into())
}
};
args.insert(CallArg::Named(name.into()), Ok(arg.span(val.span)));
}
}

View File

@ -33,6 +33,13 @@ test!(
}",
"a {\n color: 1;\n}\n"
);
test!(
splat_map_quoted_string_as_key,
"a {
color: red((\"color\": red)...);
}",
"a {\n color: 255;\n}\n"
);
error!(
splat_missing_last_period,
"@function foo($a) {
@ -53,3 +60,17 @@ error!(
}",
"Error: expected \")\"."
);
error!(
splat_map_with_non_string_key_map,
"a {
color: red(((a: b): red)...);
}",
"Error: (a: b) is not a string in ((a: b): red)."
);
error!(
splat_map_with_non_string_key_number,
"a {
color: red((1: red)...);
}",
"Error: 1 is not a string in (1: red)."
);