type-of(!important) returns 'string'

This commit is contained in:
ConnorSkees 2020-03-23 15:13:19 -04:00
parent 68d2bc7e17
commit e6f2c26bc6
2 changed files with 16 additions and 10 deletions

View File

@ -24,6 +24,8 @@ pub(crate) enum Value {
BinaryOp(Box<Value>, Op, Box<Value>),
Paren(Box<Value>),
Ident(String, QuoteKind),
// Returned by `get-function()`
// Function(String),
}
impl Display for Value {
@ -109,7 +111,7 @@ impl Value {
pub fn is_true(&self) -> SassResult<bool> {
match self {
Value::Null | Value::False => Ok(false),
Self::BinaryOp(..) => self.clone().eval()?.is_true(),
Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => self.clone().eval()?.is_true(),
_ => Ok(true),
}
}
@ -123,15 +125,14 @@ impl Value {
pub fn kind(&self) -> SassResult<&'static str> {
match self {
Value::Color(..) => Ok("color"),
Value::Ident(..) => Ok("string"),
Value::Dimension(..) => Ok("number"),
Value::List(..) => Ok("list"),
// Value::Function(..) => Ok("function"),
Value::True | Value::False => Ok("bool"),
Value::Null => Ok("null"),
Value::BinaryOp(..) => self.clone().eval()?.kind(),
_ => Ok("unknown"),
Self::Color(..) => Ok("color"),
Self::Ident(..) | Self::Important => Ok("string"),
Self::Dimension(..) => Ok("number"),
Self::List(..) => Ok("list"),
// Self::Function(..) => Ok("function"),
Self::True | Self::False => Ok("bool"),
Self::Null => Ok("null"),
Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => self.clone().eval()?.kind(),
}
}

View File

@ -139,6 +139,11 @@ test!(
"a {\n color: type-of(1 2 3)\n}\n",
"a {\n color: list;\n}\n"
);
test!(
type_of_important,
"a {\n color: type-of(!important)\n}\n",
"a {\n color: string;\n}\n"
);
test!(
type_of_true,
"a {\n color: type-of(true)\n}\n",