Skip to content

Commit

Permalink
Implement local variable targets in ripper translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 5, 2024
1 parent 57f991a commit 4e64b9f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,21 @@ def visit_array_node(node)
# foo => [bar]
# ^^^^^
def visit_array_pattern_node(node)
raise NoMethodError, __method__
constant = visit(node.constant)
requireds = visit_all(node.requireds) if node.requireds.any?
rest =
if !node.rest.nil?
if !node.rest.expression.nil?
visit(node.rest.expression)
else
bounds(node.rest.location)
on_var_field(nil)
end
end
posts = visit_all(node.posts) if node.posts.any?

bounds(node.location)
on_aryptn(constant, requireds, rest, posts)
end

# foo(bar)
Expand Down Expand Up @@ -492,7 +506,11 @@ def visit_call_target_node(node)
# foo => bar => baz
# ^^^^^^^^^^
def visit_capture_pattern_node(node)
raise NoMethodError, __method__
value = visit(node.value)
target = visit(node.target)

bounds(node.location)
on_binary(value, :"=>", target)
end

# case foo; when bar; end
Expand Down Expand Up @@ -1208,7 +1226,8 @@ def visit_local_variable_or_write_node(node)
# foo, = bar
# ^^^
def visit_local_variable_target_node(node)
raise NoMethodError, __method__
bounds(node.location)
on_var_field(on_ident(node.name.to_s))
end

# if /foo/ then end
Expand Down

0 comments on commit 4e64b9f

Please sign in to comment.