diff --git a/Changelog.md b/Changelog.md index 7c38bc10..1ceb829a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,9 @@ +# v0.6.15 2024-06-10 + +[#373](https://github.com/mbj/unparser/pull/373) + +* Fix additonal keyword dispatch + # v0.6.14 2024-06-10 [#369](https://github.com/mbj/unparser/pull/369) diff --git a/Gemfile.lock b/Gemfile.lock index 7b2d04da..2e6c9330 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - unparser (0.6.14) + unparser (0.6.15) diff-lcs (~> 1.3) parser (>= 3.3.0) @@ -12,14 +12,14 @@ GEM diff-lcs (1.5.1) json (2.7.2) language_server-protocol (3.17.0.3) - mutant (0.12.2) + mutant (0.12.3) diff-lcs (~> 1.3) parser (~> 3.3.0) regexp_parser (~> 2.9.0) sorbet-runtime (~> 0.5.0) - unparser (~> 0.6.9) - mutant-rspec (0.12.2) - mutant (= 0.12.2) + unparser (~> 0.6.14) + mutant-rspec (0.12.3) + mutant (= 0.12.3) rspec-core (>= 3.8.0, < 4.0.0) parallel (1.25.1) parser (3.3.2.0) diff --git a/lib/unparser/emitter/pair.rb b/lib/unparser/emitter/pair.rb index 967361b9..8f73bea1 100644 --- a/lib/unparser/emitter/pair.rb +++ b/lib/unparser/emitter/pair.rb @@ -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 @@ -36,8 +36,23 @@ 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? + children = value.children + + n_send?(value) \ + && !key_value.end_with?('?') \ + && !key_value.end_with?('!') \ + && children.fetch(0).nil? \ + && children.fetch(1).equal?(key_value) \ + && children.at(2).nil? end end end diff --git a/test/corpus/literal/send.rb b/test/corpus/literal/send.rb index bba63427..409e8242 100644 --- a/test/corpus/literal/send.rb +++ b/test/corpus/literal/send.rb @@ -84,3 +84,10 @@ def foo a&.+(b) a = nil foo(bar: a) +foo(return:) +foo(bar: Bar.bar) +foo(bar: bar(1)) +foo(bar: 1) +foo(do: true) +foo(a?: a?) +foo(a!: a!) diff --git a/unparser.gemspec b/unparser.gemspec index cfa39959..18f17289 100644 --- a/unparser.gemspec +++ b/unparser.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = 'unparser' - gem.version = '0.6.14' + gem.version = '0.6.15' gem.authors = ['Markus Schirp'] gem.email = 'mbj@schirp-dso.com'