summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/prism/translation/ripper.rb62
-rw-r--r--test/prism/ripper_test.rb8
2 files changed, 50 insertions, 20 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index 6bbc8e286c..e3cd300446 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -738,35 +738,72 @@ module Prism
# Foo::Foo, Bar::Bar = 1
# ^^^^^^^^ ^^^^^^^^
def visit_constant_path_write_node(node)
- parent = visit(node.target.parent)
-
- bounds(node.target.child.location)
- child = on_const(node.target.child.name.to_s)
-
- bounds(node.target.location)
- target = on_const_path_field(parent, child)
+ target = visit_constant_path_write_node_target(node.target)
value = visit(node.value)
bounds(node.location)
on_assign(target, value)
end
+ # Visit a constant path that is part of a write node.
+ private def visit_constant_path_write_node_target(node)
+ if node.parent.nil?
+ bounds(node.child.location)
+ child = on_const(node.child.name.to_s)
+
+ bounds(node.location)
+ on_top_const_field(child)
+ else
+ parent = visit(node.parent)
+
+ bounds(node.child.location)
+ child = on_const(node.child.name.to_s)
+
+ bounds(node.location)
+ on_const_path_field(parent, child)
+ end
+ end
+
# Foo::Bar += baz
# ^^^^^^^^^^^^^^^
def visit_constant_path_operator_write_node(node)
- raise NoMethodError, __method__
+ target = visit_constant_path_write_node_target(node.target)
+ value = visit(node.value)
+
+ bounds(node.operator_loc)
+ operator = on_op("#{node.operator}=")
+ value = visit(node.value)
+
+ bounds(node.location)
+ on_opassign(target, operator, value)
end
# Foo::Bar &&= baz
# ^^^^^^^^^^^^^^^^
def visit_constant_path_and_write_node(node)
- raise NoMethodError, __method__
+ target = visit_constant_path_write_node_target(node.target)
+ value = visit(node.value)
+
+ bounds(node.operator_loc)
+ operator = on_op("&&=")
+ value = visit(node.value)
+
+ bounds(node.location)
+ on_opassign(target, operator, value)
end
# Foo::Bar ||= baz
# ^^^^^^^^^^^^^^^^
def visit_constant_path_or_write_node(node)
- raise NoMethodError, __method__
+ target = visit_constant_path_write_node_target(node.target)
+ value = visit(node.value)
+
+ bounds(node.operator_loc)
+ operator = on_op("||=")
+ value = visit(node.value)
+
+ bounds(node.location)
+ on_opassign(target, operator, value)
end
# Foo::Bar, = baz
@@ -925,7 +962,8 @@ module Prism
# def foo(...); end
# ^^^
def visit_forwarding_parameter_node(node)
- raise NoMethodError, __method__
+ bounds(node.location)
+ on_args_forward
end
# super
@@ -1522,7 +1560,7 @@ module Prism
posts = visit_all(node.posts) if node.posts.any?
keywords = visit_all(node.keywords) if node.keywords.any?
keyword_rest = visit(node.keyword_rest)
- block = visit(node.block)
+ block = node.keyword_rest.is_a?(ForwardingParameterNode) ? :& : visit(node.block)
bounds(node.location)
on_params(requireds, optionals, rest, posts, keywords, keyword_rest, block)
diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb
index 9e19c5aaa6..a0b7d3a25f 100644
--- a/test/prism/ripper_test.rb
+++ b/test/prism/ripper_test.rb
@@ -394,11 +394,6 @@ module Prism
seattlerb/case_in_multiple.txt
seattlerb/case_in_or.txt
seattlerb/class_comments.txt
- seattlerb/const_2_op_asgn_or2.txt
- seattlerb/const_3_op_asgn_or.txt
- seattlerb/const_op_asgn_and1.txt
- seattlerb/const_op_asgn_and2.txt
- seattlerb/const_op_asgn_or.txt
seattlerb/defn_arg_forward_args.txt
seattlerb/defn_args_forward_args.txt
seattlerb/defn_endless_command.txt
@@ -497,7 +492,6 @@ module Prism
seattlerb/op_asgn_command_call.txt
seattlerb/op_asgn_dot_ident_command_call.txt
seattlerb/op_asgn_index_command_call.txt
- seattlerb/op_asgn_primary_colon_const_command_call.txt
seattlerb/op_asgn_primary_colon_identifier1.txt
seattlerb/op_asgn_primary_colon_identifier_command_call.txt
seattlerb/op_asgn_val_dot_ident_command_call.txt
@@ -670,12 +664,10 @@ module Prism
whitequark/bug_while_not_parens_do.txt
whitequark/case_cond_else.txt
whitequark/case_expr_else.txt
- whitequark/casgn_toplevel.txt
whitequark/character.txt
whitequark/class_definition_in_while_cond.txt
whitequark/cond_begin_masgn.txt
whitequark/cond_match_current_line.txt
- whitequark/const_op_asgn.txt
whitequark/dedenting_heredoc.txt
whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt