From: Fabien Potencier Date: Mon, 3 Jan 2011 17:35:07 +0000 (+0100) Subject: removed unneeded wrapping nodes added during parsing X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0a82da1d74d7e3b42c3523e89d5afaf4fd565b56;p=web%2Fkonrad%2Ftwig.git removed unneeded wrapping nodes added during parsing --- diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 08bca6f..346e732 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -119,6 +119,10 @@ class Twig_Parser implements Twig_ParserInterface $this->stream->next(); } + if (1 === count($rv)) { + return $rv[0]; + } + return new Twig_Node($rv, array(), $lineno); } @@ -140,6 +144,10 @@ class Twig_Parser implements Twig_ParserInterface } } + if (1 === count($rv)) { + return $rv[0]; + } + return new Twig_Node($rv, array(), $lineno); } diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index d36c9fd..4e43652 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -45,7 +45,7 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase $stream = $env->tokenize($template, 'index'); $parser = new Twig_Parser($env); - $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); + $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode('expr')); } /**