diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index a734b9f..6c67609 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -107,19 +107,22 @@ pub(crate) fn register(f: &mut HashMap) { "mixin-exists".to_owned(), Box::new(|args, scope| { max_args!(args, 1); - let value = arg!(args, 0, "name"); - Ok(Value::bool(scope.mixin_exists(&value.to_string()))) + match arg!(args, 0, "name") { + Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))), + v => Err(format!("$name: {} is not a string.", v).into()), + } }), ); f.insert( "function-exists".to_owned(), Box::new(|args, scope| { max_args!(args, 1); - let value = arg!(args, 0, "name"); - let s = value.unquote().to_string(); - Ok(Value::bool( - scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(&s), - )) + match arg!(args, 0, "name") { + Value::Ident(s, _) => Ok(Value::bool( + scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(&s), + )), + v => Err(format!("$name: {} is not a string.", v).into()), + } }), ); f.insert("call".to_owned(), Box::new(|_args, _scope| { diff --git a/src/value/mod.rs b/src/value/mod.rs index 9bb4e6f..4259357 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -111,7 +111,9 @@ impl Value { pub fn is_true(&self) -> SassResult { match self { Value::Null | Value::False => Ok(false), - Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => self.clone().eval()?.is_true(), + Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => { + self.clone().eval()?.is_true() + } _ => Ok(true), } } diff --git a/tests/meta.rs b/tests/meta.rs index 818200d..94b5d16 100644 --- a/tests/meta.rs +++ b/tests/meta.rs @@ -278,6 +278,11 @@ test!( "@function a(){} a {\n color: function-exists(a)\n}\n", "a {\n color: true;\n}\n" ); +test!( + builtin_function_does_exist, + "a {\n color: function-exists(function-exists)\n}\n", + "a {\n color: true;\n}\n" +); test!( function_does_not_exist, "a {\n color: function-exists(a)\n}\n", @@ -288,6 +293,14 @@ test!( "@function a(){} a {\n color: function-exists($name: a)\n}\n", "a {\n color: true;\n}\n" ); +error!( + function_exists_non_string, + "a {color:function-exists(12px)}", "Error: $name: 12px is not a string." +); +error!( + mixin_exists_non_string, + "a {color:mixin-exists(12px)}", "Error: $name: 12px is not a string." +); // test!( // inspect_empty_list, // "a {\n color: inspect(())\n}\n",