mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-02 13:37:41 +00:00
Call For recurseFunc inline
After https://github.com/phpstan/phpstan-src/pull/3554 this now makes it easier for PHPStan to understands what's going on. This will allow TwigStan to handle for loops in v4.
This commit is contained in:
@@ -49,7 +49,7 @@ class ForNode extends Node
|
||||
->write("\$$iteratorVar = new \Twig\Runtime\LoopIterator(")
|
||||
->subcompile($this->getNode('seq'))
|
||||
->raw(");\n")
|
||||
->write("\$$functionVar = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {\n")
|
||||
->write("yield from (\$$functionVar = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {\n")
|
||||
->indent()
|
||||
->write("\$macros = \$this->macros;\n")
|
||||
->write("\$parent = \$context;\n")
|
||||
@@ -94,8 +94,7 @@ class ForNode extends Node
|
||||
$compiler
|
||||
->write("yield from [];\n")
|
||||
->outdent()
|
||||
->write("};\n")
|
||||
->write("yield from \$$functionVar(\$$iteratorVar, \$context, \$blocks, \$$functionVar, 0);\n")
|
||||
->write("})(\$$iteratorVar, \$context, \$blocks, \$$functionVar, 0);\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -68,7 +68,7 @@ class ForTest extends NodeTestCase
|
||||
$tests[] = [$node, <<<EOF
|
||||
// line 1
|
||||
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$itemsGetter});
|
||||
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
\$macros = \$this->macros;
|
||||
\$parent = \$context;
|
||||
foreach (\$iterator as \$context["key"] => \$context["item"]) {
|
||||
@@ -77,8 +77,7 @@ class ForTest extends NodeTestCase
|
||||
unset(\$context['key'], \$context['item']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
yield from [];
|
||||
};
|
||||
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
EOF
|
||||
];
|
||||
|
||||
@@ -93,7 +92,7 @@ EOF
|
||||
$tests[] = [$node, <<<EOF
|
||||
// line 1
|
||||
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
|
||||
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
\$macros = \$this->macros;
|
||||
\$parent = \$context;
|
||||
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
|
||||
@@ -103,8 +102,7 @@ EOF
|
||||
unset(\$context['k'], \$context['v'], \$context['loop']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
yield from [];
|
||||
};
|
||||
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
EOF
|
||||
];
|
||||
|
||||
@@ -119,7 +117,7 @@ EOF
|
||||
$tests[] = [$node, <<<EOF
|
||||
// line 1
|
||||
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
|
||||
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
\$macros = \$this->macros;
|
||||
\$parent = \$context;
|
||||
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
|
||||
@@ -129,8 +127,7 @@ EOF
|
||||
unset(\$context['k'], \$context['v'], \$context['loop']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
yield from [];
|
||||
};
|
||||
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
EOF
|
||||
];
|
||||
|
||||
@@ -146,7 +143,7 @@ EOF
|
||||
$tests[] = [$node, <<<EOF
|
||||
// line 1
|
||||
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$valuesGetter});
|
||||
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
\$macros = \$this->macros;
|
||||
\$parent = \$context;
|
||||
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
|
||||
@@ -161,8 +158,7 @@ EOF
|
||||
unset(\$context['k'], \$context['v'], \$context['loop']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
yield from [];
|
||||
};
|
||||
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
EOF
|
||||
];
|
||||
|
||||
@@ -173,7 +169,7 @@ EOF
|
||||
$tests[] = [$node, <<<EOF
|
||||
// line 1
|
||||
\$__internal_compile_0 = new \Twig\Runtime\LoopIterator({$itemsGetter});
|
||||
\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
yield from (\$__internal_compile_1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \$depth) {
|
||||
\$macros = \$this->macros;
|
||||
\$parent = \$context;
|
||||
\$context['loop'] = new \Twig\Runtime\LoopContext(\$iterator, \$parent, \$blocks, \$recurseFunc, \$depth);
|
||||
@@ -183,8 +179,7 @@ EOF
|
||||
unset(\$context['_key'], \$context['item'], \$context['loop']);
|
||||
\$context = array_intersect_key(\$context, \$parent) + \$parent;
|
||||
yield from [];
|
||||
};
|
||||
yield from \$__internal_compile_1(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
})(\$__internal_compile_0, \$context, \$blocks, \$__internal_compile_1, 0);
|
||||
EOF
|
||||
, $env];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user