From b3b2055c24bafc1abd66cb9612b93862db4abd22 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Thu, 2 Jan 2020 22:05:14 +0100 Subject: [PATCH] fix: regression with unary / retif precedence --- src/ast.js | 7 +++++++ test/precedence.test.js | 4 ++++ 2 files changed, 11 insertions(+) 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)") + }); });