diff --git a/src/builtin/functions/meta.rs b/src/builtin/functions/meta.rs index b3c569c..71587d1 100644 --- a/src/builtin/functions/meta.rs +++ b/src/builtin/functions/meta.rs @@ -7,6 +7,7 @@ use crate::{ common::{Identifier, QuoteKind}, error::SassResult, parse::Parser, + unit::Unit, value::{SassFunction, Value}, }; @@ -72,7 +73,17 @@ pub(crate) fn type_of(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult pub(crate) fn unitless(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { args.max_args(1)?; - Ok(Value::bool(args.get_err(0, "number")?.unitless())) + Ok(match args.get_err(0, "number")? { + Value::Dimension(_, Unit::None, _) => Value::True, + Value::Dimension(..) => Value::False, + v => { + return Err(( + format!("$number: {} is not a number.", v.inspect(args.span())?), + args.span(), + ) + .into()) + } + }) } pub(crate) fn inspect(mut args: CallArgs, parser: &mut Parser<'_>) -> SassResult { diff --git a/src/value/mod.rs b/src/value/mod.rs index 7e7291a..141c74e 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -380,15 +380,6 @@ impl Value { }) } - pub fn unitless(&self) -> bool { - #[allow(clippy::match_same_arms)] - match self { - Value::Dimension(_, Unit::None, _) => true, - Value::Dimension(..) => false, - _ => true, - } - } - pub fn not_equals(&self, other: &Self) -> bool { match self { Value::String(s1, ..) => match other { diff --git a/tests/meta.rs b/tests/meta.rs index c3c31ed..8bcf4ea 100644 --- a/tests/meta.rs +++ b/tests/meta.rs @@ -213,10 +213,9 @@ test!( "a {\n color: unitless(1)\n}\n", "a {\n color: true;\n}\n" ); -test!( +error!( unitless_string, - "a {\n color: unitless(foo)\n}\n", - "a {\n color: true;\n}\n" + "a {\n color: unitless(foo)\n}\n", "Error: $number: foo is not a number." ); test!( variable_does_exist,