mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
[ruby/prism] Handle trailing commas in method calls for ripper translation
fe10b5f49f
This commit is contained in:
parent
dad21783ac
commit
409a49c832
2 changed files with 11 additions and 17 deletions
|
@ -554,7 +554,7 @@ module Prism
|
|||
case node.name
|
||||
when :[]
|
||||
receiver = visit(node.receiver)
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block)
|
||||
arguments, 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)
|
||||
|
@ -612,7 +612,7 @@ module Prism
|
|||
if node.variable_call?
|
||||
on_vcall(message)
|
||||
else
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block)
|
||||
arguments, 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? && (arguments&.any? || block.nil?)
|
||||
bounds(node.location)
|
||||
|
@ -653,7 +653,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)
|
||||
arguments, 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)
|
||||
|
@ -683,7 +683,7 @@ module Prism
|
|||
|
||||
# Visit the arguments and block of a call node and return the arguments
|
||||
# and block as they should be used.
|
||||
private def visit_call_node_arguments(arguments_node, block_node)
|
||||
private def visit_call_node_arguments(arguments_node, block_node, trailing_comma)
|
||||
arguments = arguments_node&.arguments || []
|
||||
block = block_node
|
||||
|
||||
|
@ -698,7 +698,7 @@ module Prism
|
|||
elsif arguments.any?
|
||||
args = visit_arguments(arguments)
|
||||
|
||||
if block_node.is_a?(BlockArgumentNode) || arguments.last.is_a?(ForwardingArgumentsNode)
|
||||
if block_node.is_a?(BlockArgumentNode) || arguments.last.is_a?(ForwardingArgumentsNode) || trailing_comma
|
||||
args
|
||||
else
|
||||
bounds(arguments.first.location)
|
||||
|
@ -2479,7 +2479,7 @@ module Prism
|
|||
# super(foo)
|
||||
# ^^^^^^^^^^
|
||||
def visit_super_node(node)
|
||||
arguments, block = visit_call_node_arguments(node.arguments, node.block)
|
||||
arguments, 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)
|
||||
|
@ -2696,6 +2696,11 @@ module Prism
|
|||
# Helpers
|
||||
##########################################################################
|
||||
|
||||
# Returns true if there is a comma between the two locations.
|
||||
def trailing_comma?(left, right)
|
||||
source.byteslice(left.end_offset...right.start_offset).include?(",")
|
||||
end
|
||||
|
||||
# Returns true if there is a semicolon between the two locations.
|
||||
def void_stmt?(left, right)
|
||||
source.byteslice(left.end_offset...right.start_offset).match?(/[;#]/)
|
||||
|
|
|
@ -51,13 +51,9 @@ module Prism
|
|||
seattlerb/block_command_operation_dot.txt
|
||||
seattlerb/block_next.txt
|
||||
seattlerb/block_return.txt
|
||||
seattlerb/bug_hash_args_trailing_comma.txt
|
||||
seattlerb/bug_hash_interp_array.txt
|
||||
seattlerb/call_args_assoc_trailing_comma.txt
|
||||
seattlerb/call_args_command.txt
|
||||
seattlerb/call_array_lambda_block_call.txt
|
||||
seattlerb/call_assoc_trailing_comma.txt
|
||||
seattlerb/call_trailing_comma.txt
|
||||
seattlerb/defn_oneliner_eq2.txt
|
||||
seattlerb/defs_oneliner_eq2.txt
|
||||
seattlerb/difficult3_5.txt
|
||||
|
@ -76,13 +72,9 @@ module Prism
|
|||
seattlerb/lambda_do_vs_brace.txt
|
||||
seattlerb/masgn_arg_colon_arg.txt
|
||||
seattlerb/masgn_double_paren.txt
|
||||
seattlerb/method_call_assoc_trailing_comma.txt
|
||||
seattlerb/method_call_trailing_comma.txt
|
||||
seattlerb/parse_line_dstr_escaped_newline.txt
|
||||
seattlerb/parse_line_dstr_soft_newline.txt
|
||||
seattlerb/parse_line_evstr_after_break.txt
|
||||
seattlerb/parse_opt_call_args_assocs_comma.txt
|
||||
seattlerb/parse_opt_call_args_lit_comma.txt
|
||||
seattlerb/parse_pattern_051.txt
|
||||
seattlerb/parse_pattern_058.txt
|
||||
seattlerb/return_call_assocs.txt
|
||||
|
@ -117,9 +109,6 @@ module Prism
|
|||
until.txt
|
||||
variables.txt
|
||||
while.txt
|
||||
whitequark/args_args_assocs_comma.txt
|
||||
whitequark/args_args_comma.txt
|
||||
whitequark/args_assocs_comma.txt
|
||||
whitequark/args_cmd.txt
|
||||
whitequark/asgn_mrhs.txt
|
||||
whitequark/bug_480.txt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue