mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-01 01:18:12 +00:00
fixed the ternary operator
This commit is contained in:
@@ -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('))')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user