use Identifier for FuncArg

This commit is contained in:
ConnorSkees 2020-05-22 22:43:26 -04:00
parent 7b8b5c233c
commit 33c5acc35f
4 changed files with 25 additions and 16 deletions

View File

@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::mem;
use codemap::{Span, Spanned};
@ -20,7 +21,7 @@ pub(crate) struct FuncArgs(pub Vec<FuncArg>);
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct FuncArg {
pub name: String,
pub name: Identifier,
pub default: Option<Vec<Token>>,
pub is_variadic: bool,
}
@ -128,10 +129,10 @@ impl CallArgs {
}
}
pub fn get(
pub fn get<T: Into<Identifier>>(
&mut self,
position: usize,
name: String,
name: T,
scope: &Scope,
super_selector: &Selector,
) -> Option<SassResult<Spanned<Value>>> {
@ -244,7 +245,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
',' => {
toks.next();
args.push(FuncArg {
name: name.replace('_', "-"),
name: name.node.into(),
default: Some(default),
is_variadic,
});
@ -252,7 +253,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
}
')' => {
args.push(FuncArg {
name: name.replace('_', "-"),
name: name.node.into(),
default: Some(default),
is_variadic,
});
@ -285,7 +286,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
is_variadic = true;
args.push(FuncArg {
name: name.replace('_', "-"),
name: name.node.into(),
default: Some(default),
is_variadic,
});
@ -294,7 +295,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
')' => {
close_paren_span = span;
args.push(FuncArg {
name: name.replace('_', "-"),
name: name.node.into(),
default: if default.is_empty() {
None
} else {
@ -305,7 +306,7 @@ pub(crate) fn eat_func_args<I: Iterator<Item = Token>>(
break;
}
',' => args.push(FuncArg {
name: name.replace('_', "-"),
name: name.node.into(),
default: None,
is_variadic,
}),
@ -399,9 +400,8 @@ pub(crate) fn eat_call_args<I: Iterator<Item = Token>>(
} else {
CallArg::Named(name.as_str().into())
},
val.clone(),
mem::take(&mut val),
);
val.clear();
devour_whitespace(toks);
if toks.peek().is_none() {

View File

@ -1,3 +1,5 @@
use std::mem;
use super::eat_stmts;
use codemap::{Span, Spanned};
@ -75,7 +77,7 @@ impl Function {
let span = args.span();
let arg_list = Value::ArgList(args.get_variadic(&scope, super_selector)?);
self.scope.insert_var(
&arg.name,
arg.name.clone(),
Spanned {
node: arg_list,
span,
@ -87,7 +89,7 @@ impl Function {
Some(v) => v?,
None => match arg.default.as_mut() {
Some(v) => Value::from_tokens(
&mut std::mem::take(v).into_iter().peekmore(),
&mut mem::take(v).into_iter().peekmore(),
&scope,
super_selector,
)?,
@ -98,8 +100,8 @@ impl Function {
}
},
};
scope.insert_var(&arg.name, val.clone())?;
self.scope.insert_var(&arg.name, val)?;
scope.insert_var(arg.name.clone(), val.clone())?;
self.scope.insert_var(mem::take(&mut arg.name), val)?;
}
Ok(())
}

View File

@ -1,3 +1,4 @@
use std::mem;
use std::vec::IntoIter;
use codemap::{Span, Spanned};
@ -67,7 +68,7 @@ impl Mixin {
if arg.is_variadic {
let span = args.span();
self.scope.insert_var(
&arg.name,
mem::take(&mut arg.name),
Spanned {
node: Value::ArgList(args.get_variadic(scope, super_selector)?),
span,
@ -90,7 +91,7 @@ impl Mixin {
}
},
};
self.scope.insert_var(&arg.name, val)?;
self.scope.insert_var(mem::take(&mut arg.name), val)?;
}
Ok(self)
}

View File

@ -146,3 +146,9 @@ impl Display for Identifier {
write!(f, "{}", self.0)
}
}
impl Default for Identifier {
fn default() -> Self {
Self(String::new())
}
}