Handle positional arguments to mixins
This commit is contained in:
parent
d1ea6d2dd6
commit
ab8e98244f
19
src/main.rs
19
src/main.rs
@ -384,8 +384,8 @@ fn eat_include<I: Iterator<Item = Token>>(
|
||||
return Err((pos, "expected identifier"));
|
||||
};
|
||||
let rules = mixin
|
||||
.call_with_args(&args)
|
||||
.eval(super_selector, &mut scope.clone())?;
|
||||
.args(&args)
|
||||
.call(super_selector)?;
|
||||
Ok(rules)
|
||||
}
|
||||
|
||||
@ -1121,4 +1121,19 @@ mod css_mixins {
|
||||
"@mixin a {\n $a: blue;\nb {\n $a: red;\n} color: $a\n}\nd {\n @include a;\n}\n",
|
||||
"d {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
mixin_single_arg,
|
||||
"@mixin a($b) {\n color: $b;\n}\nd {\n @include a(red);\n}\n",
|
||||
"d {\n color: red;\n}\n"
|
||||
);
|
||||
test!(
|
||||
mixin_two_args,
|
||||
"@mixin a($b, $c) {\n color: $b;\n color: $c\n}\nd {\n @include a(red, blue);\n}\n",
|
||||
"d {\n color: red;\n color: blue;\n}\n"
|
||||
);
|
||||
test!(
|
||||
mixin_arg_trailing_comma,
|
||||
"@mixin a($b, $c,) {\n color: $b;\n color: $c\n}\nd {\n @include a(red, blue);\n}\n",
|
||||
"d {\n color: red;\n color: blue;\n}\n"
|
||||
);
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ impl Mixin {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn call_with_args(&mut self, args: &CallArgs) -> &mut Mixin {
|
||||
pub fn args(&mut self, args: &CallArgs) -> &mut Mixin {
|
||||
for (idx, arg) in args.0.iter().enumerate() {
|
||||
if arg.is_named() {
|
||||
todo!("keyword args")
|
||||
} else {
|
||||
// dbg!(&self.args.0[idx].name.clone());
|
||||
self.scope
|
||||
.vars
|
||||
.insert(self.args.0[idx].name.clone(), arg.val.clone());
|
||||
@ -39,6 +38,10 @@ impl Mixin {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn call(&mut self, super_selector: &Selector,) -> Result<Vec<Stmt>, (Pos, &'static str)> {
|
||||
self.eval(super_selector, &mut self.scope.clone())
|
||||
}
|
||||
|
||||
pub fn eval(
|
||||
&mut self,
|
||||
super_selector: &Selector,
|
||||
|
Loading…
x
Reference in New Issue
Block a user