* 1.0.0-RC2
-...
+Changes:
+
+ * fixed the ternary operator precedence rule
* 1.0.0-RC1 (2011-01-09)
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('))')
;
}
}
// 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
$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);
}
$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;
}
);
$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);
}
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);
}