fixed previous merge
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 27 Jul 2011 07:34:28 +0000 (09:34 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 27 Jul 2011 07:34:28 +0000 (09:34 +0200)
lib/Twig/Node/BlockReference.php
lib/Twig/NodeVisitor/Optimizer.php

index 53f6287..4df2ed8 100644 (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')))
+            ;
+        }
     }
 }
index 8a9a35a..4834775 100644 (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;