handle quoted strings in variable-exists
This commit is contained in:
parent
712795544b
commit
d0b56c57d2
@ -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(
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user