Skip to content

Commit 380163a

Browse files
authored
Merge pull request #390 from viralpraxis/fix-and-or-operators-round-trip-assoc
Fix `and` and `or` operators RT broken associativity
2 parents 6c6a242 + 8d813e2 commit 380163a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/unparser/writer/binary.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ def symbol_name
5252
end
5353

5454
def dispatch
55-
left_emitter.write_to_buffer
56-
write(' ', MAP.fetch(effective_symbol), ' ')
57-
visit(right)
55+
if node.type.eql?(:and) && left.type.equal?(:or)
56+
emit_with(KEYWORD_TOKENS)
57+
else
58+
left_emitter.write_to_buffer
59+
write(' ', MAP.fetch(effective_symbol), ' ')
60+
visit(right)
61+
end
5862
end
5963

6064
private

test/corpus/semantic/and.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@
66

77
if a...b and c...d
88
end
9+
10+
a and b and c
11+
(a and b) and c
12+
a and (b and c)
13+
a and b or c
14+
(a and b) or c
15+
a and (b or c)
16+
a or b and c
17+
(a or b) and c
18+
a or (b and c)

test/corpus/semantic/or.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a[:x] = b[:x] || c[:x] || d(:new)

0 commit comments

Comments
 (0)