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
+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);
}