diff --git a/src/atrule/function.rs b/src/atrule/function.rs index 21543ba..f0a5ee5 100644 --- a/src/atrule/function.rs +++ b/src/atrule/function.rs @@ -68,26 +68,28 @@ impl Function { scope: &Scope, super_selector: &Selector, ) -> SassResult<()> { + let mut scope = scope.clone(); for (idx, arg) in self.args.0.iter().enumerate() { if arg.is_variadic { let span = args.span(); - self.scope.insert_var( + let arg_list = Value::ArgList(args.get_variadic(&mut scope, super_selector)?); + scope.insert_var( &arg.name, Spanned { - node: Value::ArgList(args.get_variadic(scope, super_selector)?), + node: arg_list, span, }, )?; break; } - let val = match args.get_positional(idx, scope, super_selector) { + let val = match args.get_positional(idx, &mut scope, super_selector) { Some(v) => v?, - None => match args.get_named(arg.name.clone(), scope, super_selector) { + None => match args.get_named(arg.name.clone(), &mut scope, super_selector) { Some(v) => v?, None => match &arg.default { Some(v) => Value::from_tokens( &mut v.iter().cloned().peekmore(), - scope, + &mut scope, super_selector, )?, None => { @@ -98,8 +100,9 @@ impl Function { }, }, }; - self.scope.insert_var(&arg.name, val)?; + scope.insert_var(&arg.name, val)?; } + self.scope.extend(scope); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 291e86c..344d00a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -261,7 +261,7 @@ impl StyleSheet { /// ``` #[inline] #[cfg(not(feature = "wasm"))] - pub fn from_path + Into + Clone>(p: &P) -> SassResult { + pub fn from_path(p: &str) -> SassResult { let mut map = CodeMap::new(); let file = map.add_file(p.clone().into(), String::from_utf8(fs::read(p.clone())?)?); Css::from_stylesheet(StyleSheet( diff --git a/tests/args.rs b/tests/args.rs index 9527242..d72e02e 100644 --- a/tests/args.rs +++ b/tests/args.rs @@ -40,3 +40,8 @@ test!( "@function foo($arg1: bar()) {\n @return true;\n}\n\na {\n color: foo();\n}\n", "a {\n color: true;\n}\n" ); +test!( + self_referential_default_arg_value, + "@function foo($a, $b: $a) {\n @return $b;\n}\n\na {\n color: foo(2);\n}\n", + "a {\n color: 2;\n}\n" +);