Changes:
+ * added a performance optimization in the Optimizer (also helps to lower the number of nested level calls)
* made some performance improvement for some edge cases
* 1.1.0 (2011-06-28)
$node = $this->optimizeRawFilter($node, $env);
}
+ $node = $this->optimizeRenderBlock($node, $env);
+
+ return $node;
+ }
+
+ /**
+ * Replaces "echo $this->renderBlock()" with "$this->displayBlock()".
+ *
+ * @param Twig_NodeInterface $node A Node
+ * @param Twig_Environment $env The current Twig environment
+ */
+ protected function optimizeRenderBlock($node, $env)
+ {
+ if ($node instanceof Twig_Node_Print && $node->getNode('expr') instanceof Twig_Node_Expression_BlockReference) {
+ return new Twig_Node_BlockReference($node->getNode('expr')->getNode('name')->getAttribute('value'), $node->getLine(), $node->getNodeTag());
+ }
+
return $node;
}
*/
class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase
{
+ public function testRenderBlockOptimizer()
+ {
+ $env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
+ $env->addExtension(new Twig_Extension_Optimizer());
+
+ $stream = $env->parse($env->tokenize('{{ block("foo") }}', 'index'));
+
+ $this->assertInstanceOf('Twig_Node_BlockReference', $stream->getNode('body'));
+ }
+
/**
* @dataProvider getTestsForForOptimizer
*/