removed unneeded wrapping nodes added during parsing
authorFabien Potencier <fabien.potencier@gmail.com>
Mon, 3 Jan 2011 17:35:07 +0000 (18:35 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 3 Jan 2011 17:35:07 +0000 (18:35 +0100)
lib/Twig/Parser.php
test/Twig/Tests/ExpressionParserTest.php

index 08bca6f..346e732 100644 (file)
@@ -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);
     }
 
index d36c9fd..4e43652 100644 (file)
@@ -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'));
     }
 
     /**