Skip to content

Commit

Permalink
Fix keyword pairs for sends
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Jun 15, 2024
1 parent 0bf5fc5 commit 5fd0425
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/unparser/emitter/pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Pair < self
def dispatch
if colon?
emit_colon
unless implicit_value?
unless implicit_value_lvar? || implicit_value_send?
write(' ')
visit(value)
end
Expand All @@ -36,8 +36,16 @@ def emit_colon
write(key.children.first.to_s, ':')
end

def implicit_value?
n_lvar?(value) && value.children.first.equal?(key.children.first)
def key_value
key.children.first
end

def implicit_value_lvar?
n_lvar?(value) && value.children.first.equal?(key_value)
end

def implicit_value_send?
n_send?(value) && value.children.fetch(1).equal?(key_value)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions test/corpus/literal/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ def foo
a&.+(b)
a = nil
foo(bar: a)
foo(return:)

0 comments on commit 5fd0425

Please sign in to comment.