mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
Add another test
This commit is contained in:
@@ -469,9 +469,8 @@ class ExpressionParser
|
|||||||
$recurseArgs = new ArrayExpression([new ConstantExpression(0, $line), $args->getNode('0')], $line);
|
$recurseArgs = new ArrayExpression([new ConstantExpression(0, $line), $args->getNode('0')], $line);
|
||||||
$expr = new GetAttrExpression(new NameExpression('loop', $line), new ConstantExpression('__invoke', $line), $recurseArgs, Template::METHOD_CALL, $line);
|
$expr = new GetAttrExpression(new NameExpression('loop', $line), new ConstantExpression('__invoke', $line), $recurseArgs, Template::METHOD_CALL, $line);
|
||||||
$expr->setAttribute('is_generator', true);
|
$expr->setAttribute('is_generator', true);
|
||||||
$expr = new FilterExpression($expr, new ConstantExpression('raw', $line), new Node(), $line);
|
|
||||||
|
|
||||||
return $expr;
|
return new FilterExpression($expr, new ConstantExpression('raw', $line), new Node(), $line);
|
||||||
default:
|
default:
|
||||||
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
||||||
$arguments = new ArrayExpression([], $line);
|
$arguments = new ArrayExpression([], $line);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ namespace Twig\Tests\Node;
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Loader\ArrayLoader;
|
||||||
use Twig\Node\Expression\AssignNameExpression;
|
use Twig\Node\Expression\AssignNameExpression;
|
||||||
use Twig\Node\Expression\NameExpression;
|
use Twig\Node\Expression\NameExpression;
|
||||||
use Twig\Node\ForNode;
|
use Twig\Node\ForNode;
|
||||||
@@ -156,6 +158,29 @@ yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \
|
|||||||
EOF
|
EOF
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// recursive loop
|
||||||
|
$env = new Environment(new ArrayLoader(['index' => '{% for item in items %}{{ loop(item.children) }}{% endfor %}']));
|
||||||
|
$node = $env->parse($env->tokenize($env->getLoader()->getSourceContext('index')))->getNode('body');
|
||||||
|
|
||||||
|
$tests[] = [$node, <<<EOF
|
||||||
|
// line 1
|
||||||
|
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$this->getVariableGetter('items')});
|
||||||
|
\$__internal_compile_1 = function (\$__internal_compile_0, &\$context, \$blocks, &\$__internal_compile_1, \$depth) {
|
||||||
|
\$macros = \$this->macros;
|
||||||
|
\$__internal_compile_2 = \$context;
|
||||||
|
\$context['loop'] = new \Twig\Runtime\LoopContext(\$__internal_compile_0, \$__internal_compile_2, \$blocks, \$__internal_compile_1, \$depth);
|
||||||
|
foreach (\$__internal_compile_0 as \$context["_key"] => \$context["item"]) {
|
||||||
|
yield from CoreExtension::getAttribute(\$this->env, \$this->source, \$context["loop"], "__invoke", arguments: [CoreExtension::getAttribute(\$this->env, \$this->source, \$context["item"], "children", arguments: [], lineno: 1)], type: "method", lineno: 1);
|
||||||
|
}
|
||||||
|
unset(\$context['_key'], \$context['item'], \$context['loop']);
|
||||||
|
\$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2;
|
||||||
|
return; yield;
|
||||||
|
};
|
||||||
|
\Closure::bind(\$__internal_compile_1, \$this, self::class);
|
||||||
|
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||||
|
EOF
|
||||||
|
, $env];
|
||||||
|
|
||||||
return $tests;
|
return $tests;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user