fixed previous merge

This commit is contained in:
Fabien Potencier
2011-07-27 09:34:28 +02:00
parent a6726c7ddd
commit 1f233ce06b
2 changed files with 20 additions and 11 deletions
+19 -5
View File
@@ -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')))
;
}
}
}
+1 -6
View File
@@ -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;