From f20c000b545b82e776dfee1dc18ee87d6cabe57d Mon Sep 17 00:00:00 2001 From: connorskees Date: Sat, 7 Jan 2023 05:31:13 +0000 Subject: [PATCH] is_true => is_truthy --- grass_internal/src/builtin/functions/list.rs | 2 +- grass_internal/src/builtin/functions/math.rs | 6 ++++-- grass_internal/src/builtin/functions/meta.rs | 4 ++-- grass_internal/src/evaluate/visitor.rs | 13 ++++++++----- grass_internal/src/value/mod.rs | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/grass_internal/src/builtin/functions/list.rs b/grass_internal/src/builtin/functions/list.rs index 012f06e..2753d00 100644 --- a/grass_internal/src/builtin/functions/list.rs +++ b/grass_internal/src/builtin/functions/list.rs @@ -231,7 +231,7 @@ pub(crate) fn join(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResul _ => Brackets::Bracketed, }, v => { - if v.is_true() { + if v.is_truthy() { Brackets::Bracketed } else { Brackets::None diff --git a/grass_internal/src/builtin/functions/math.rs b/grass_internal/src/builtin/functions/math.rs index fd8e68b..c16f242 100644 --- a/grass_internal/src/builtin/functions/math.rs +++ b/grass_internal/src/builtin/functions/math.rs @@ -188,7 +188,8 @@ pub(crate) fn min(args: ArgumentResult, visitor: &mut Visitor) -> SassResult SassResult ArgumentDeclaration { fn if_(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult { 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")?) } else { Ok(args.get_err(2, "if-false")?) @@ -249,7 +249,7 @@ pub(crate) fn get_function(mut args: ArgumentResult, visitor: &mut Visitor) -> S .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) { Value::String(s, ..) => Some(s), Value::Null => None, diff --git a/grass_internal/src/evaluate/visitor.rs b/grass_internal/src/evaluate/visitor.rs index dcfad17..1883a7d 100644 --- a/grass_internal/src/evaluate/visitor.rs +++ b/grass_internal/src/evaluate/visitor.rs @@ -1773,7 +1773,10 @@ impl<'a> Visitor<'a> { self.with_scope(true, true, |visitor| { 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() { let val = visitor.visit_stmt(stmt)?; if val.is_some() { @@ -1790,7 +1793,7 @@ impl<'a> Visitor<'a> { fn visit_if_stmt(&mut self, if_stmt: AstIf) -> SassResult> { let mut clause: Option> = if_stmt.else_clause; 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); break; } @@ -2591,7 +2594,7 @@ impl<'a> Visitor<'a> { 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)? } else { self.visit_expr(if_false)? @@ -2681,14 +2684,14 @@ impl<'a> Visitor<'a> { single_eq(&left, &right, self.options, span)? } BinaryOp::Or => { - if left.is_true() { + if left.is_truthy() { left } else { self.visit_expr(rhs)? } } BinaryOp::And => { - if left.is_true() { + if left.is_truthy() { self.visit_expr(rhs)? } else { left diff --git a/grass_internal/src/value/mod.rs b/grass_internal/src/value/mod.rs index 13242cd..1177e11 100644 --- a/grass_internal/src/value/mod.rs +++ b/grass_internal/src/value/mod.rs @@ -225,7 +225,7 @@ impl Value { inspect_value(self, &Options::default(), span) } - pub fn is_true(&self) -> bool { + pub fn is_truthy(&self) -> bool { !matches!(self, Value::Null | Value::False) }