allow arbitrary control flow inside @ for
This commit is contained in:
parent
9bb7c05d19
commit
69764ceaa3
@ -42,12 +42,27 @@ impl For {
|
||||
span: self.var.span,
|
||||
},
|
||||
)?;
|
||||
stmts.extend(eat_stmts(
|
||||
for stmt in eat_stmts(
|
||||
&mut self.body.clone().into_iter().peekmore(),
|
||||
scope,
|
||||
super_selector,
|
||||
false,
|
||||
)?);
|
||||
)? {
|
||||
match stmt.node {
|
||||
Stmt::AtRule(AtRule::For(f)) => {
|
||||
stmts.extend(f.ruleset_eval(scope, super_selector)?)
|
||||
}
|
||||
Stmt::AtRule(AtRule::While(w)) => {
|
||||
// TODO: should at_root be false? scoping
|
||||
stmts.extend(w.ruleset_eval(scope, super_selector, false)?)
|
||||
}
|
||||
Stmt::AtRule(AtRule::Include(s)) | Stmt::AtRule(AtRule::Each(s)) => {
|
||||
stmts.extend(s)
|
||||
}
|
||||
Stmt::AtRule(AtRule::If(i)) => stmts.extend(i.eval(scope, super_selector)?),
|
||||
_ => stmts.push(stmt),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(stmts)
|
||||
}
|
||||
|
@ -53,3 +53,8 @@ test!(
|
||||
"@function foo() {\n @for $i from 1 through 2 {\n @if $i==2 {\n @return $i;\n }\n }\n}\na {\n color: foo();\n}\n",
|
||||
"a {\n color: 2;\n}\n"
|
||||
);
|
||||
test!(
|
||||
inner_if,
|
||||
"a {\n @for $i from 1 to 3 {\n @if $i==2 {\n color: red;\n }\n }\n}\n",
|
||||
"a {\n color: red;\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user