Skip to content

Commit

Permalink
fix(precedence): right-associative operators
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed May 10, 2020
1 parent 945333f commit d0e5cd3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ AST.prototype.resolvePrecedence = function (result, parser) {
lLevel &&
rLevel &&
rLevel <= lLevel &&
!this.isRightAssociative(result.type)
(result.type !== result.right.type ||
!this.isRightAssociative(result.type))
) {
// https://github.com/glayzzle/php-parser/issues/79
// shift precedence
Expand Down
3 changes: 3 additions & 0 deletions test/precedence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe("Test precedence", function () {
it("test ?? right-associative", function () {
shouldBeSame("1 ?? 2 ?? 3", "1 ?? (2 ?? 3)");
});
it("test ** precedence", function () {
shouldBeSame("1 ** 2 + 3", "(1 ** 2) + 3");
});
it("test ** right-associative", function () {
shouldBeSame("1 ** 2 ** 3", "1 ** (2 ** 3)");
});
Expand Down

0 comments on commit d0e5cd3

Please sign in to comment.