mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
fixed previous merge
This commit is contained in:
@@ -20,7 +20,12 @@ class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInter
|
||||
{
|
||||
public function __construct($name, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(array(), array('name' => $name), $lineno, $tag);
|
||||
// hack to be BC
|
||||
if ($name instanceof Twig_NodeInterface) {
|
||||
parent::__construct(array('name' => $name), array(), $lineno, $tag);
|
||||
} else {
|
||||
parent::__construct(array(), array('name' => $name), $lineno, $tag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,9 +35,18 @@ class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInter
|
||||
*/
|
||||
public function compile(Twig_Compiler $compiler)
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
|
||||
;
|
||||
if ($this->hasNode('name')) {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->raw("\$this->displayBlock(")
|
||||
->subcompile($this->getNode('name'))
|
||||
->write(", \$context, \$blocks);\n")
|
||||
;
|
||||
} else {
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +83,7 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
|
||||
protected function optimizeRenderBlock($node, $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference) {
|
||||
$name = $node->getNode('expr')->getNode('name');
|
||||
if ($name instanceof Twig_Node_Expression_Constant) {
|
||||
return new Twig_Node_BlockReference($name->getAttribute('value'), $node->getLine(), $node->getNodeTag());
|
||||
} else {
|
||||
return new Twig_Node_BlockReference($name, $node->getLine(), $node->getNodeTag());
|
||||
}
|
||||
return new Twig_Node_BlockReference($node->getNode('expr')->getNode('name'), $node->getLine(), $node->getNodeTag());
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
||||
Reference in New Issue
Block a user