diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-03-05 20:11:52 -0500 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:42:47 +0000 |
| commit | e97b364adb0e4447c1c361c438dacc25ca757c95 (patch) | |
| tree | c46811426d567981a30cee1529c9336399b57b81 | |
| parent | 78fe61c95fecf8e7964337a067908976d9d4bfca (diff) | |
[ruby/prism] Unary not for ripper translation
https://github.com/ruby/prism/commit/149d01f2c9
| -rw-r--r-- | lib/prism/translation/ripper.rb | 27 | ||||
| -rw-r--r-- | test/prism/ripper_test.rb | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index ada44b81d6..ea1a1882e4 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -508,11 +508,34 @@ module Prism value = visit(last_argument) bounds(last_argument.location) on_assign(call, value) - when :-@, :+@, :~@, :!@ + when :-@, :+@, :~@ receiver = visit(node.receiver) bounds(node.location) - on_unary(node.message == "not" ? :not : node.name, receiver) + on_unary(node.name, receiver) + when :!@ + if node.message == "not" + receiver = + case node.receiver + when nil + nil + when ParenthesesNode + body = visit(node.receiver.body&.body&.first) || false + + bounds(node.receiver.location) + on_paren(body) + else + visit(node.receiver) + end + + bounds(node.location) + on_unary(:not, receiver) + else + receiver = visit(node.receiver) + + bounds(node.location) + on_unary(:!@, receiver) + end when :!=, :!~, :=~, :==, :===, :<=>, :>, :>=, :<, :<=, :&, :|, :^, :>>, :<<, :-, :+, :%, :/, :*, :** receiver = visit(node.receiver) value = visit(node.arguments.arguments.first) diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index a58b52b5f7..1883fc1e49 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -37,7 +37,6 @@ module Prism modules.txt multi_write.txt non_alphanumeric_methods.txt - not.txt patterns.txt procs.txt regex.txt @@ -300,7 +299,6 @@ module Prism whitequark/bug_heredoc_do.txt whitequark/bug_interp_single.txt whitequark/bug_rescue_empty_else.txt - whitequark/bug_while_not_parens_do.txt whitequark/case_cond_else.txt whitequark/case_expr_else.txt whitequark/character.txt |
