mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 18:43:59 +02:00
[ruby/prism] Implement local variable targets in ripper translation
4e64b9fc53
This commit is contained in:
parent
862a188826
commit
f44671b094
1 changed files with 22 additions and 3 deletions
|
@ -256,7 +256,21 @@ module Prism
|
||||||
# foo => [bar]
|
# foo => [bar]
|
||||||
# ^^^^^
|
# ^^^^^
|
||||||
def visit_array_pattern_node(node)
|
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
|
end
|
||||||
|
|
||||||
# foo(bar)
|
# foo(bar)
|
||||||
|
@ -492,7 +506,11 @@ module Prism
|
||||||
# foo => bar => baz
|
# foo => bar => baz
|
||||||
# ^^^^^^^^^^
|
# ^^^^^^^^^^
|
||||||
def visit_capture_pattern_node(node)
|
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
|
end
|
||||||
|
|
||||||
# case foo; when bar; end
|
# case foo; when bar; end
|
||||||
|
@ -1208,7 +1226,8 @@ module Prism
|
||||||
# foo, = bar
|
# foo, = bar
|
||||||
# ^^^
|
# ^^^
|
||||||
def visit_local_variable_target_node(node)
|
def visit_local_variable_target_node(node)
|
||||||
raise NoMethodError, __method__
|
bounds(node.location)
|
||||||
|
on_var_field(on_ident(node.name.to_s))
|
||||||
end
|
end
|
||||||
|
|
||||||
# if /foo/ then end
|
# if /foo/ then end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue