mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Always evaluate for loop to template 🔁
This commit is contained in:
parent
ce8138c685
commit
2641c2d20e
@ -388,11 +388,7 @@ impl Eval for Spanned<&ExprFor> {
|
|||||||
|
|
||||||
fn eval(self, ctx: &mut EvalContext) -> Self::Output {
|
fn eval(self, ctx: &mut EvalContext) -> Self::Output {
|
||||||
let iter = self.v.iter.eval(ctx);
|
let iter = self.v.iter.eval(ctx);
|
||||||
let mut output = if let Expr::Template(_) = self.v.body.v {
|
let mut output = vec![];
|
||||||
Value::Template(vec![])
|
|
||||||
} else {
|
|
||||||
Value::None
|
|
||||||
};
|
|
||||||
|
|
||||||
macro_rules! iterate {
|
macro_rules! iterate {
|
||||||
(for ($($binding:ident => $value:ident),*) in $iter:expr) => {
|
(for ($($binding:ident => $value:ident),*) in $iter:expr) => {
|
||||||
@ -400,16 +396,12 @@ impl Eval for Spanned<&ExprFor> {
|
|||||||
for ($($value),*) in $iter {
|
for ($($value),*) in $iter {
|
||||||
$(ctx.scopes.define($binding.as_str(), $value);)*
|
$(ctx.scopes.define($binding.as_str(), $value);)*
|
||||||
|
|
||||||
let value = self.v.body.eval(ctx);
|
if let Value::Template(new) = self.v.body.eval(ctx) {
|
||||||
|
output.extend(new);
|
||||||
if let Value::Template(prev) = &mut output {
|
|
||||||
if let Value::Template(new) = value {
|
|
||||||
prev.extend(new);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return Value::Template(output);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user