diff --git a/src/ast.js b/src/ast.js index 45c7ab266..99b95842d 100644 --- a/src/ast.js +++ b/src/ast.js @@ -284,6 +284,13 @@ AST.prototype.resolvePrecedence = function(result, parser) { buffer.left = this.resolvePrecedence(result, parser); this.swapLocations(buffer, buffer.left, buffer.right, parser); result = buffer; + } else if (result.what.kind === "retif") { + buffer = result.what; + result.what = result.what.test; + this.swapLocations(result, result, result.what, parser); + buffer.test = this.resolvePrecedence(result, parser); + this.swapLocations(buffer, buffer.test, buffer.falseExpr, parser); + result = buffer; } } } else if (result.kind === "retif") { diff --git a/test/precedence.test.js b/test/precedence.test.js index 5166541d0..29117b5a5 100644 --- a/test/precedence.test.js +++ b/test/precedence.test.js @@ -158,4 +158,8 @@ describe("Test precedence", function() { shouldBeSame("$a = (string)$b->foo . $c", "$a = ((string)$b->foo) . $c"); shouldBeSame("(bool) $var ? 1 : 2;", "((bool)$var) ? 1 : 2;"); }); + + it("test unary / retif", function() { + shouldBeSame("$a = +(+$var ? 1 : 2)", "$a = +((+$var) ? 1 : 2)") + }); });