refactor mixin args

This commit is contained in:
ConnorSkees 2020-05-13 23:56:47 -04:00
parent 0cbdc67f06
commit 4b15b27119

View File

@ -62,7 +62,7 @@ impl Mixin {
scope: &Scope, scope: &Scope,
super_selector: &Selector, super_selector: &Selector,
) -> SassResult<Mixin> { ) -> SassResult<Mixin> {
for (idx, arg) in self.args.0.iter().enumerate() { for (idx, arg) in self.args.0.iter_mut().enumerate() {
if arg.is_variadic { if arg.is_variadic {
let span = args.span(); let span = args.span();
self.scope.insert_var( self.scope.insert_var(
@ -74,22 +74,19 @@ impl Mixin {
)?; )?;
break; break;
} }
let val = match args.get_positional(idx, scope, super_selector) { let val = match args.get(idx, arg.name.clone(), &scope, super_selector) {
Some(v) => v?, Some(v) => v?,
None => match args.get_named(arg.name.clone(), scope, super_selector) { None => match arg.default.as_mut() {
Some(v) => v?, Some(v) => Value::from_tokens(
None => match &arg.default { &mut std::mem::take(v).into_iter().peekmore(),
Some(v) => Value::from_tokens( &scope,
&mut v.iter().cloned().peekmore(), super_selector,
scope, )?,
super_selector, None => {
)?, return Err(
None => { (format!("Missing argument ${}.", &arg.name), args.span()).into()
return Err( )
(format!("Missing argument ${}.", &arg.name), args.span()).into() }
)
}
},
}, },
}; };
self.scope.insert_var(&arg.name, val)?; self.scope.insert_var(&arg.name, val)?;