mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
fixed the ternary operator
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
* 1.0.0-RC2
|
||||
|
||||
...
|
||||
Changes:
|
||||
|
||||
* fixed the ternary operator precedence rule
|
||||
|
||||
* 1.0.0-RC1 (2011-01-09)
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user