handle quoted strings in variable-exists

This commit is contained in:
ConnorSkees 2020-03-23 14:34:03 -04:00
parent 712795544b
commit d0b56c57d2
2 changed files with 13 additions and 2 deletions

View File

@ -83,8 +83,10 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
"variable-exists".to_owned(),
Box::new(|args, scope| {
max_args!(args, 1);
let value = arg!(args, 0, "name");
Ok(Value::bool(scope.var_exists(&value.to_string())))
match arg!(args, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
v => Err(format!("$name: {} is not a string.", v).into()),
}
}),
);
f.insert(

View File

@ -244,6 +244,15 @@ test!(
"$a: red; a {\n color: variable-exists($name: a)\n}\n",
"a {\n color: true;\n}\n"
);
test!(
variable_exists_quoted,
"$a: red; a {\n color: variable-exists('a')\n}\n",
"a {\n color: true;\n}\n"
);
error!(
variable_exists_not_string,
"a {\n color: variable-exists(12px)\n}\n", "Error: $name: 12px is not a string."
);
test!(
mixin_does_exist,
"@mixin a{} a {\n color: mixin-exists(a)\n}\n",