mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
[ruby/prism] Also handle BasicObject as a return value
We should touch these as little as possible and just pass them along https://github.com/ruby/prism/commit/52c4fa785e
This commit is contained in:
parent
913ffcd1dd
commit
8aedb89681
@ -832,7 +832,7 @@ module Prism
|
||||
# foo(bar)
|
||||
# ^^^
|
||||
def visit_arguments_node(node)
|
||||
arguments, _ = visit_call_node_arguments(node, nil, false)
|
||||
arguments, _, _ = visit_call_node_arguments(node, nil, false)
|
||||
arguments
|
||||
end
|
||||
|
||||
@ -1042,16 +1042,16 @@ module Prism
|
||||
case node.name
|
||||
when :[]
|
||||
receiver = visit(node.receiver)
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
arguments, block, has_ripper_block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
|
||||
bounds(node.location)
|
||||
call = on_aref(receiver, arguments)
|
||||
|
||||
if block.nil?
|
||||
call
|
||||
else
|
||||
if has_ripper_block
|
||||
bounds(node.location)
|
||||
on_method_add_block(call, block)
|
||||
else
|
||||
call
|
||||
end
|
||||
when :[]=
|
||||
receiver = visit(node.receiver)
|
||||
@ -1110,7 +1110,7 @@ module Prism
|
||||
if node.variable_call?
|
||||
on_vcall(message)
|
||||
else
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
|
||||
arguments, block, has_ripper_block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
|
||||
call =
|
||||
if node.opening_loc.nil? && get_arguments_and_block(node.arguments, node.block).first.any?
|
||||
bounds(node.location)
|
||||
@ -1123,11 +1123,11 @@ module Prism
|
||||
on_method_add_arg(on_fcall(message), on_args_new)
|
||||
end
|
||||
|
||||
if block.nil?
|
||||
call
|
||||
else
|
||||
if has_ripper_block
|
||||
bounds(node.block.location)
|
||||
on_method_add_block(call, block)
|
||||
else
|
||||
call
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1151,7 +1151,7 @@ module Prism
|
||||
bounds(node.location)
|
||||
on_assign(on_field(receiver, call_operator, message), value)
|
||||
else
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
|
||||
arguments, block, has_ripper_block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location))
|
||||
call =
|
||||
if node.opening_loc.nil?
|
||||
bounds(node.location)
|
||||
@ -1169,11 +1169,11 @@ module Prism
|
||||
on_method_add_arg(on_call(receiver, call_operator, message), arguments)
|
||||
end
|
||||
|
||||
if block.nil?
|
||||
call
|
||||
else
|
||||
if has_ripper_block
|
||||
bounds(node.block.location)
|
||||
on_method_add_block(call, block)
|
||||
else
|
||||
call
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1211,7 +1211,8 @@ module Prism
|
||||
on_args_add_block(args, false)
|
||||
end
|
||||
end,
|
||||
visit(block)
|
||||
visit(block),
|
||||
block != nil,
|
||||
]
|
||||
end
|
||||
|
||||
@ -1648,10 +1649,10 @@ module Prism
|
||||
end
|
||||
|
||||
bounds(node.location)
|
||||
if receiver.nil?
|
||||
on_def(name, parameters, bodystmt)
|
||||
else
|
||||
if receiver
|
||||
on_defs(receiver, operator, name, parameters, bodystmt)
|
||||
else
|
||||
on_def(name, parameters, bodystmt)
|
||||
end
|
||||
end
|
||||
|
||||
@ -2049,7 +2050,7 @@ module Prism
|
||||
# ^^^^^^^^^^^^^^^
|
||||
def visit_index_operator_write_node(node)
|
||||
receiver = visit(node.receiver)
|
||||
arguments, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
arguments, _, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
|
||||
bounds(node.location)
|
||||
target = on_aref_field(receiver, arguments)
|
||||
@ -2066,7 +2067,7 @@ module Prism
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
def visit_index_and_write_node(node)
|
||||
receiver = visit(node.receiver)
|
||||
arguments, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
arguments, _, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
|
||||
bounds(node.location)
|
||||
target = on_aref_field(receiver, arguments)
|
||||
@ -2083,7 +2084,7 @@ module Prism
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
def visit_index_or_write_node(node)
|
||||
receiver = visit(node.receiver)
|
||||
arguments, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
arguments, _, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
|
||||
bounds(node.location)
|
||||
target = on_aref_field(receiver, arguments)
|
||||
@ -2100,7 +2101,7 @@ module Prism
|
||||
# ^^^^^^^^
|
||||
def visit_index_target_node(node)
|
||||
receiver = visit(node.receiver)
|
||||
arguments, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
arguments, _, _ = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc))
|
||||
|
||||
bounds(node.location)
|
||||
on_aref_field(receiver, arguments)
|
||||
@ -3130,7 +3131,7 @@ module Prism
|
||||
# super(foo)
|
||||
# ^^^^^^^^^^
|
||||
def visit_super_node(node)
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.rparen_loc || node.location))
|
||||
arguments, block, has_ripper_block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.rparen_loc || node.location))
|
||||
|
||||
if !node.lparen_loc.nil?
|
||||
bounds(node.lparen_loc)
|
||||
@ -3140,11 +3141,11 @@ module Prism
|
||||
bounds(node.location)
|
||||
call = on_super(arguments)
|
||||
|
||||
if block.nil?
|
||||
call
|
||||
else
|
||||
if has_ripper_block
|
||||
bounds(node.block.location)
|
||||
on_method_add_block(call, block)
|
||||
else
|
||||
call
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -111,10 +111,18 @@ module Prism
|
||||
end
|
||||
|
||||
class ObjectEvents < Translation::Ripper
|
||||
OBJECT = BasicObject.new
|
||||
Prism::Translation::Ripper::PARSER_EVENTS.each do |event|
|
||||
define_method(:"on_#{event}") do |*args|
|
||||
Object.new
|
||||
end
|
||||
define_method(:"on_#{event}") { |*args| OBJECT }
|
||||
end
|
||||
end
|
||||
|
||||
Fixture.each_for_current_ruby(except: incorrect) do |fixture|
|
||||
define_method("#{fixture.test_name}_events") do
|
||||
source = fixture.read
|
||||
# Similar to test/ripper/assert_parse_files.rb in CRuby
|
||||
object_events = ObjectEvents.new(source)
|
||||
assert_nothing_raised { object_events.parse }
|
||||
end
|
||||
end
|
||||
|
||||
@ -160,10 +168,6 @@ module Prism
|
||||
|
||||
def assert_ripper_sexp_raw(source)
|
||||
assert_equal Ripper.sexp_raw(source), Prism::Translation::Ripper.sexp_raw(source)
|
||||
|
||||
# Similar to test/ripper/assert_parse_files.rb in CRuby
|
||||
object_events = ObjectEvents.new(source)
|
||||
assert_nothing_raised { object_events.parse }
|
||||
end
|
||||
|
||||
def assert_ripper_lex(source)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user