Remove obsolete code about non-yield templates

This commit is contained in:
Fabien Potencier
2024-02-05 15:26:25 +01:00
parent b1c22a1cee
commit b3eeb41861
17 changed files with 71 additions and 299 deletions
+5 -13
View File
@@ -151,14 +151,14 @@ final class ModuleNode extends Node
->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n")
->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n")
->write("use Twig\Source;\n")
->write(sprintf("use Twig\%s;\n\n", $compiler->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template'))
->write("use Twig\YieldingTemplate;\n\n")
;
}
$compiler
// if the template name contains */, add a blank to avoid a PHP parse error
->write('/* '.str_replace('*/', '* /', $this->getSourceContext()->getName())." */\n")
->write('class '.$compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index')))
->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template'))
->raw(" extends YieldingTemplate\n")
->write("{\n")
->indent()
->write("private Source \$source;\n")
@@ -326,23 +326,15 @@ final class ModuleNode extends Node
->raw(");\n")
;
}
if ($compiler->getEnvironment()->useYield()) {
$compiler->write('yield from ');
} else {
$compiler->write('');
}
$compiler->write('yield from ');
if ($parent instanceof ConstantExpression) {
$compiler->raw('$this->parent');
} else {
$compiler->raw('$this->getParent($context)');
}
if ($compiler->getEnvironment()->useYield()) {
$compiler->raw("->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks));\n");
} else {
$compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
}
} elseif ($compiler->getEnvironment()->useYield() && !$this->hasNodeOutputNodes($this->getNode('body'))) {
$compiler->raw("->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks));\n");
} elseif (!$this->hasNodeOutputNodes($this->getNode('body'))) {
// ensure at least one yield call even for templates with no output
$compiler->write("yield '';\n");
}