From 1f4698378d3ba52cc3aeab9d7c119250b09fbc4c Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:18:31 -0400 Subject: [PATCH] resolve regression in function scoping --- src/parse/function.rs | 12 +++++++++--- src/parse/mixin.rs | 7 +++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/parse/function.rs b/src/parse/function.rs index f9d54a8..efafff8 100644 --- a/src/parse/function.rs +++ b/src/parse/function.rs @@ -61,8 +61,9 @@ impl<'a> Parser<'a> { } pub fn eval_function(&mut self, mut function: Function, args: CallArgs) -> SassResult { - self.scopes.push(self.scopes.last().clone()); self.eval_fn_args(&mut function, args)?; + self.scopes.push(function.scope); + let mut return_value = Parser { toks: &mut function.body.into_iter().peekmore(), map: self.map, @@ -79,7 +80,9 @@ impl<'a> Parser<'a> { at_root_has_selector: self.at_root_has_selector, } .parse()?; + self.scopes.pop(); + debug_assert!(return_value.len() <= 1); match return_value .pop() @@ -91,11 +94,12 @@ impl<'a> Parser<'a> { } fn eval_fn_args(&mut self, function: &mut Function, mut args: CallArgs) -> SassResult<()> { + self.scopes.push(self.scopes.last().clone()); for (idx, arg) in function.args.0.iter_mut().enumerate() { if arg.is_variadic { let span = args.span(); let arg_list = Value::ArgList(self.variadic_args(args)?); - self.scopes.last_mut().insert_var( + function.scope.insert_var( arg.name.clone(), Spanned { node: arg_list, @@ -117,8 +121,10 @@ impl<'a> Parser<'a> { }; self.scopes .last_mut() - .insert_var(mem::take(&mut arg.name), val)?; + .insert_var(arg.name.clone(), val.clone())?; + function.scope.insert_var(mem::take(&mut arg.name), val)?; } + self.scopes.pop(); Ok(()) } } diff --git a/src/parse/mixin.rs b/src/parse/mixin.rs index 32b589c..0a34aec 100644 --- a/src/parse/mixin.rs +++ b/src/parse/mixin.rs @@ -126,7 +126,7 @@ impl<'a> Parser<'a> { } fn eval_mixin_args(&mut self, mixin: &mut Mixin, mut args: CallArgs) -> SassResult<()> { - let mut scope = self.scopes.last().clone(); + self.scopes.push(self.scopes.last().clone()); for (idx, arg) in mixin.args.0.iter_mut().enumerate() { if arg.is_variadic { let span = args.span(); @@ -152,9 +152,12 @@ impl<'a> Parser<'a> { } }, }; - scope.insert_var(arg.name.clone(), val.clone())?; + self.scopes + .last_mut() + .insert_var(arg.name.clone(), val.clone())?; mixin.scope.insert_var(mem::take(&mut arg.name), val)?; } + self.scopes.pop(); Ok(()) } }