Use loop() to recurse instead of loop.recurse()

This commit is contained in:
Fabien Potencier
2024-07-22 09:41:43 +02:00
parent e95d6b2f21
commit 8c5dd39b9b
4 changed files with 13 additions and 4 deletions
+9
View File
@@ -460,6 +460,15 @@ class ExpressionParser
}
return new GetAttrExpression($args->getNode('0'), $args->getNode('1'), \count($args) > 2 ? $args->getNode('2') : null, Template::ANY_CALL, $line);
case 'loop':
$args = $this->parseArguments();
if (\count($args) < 1) {
throw new SyntaxError('The "loop" function takes an iterator as an argument.', $line, $this->parser->getStream()->getSourceContext());
}
$recurseArgs = new ArrayExpression([], $line);
$recurseArgs->addElement($args->getNode('0'));
return new GetAttrExpression(new NameExpression('loop', $line), new ConstantExpression('__invoke', $line), $recurseArgs, Template::METHOD_CALL, $line);
default:
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
$arguments = new ArrayExpression([], $line);