diff --git a/grass_internal/src/ast/expr.rs b/grass_internal/src/ast/expr.rs index df95ad2..84ec01e 100644 --- a/grass_internal/src/ast/expr.rs +++ b/grass_internal/src/ast/expr.rs @@ -26,14 +26,14 @@ pub(crate) struct ListExpr { pub(crate) struct FunctionCallExpr { pub namespace: Option>, pub name: Identifier, - pub arguments: Box, + pub arguments: Arc, pub span: Span, } #[derive(Debug, Clone)] pub(crate) struct InterpolatedFunction { pub name: Interpolation, - pub arguments: Box, + pub arguments: ArgumentInvocation, pub span: Span, } @@ -61,7 +61,7 @@ pub(crate) enum AstExpr { Color(Arc), FunctionCall(FunctionCallExpr), If(Arc), - InterpolatedFunction(InterpolatedFunction), + InterpolatedFunction(Arc), List(ListExpr), Map(AstSassMap), Null, diff --git a/grass_internal/src/evaluate/visitor.rs b/grass_internal/src/evaluate/visitor.rs index 34e8cd0..0ffee6a 100644 --- a/grass_internal/src/evaluate/visitor.rs +++ b/grass_internal/src/evaluate/visitor.rs @@ -2360,7 +2360,8 @@ impl<'a> Visitor<'a> { let old_in_function = self.flags.in_function(); self.flags.set(ContextFlags::IN_FUNCTION, true); - let value = self.run_function_callable(func, *func_call.arguments, func_call.span)?; + let value = + self.run_function_callable(func, (*func_call.arguments).clone(), func_call.span)?; self.flags.set(ContextFlags::IN_FUNCTION, old_in_function); Ok(value) @@ -2381,7 +2382,7 @@ impl<'a> Visitor<'a> { let mut buffer = format!("{}(", fn_name); let mut first = true; - for arg in args.positional { + for arg in args.positional.clone() { if first { first = false; } else { @@ -2391,7 +2392,7 @@ impl<'a> Visitor<'a> { buffer.push_str(&evaluated); } - if let Some(rest_arg) = args.rest { + if let Some(rest_arg) = args.rest.clone() { let rest = self.visit_expr(rest_arg)?; if !first { buffer.push_str(", "); @@ -2421,15 +2422,13 @@ impl<'a> Visitor<'a> { }), AstExpr::List(list) => self.visit_list_expr(list)?, AstExpr::String(StringExpr(text, quote), ..) => self.visit_string(text, quote)?, - AstExpr::BinaryOp(binop) => { - self.visit_bin_op( - binop.lhs.clone(), - binop.op, - binop.rhs.clone(), - binop.allows_slash, - binop.span, - )? - } + AstExpr::BinaryOp(binop) => self.visit_bin_op( + binop.lhs.clone(), + binop.op, + binop.rhs.clone(), + binop.allows_slash, + binop.span, + )?, AstExpr::True => Value::True, AstExpr::False => Value::False, AstExpr::Calculation { name, args } => { @@ -2437,7 +2436,9 @@ impl<'a> Visitor<'a> { } AstExpr::FunctionCall(func_call) => self.visit_function_call_expr(func_call)?, AstExpr::If(if_expr) => self.visit_ternary((*if_expr).clone())?, - AstExpr::InterpolatedFunction(func) => self.visit_interpolated_func_expr(func)?, + AstExpr::InterpolatedFunction(func) => { + self.visit_interpolated_func_expr((*func).clone())? + } AstExpr::Map(map) => self.visit_map(map)?, AstExpr::Null => Value::Null, AstExpr::Paren(expr) => self.visit_expr((*expr).clone())?, @@ -2477,17 +2478,15 @@ impl<'a> Visitor<'a> { debug_assert!(string_expr.1 == QuoteKind::None); CalculationArg::Interpolation(self.perform_interpolation(string_expr.0, false)?) } - AstExpr::BinaryOp(binop) => { - SassCalculation::operate_internal( - binop.op, - self.visit_calculation_value(binop.lhs.clone(), in_min_or_max, span)?, - self.visit_calculation_value(binop.rhs.clone(), in_min_or_max, span)?, - in_min_or_max, - !self.flags.in_supports_declaration(), - self.options, - span, - )? - } + AstExpr::BinaryOp(binop) => SassCalculation::operate_internal( + binop.op, + self.visit_calculation_value(binop.lhs.clone(), in_min_or_max, span)?, + self.visit_calculation_value(binop.rhs.clone(), in_min_or_max, span)?, + in_min_or_max, + !self.flags.in_supports_declaration(), + self.options, + span, + )?, AstExpr::Number { .. } | AstExpr::Calculation { .. } | AstExpr::Variable { .. } diff --git a/grass_internal/src/parse/css.rs b/grass_internal/src/parse/css.rs index 0fa68e1..22a2248 100644 --- a/grass_internal/src/parse/css.rs +++ b/grass_internal/src/parse/css.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, path::Path}; +use std::{collections::BTreeMap, path::Path, sync::Arc}; use codemap::{CodeMap, Span, Spanned}; @@ -203,17 +203,17 @@ impl<'a> CssParser<'a> { return Err(("This function isn't allowed in plain CSS.", span).into()); } - Ok(AstExpr::InterpolatedFunction(InterpolatedFunction { + Ok(AstExpr::InterpolatedFunction(Arc::new(InterpolatedFunction { name: identifier, - arguments: Box::new(ArgumentInvocation { + arguments: ArgumentInvocation { positional: arguments, named: BTreeMap::new(), rest: None, keyword_rest: None, span: self.toks.span_from(before_args), - }), + }, span, - }) + })) .span(span)) } } diff --git a/grass_internal/src/parse/stylesheet.rs b/grass_internal/src/parse/stylesheet.rs index 5e20a77..fe62434 100644 --- a/grass_internal/src/parse/stylesheet.rs +++ b/grass_internal/src/parse/stylesheet.rs @@ -3,7 +3,8 @@ use std::{ collections::{BTreeMap, HashSet}, ffi::OsString, mem, - path::{Path, PathBuf}, sync::Arc, + path::{Path, PathBuf}, + sync::Arc, }; use codemap::{CodeMap, Span, Spanned}; @@ -840,11 +841,11 @@ pub(crate) trait StylesheetParser<'a>: BaseParser<'a> + Sized { StringExpr(contents, QuoteKind::None), self.toks_mut().span_from(start), ), - None => AstExpr::InterpolatedFunction(InterpolatedFunction { + None => AstExpr::InterpolatedFunction(Arc::new(InterpolatedFunction { name: Interpolation::new_plain("url".to_owned()), - arguments: Box::new(self.parse_argument_invocation(false, false)?), + arguments: self.parse_argument_invocation(false, false)?, span: self.toks_mut().span_from(start), - }), + })), }) } diff --git a/grass_internal/src/parse/value.rs b/grass_internal/src/parse/value.rs index 866369a..307dc20 100644 --- a/grass_internal/src/parse/value.rs +++ b/grass_internal/src/parse/value.rs @@ -1228,17 +1228,17 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> { Ok(AstExpr::FunctionCall(FunctionCallExpr { namespace: None, name: Identifier::from(plain), - arguments: Box::new(arguments), + arguments: Arc::new(arguments), span: parser.toks_mut().span_from(start), }) .span(parser.toks_mut().span_from(start))) } else { let arguments = parser.parse_argument_invocation(false, false)?; - Ok(AstExpr::InterpolatedFunction(InterpolatedFunction { + Ok(AstExpr::InterpolatedFunction(Arc::new(InterpolatedFunction { name: identifier, - arguments: Box::new(arguments), + arguments, span: parser.toks_mut().span_from(start), - }) + })) .span(parser.toks_mut().span_from(start))) } } @@ -1286,7 +1286,7 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> { Ok(AstExpr::FunctionCall(FunctionCallExpr { namespace: Some(namespace), name: Identifier::from(name), - arguments: Box::new(args), + arguments: Arc::new(args), span, }) .span(span)) @@ -1575,7 +1575,7 @@ impl<'a, 'c, P: StylesheetParser<'a>> ValueParser<'a, 'c, P> { Ok(AstExpr::FunctionCall(FunctionCallExpr { namespace: None, name: Identifier::from(ident), - arguments: Box::new(parser.parse_argument_invocation(false, false)?), + arguments: Arc::new(parser.parse_argument_invocation(false, false)?), span: parser.toks_mut().span_from(start), }) .span(parser.toks_mut().span_from(start))) diff --git a/grass_internal/src/unit/mod.rs b/grass_internal/src/unit/mod.rs index 970fa3c..7e38e55 100644 --- a/grass_internal/src/unit/mod.rs +++ b/grass_internal/src/unit/mod.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::{fmt, sync::Arc}; use crate::interner::InternedString; @@ -100,7 +100,7 @@ pub(crate) enum Unit { /// Unspecified unit None, - Complex(Box), + Complex(Arc), } #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -141,13 +141,13 @@ impl Unit { } else if denom.is_empty() && numer.len() == 1 { numer.pop().unwrap() } else { - Unit::Complex(Box::new(ComplexUnit { numer, denom })) + Unit::Complex(Arc::new(ComplexUnit { numer, denom })) } } pub fn numer_and_denom(self) -> (Vec, Vec) { match self { - Self::Complex(complex) => (complex.numer, complex.denom), + Self::Complex(complex) => (complex.numer.clone(), complex.denom.clone()), Self::None => (Vec::new(), Vec::new()), v => (vec![v], Vec::new()), } diff --git a/grass_internal/src/value/mod.rs b/grass_internal/src/value/mod.rs index 6de38bc..2a62006 100644 --- a/grass_internal/src/value/mod.rs +++ b/grass_internal/src/value/mod.rs @@ -129,7 +129,7 @@ impl Value { span: Span, ) -> SassResult { let mut number = self.assert_number(span)?; - number.as_slash = Some(Box::new((numerator, denom))); + number.as_slash = Some(Arc::new((numerator, denom))); Ok(Value::Dimension(number)) } @@ -194,7 +194,7 @@ impl Value { Value::Null => true, Value::String(i, QuoteKind::None) if i.is_empty() => true, Value::List(_, _, Brackets::Bracketed) => false, - Value::List(v, ..) => v.iter().map(Value::is_blank).all(|f| f), + Value::List(v, ..) => v.iter().all(Value::is_blank), Value::ArgList(v, ..) => v.is_blank(), _ => false, } @@ -258,7 +258,7 @@ impl Value { } } - pub fn as_slash(&self) -> Option> { + pub fn as_slash(&self) -> Option> { match self { Value::Dimension(SassNumber { as_slash, .. }) => as_slash.clone(), _ => None, diff --git a/grass_internal/src/value/sass_number.rs b/grass_internal/src/value/sass_number.rs index 8085270..da8f4a2 100644 --- a/grass_internal/src/value/sass_number.rs +++ b/grass_internal/src/value/sass_number.rs @@ -1,4 +1,7 @@ -use std::ops::{Add, Div, Mul, Sub}; +use std::{ + ops::{Add, Div, Mul, Sub}, + sync::Arc, +}; use codemap::Span; @@ -11,12 +14,11 @@ use crate::{ use super::Number; -// todo: is as_slash included in eq #[derive(Debug, Clone)] pub(crate) struct SassNumber { pub num: Number, pub unit: Unit, - pub as_slash: Option>, + pub as_slash: Option>, } pub(crate) fn conversion_factor(from: &Unit, to: &Unit) -> Option {