fixed the ternary operator

This commit is contained in:
Fabien Potencier
2011-01-10 19:06:37 +01:00
parent e96ed3f66c
commit ac9e4eec15
6 changed files with 12 additions and 10 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
* 1.0.0-RC2
...
Changes:
* fixed the ternary operator precedence rule
* 1.0.0-RC1 (2011-01-09)
+2 -2
View File
@@ -19,13 +19,13 @@ class Twig_Node_Expression_Conditional extends Twig_Node_Expression
public function compile(Twig_Compiler $compiler)
{
$compiler
->raw('(')
->raw('((')
->subcompile($this->getNode('expr1'))
->raw(') ? (')
->subcompile($this->getNode('expr2'))
->raw(') : (')
->subcompile($this->getNode('expr3'))
->raw(')')
->raw('))')
;
}
}
+4 -4
View File
@@ -27,7 +27,7 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression
// is a name (like obj) or an attribute (like obj.attr)
// In such a case, it's compiled to {{ obj is defined ? obj|default('bar') : 'bar' }}
if ('default' === $name && ($this->getNode('node') instanceof Twig_Node_Expression_Name || $this->getNode('node') instanceof Twig_Node_Expression_GetAttr)) {
$compiler->raw('(');
$compiler->raw('((');
if ($this->getNode('node') instanceof Twig_Node_Expression_Name) {
$testMap = $compiler->getEnvironment()->getTests();
$compiler
@@ -40,11 +40,11 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression
$compiler->subcompile($this->getNode('node'));
}
$compiler->raw(' ? ');
$compiler->raw(') ? (');
$this->compileFilter($compiler, $filter);
$compiler->raw(' : ');
$compiler->raw(') : (');
$compiler->subcompile($this->getNode('arguments')->getNode(0));
$compiler->raw(')');
$compiler->raw('))');
} else {
$this->compileFilter($compiler, $filter);
}
@@ -45,7 +45,7 @@ class Twig_Tests_Node_Expression_ConditionalTest extends Twig_Tests_Node_TestCas
$expr2 = new Twig_Node_Expression_Constant(2, 0);
$expr3 = new Twig_Node_Expression_Constant(3, 0);
$node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 0);
$tests[] = array($node, '(1) ? (2) : (3)');
$tests[] = array($node, '((1) ? (2) : (3))');
return $tests;
}
+1 -1
View File
@@ -56,7 +56,7 @@ class Twig_Tests_Node_IncludeTest extends Twig_Tests_Node_TestCase
);
$node = new Twig_Node_Include($expr, null, false, 0);
$tests[] = array($node, <<<EOF
\$template = (true) ? ("foo") : ("foo");
\$template = ((true) ? ("foo") : ("foo"));
if (!\$template instanceof Twig_Template) {
\$template = \$this->env->loadTemplate(\$template);
}
+1 -1
View File
@@ -141,7 +141,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
public function getParent(array \$context)
{
if (null === \$this->parent) {
\$this->parent = (true) ? ("foo") : ("foo");
\$this->parent = ((true) ? ("foo") : ("foo"));
if (!\$this->parent instanceof Twig_Template) {
\$this->parent = \$this->env->loadTemplate(\$this->parent);
}