From 0a82da1d74d7e3b42c3523e89d5afaf4fd565b56 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Jan 2011 18:35:07 +0100 Subject: [PATCH] removed unneeded wrapping nodes added during parsing --- lib/Twig/Parser.php | 8 ++++++++ test/Twig/Tests/ExpressionParserTest.php | 2 +- 2 files changed, 9 insertions(+), 1 deletions(-) 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')); } /** -- 1.7.2.5