Skip to content

Commit 83ec2fc

Browse files
committed
Fix block in while/unless condition
[fix mbj#66]
1 parent 92dba8f commit 83ec2fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/unparser/emitter/repetition.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def emit_keyword
8787
#
8888
def emit_normal
8989
emit_keyword
90-
visit(condition)
90+
conditional_parentheses(condition.type.equal?(:block)) do
91+
visit(condition)
92+
end
9193
emit_body
9294
k_end
9395
end

spec/unit/unparser_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,13 @@ def foo
15411541
3
15421542
end
15431543
RUBY
1544+
1545+
assert_source <<-'RUBY'
1546+
while (foo do
1547+
end)
1548+
:body
1549+
end
1550+
RUBY
15441551
end
15451552

15461553
context 'until' do
@@ -1554,6 +1561,13 @@ def foo
15541561
3
15551562
end
15561563
RUBY
1564+
1565+
assert_source <<-'RUBY'
1566+
until (foo do
1567+
end)
1568+
:body
1569+
end
1570+
RUBY
15571571
end
15581572

15591573
assert_source <<-'RUBY'

0 commit comments

Comments
 (0)