is_true => is_truthy

This commit is contained in:
connorskees 2023-01-07 05:31:13 +00:00
parent ae88b3ed24
commit f20c000b54
5 changed files with 16 additions and 11 deletions

View File

@ -231,7 +231,7 @@ pub(crate) fn join(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResul
_ => Brackets::Bracketed, _ => Brackets::Bracketed,
}, },
v => { v => {
if v.is_true() { if v.is_truthy() {
Brackets::Bracketed Brackets::Bracketed
} else { } else {
Brackets::None Brackets::None

View File

@ -188,7 +188,8 @@ pub(crate) fn min(args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Val
as_slash: None, as_slash: None,
}); });
if crate::evaluate::cmp(&lhs, &rhs, visitor.options, span, BinaryOp::LessThan)?.is_true() { if crate::evaluate::cmp(&lhs, &rhs, visitor.options, span, BinaryOp::LessThan)?.is_truthy()
{
min = (num, unit); min = (num, unit);
} }
} }
@ -233,7 +234,8 @@ pub(crate) fn max(args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Val
as_slash: None, as_slash: None,
}); });
if crate::evaluate::cmp(&lhs, &rhs, visitor.options, span, BinaryOp::GreaterThan)?.is_true() if crate::evaluate::cmp(&lhs, &rhs, visitor.options, span, BinaryOp::GreaterThan)?
.is_truthy()
{ {
max = (num, unit); max = (num, unit);
} }

View File

@ -24,7 +24,7 @@ pub(crate) fn if_arguments() -> ArgumentDeclaration {
fn if_(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Value> { fn if_(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Value> {
args.max_args(3)?; args.max_args(3)?;
if args.get_err(0, "condition")?.is_true() { if args.get_err(0, "condition")?.is_truthy() {
Ok(args.get_err(1, "if-true")?) Ok(args.get_err(1, "if-true")?)
} else { } else {
Ok(args.get_err(2, "if-false")?) Ok(args.get_err(2, "if-false")?)
@ -249,7 +249,7 @@ pub(crate) fn get_function(mut args: ArgumentResult, visitor: &mut Visitor) -> S
.into()) .into())
} }
}; };
let css = args.default_arg(1, "css", Value::False).is_true(); let css = args.default_arg(1, "css", Value::False).is_truthy();
let module = match args.default_arg(2, "module", Value::Null) { let module = match args.default_arg(2, "module", Value::Null) {
Value::String(s, ..) => Some(s), Value::String(s, ..) => Some(s),
Value::Null => None, Value::Null => None,

View File

@ -1773,7 +1773,10 @@ impl<'a> Visitor<'a> {
self.with_scope(true, true, |visitor| { self.with_scope(true, true, |visitor| {
let mut result = None; let mut result = None;
'outer: while visitor.visit_expr(while_stmt.condition.clone())?.is_true() { 'outer: while visitor
.visit_expr(while_stmt.condition.clone())?
.is_truthy()
{
for stmt in while_stmt.body.clone() { for stmt in while_stmt.body.clone() {
let val = visitor.visit_stmt(stmt)?; let val = visitor.visit_stmt(stmt)?;
if val.is_some() { if val.is_some() {
@ -1790,7 +1793,7 @@ impl<'a> Visitor<'a> {
fn visit_if_stmt(&mut self, if_stmt: AstIf) -> SassResult<Option<Value>> { fn visit_if_stmt(&mut self, if_stmt: AstIf) -> SassResult<Option<Value>> {
let mut clause: Option<Vec<AstStmt>> = if_stmt.else_clause; let mut clause: Option<Vec<AstStmt>> = if_stmt.else_clause;
for clause_to_check in if_stmt.if_clauses { for clause_to_check in if_stmt.if_clauses {
if self.visit_expr(clause_to_check.condition)?.is_true() { if self.visit_expr(clause_to_check.condition)?.is_truthy() {
clause = Some(clause_to_check.body); clause = Some(clause_to_check.body);
break; break;
} }
@ -2591,7 +2594,7 @@ impl<'a> Visitor<'a> {
positional.remove(0) positional.remove(0)
}; };
let value = if self.visit_expr(condition)?.is_true() { let value = if self.visit_expr(condition)?.is_truthy() {
self.visit_expr(if_true)? self.visit_expr(if_true)?
} else { } else {
self.visit_expr(if_false)? self.visit_expr(if_false)?
@ -2681,14 +2684,14 @@ impl<'a> Visitor<'a> {
single_eq(&left, &right, self.options, span)? single_eq(&left, &right, self.options, span)?
} }
BinaryOp::Or => { BinaryOp::Or => {
if left.is_true() { if left.is_truthy() {
left left
} else { } else {
self.visit_expr(rhs)? self.visit_expr(rhs)?
} }
} }
BinaryOp::And => { BinaryOp::And => {
if left.is_true() { if left.is_truthy() {
self.visit_expr(rhs)? self.visit_expr(rhs)?
} else { } else {
left left

View File

@ -225,7 +225,7 @@ impl Value {
inspect_value(self, &Options::default(), span) inspect_value(self, &Options::default(), span)
} }
pub fn is_true(&self) -> bool { pub fn is_truthy(&self) -> bool {
!matches!(self, Value::Null | Value::False) !matches!(self, Value::Null | Value::False)
} }