lib/node_mutation/adapter/parser.rb in node_mutation-1.18.0 vs lib/node_mutation/adapter/parser.rb in node_mutation-1.18.1

- old
+ new

@@ -78,18 +78,35 @@ return NodeMutation::Struct::Range.new(child_node.loc.expression.begin_pos, child_node.loc.expression.end_pos) end case [node.type, child_name.to_sym] when %i[block pipes], %i[def parentheses], %i[defs parentheses] - NodeMutation::Struct::Range.new( - node.arguments.first.loc.expression.begin_pos - 1, - node.arguments.last.loc.expression.end_pos + 1 - ) + if node.arguments.empty? + nil + else + NodeMutation::Struct::Range.new( + node.arguments.first.loc.expression.begin_pos - 1, + node.arguments.last.loc.expression.end_pos + 1 + ) + end when %i[block arguments], %i[def arguments], %i[defs arguments] - NodeMutation::Struct::Range.new( - node.arguments.first.loc.expression.begin_pos, - node.arguments.last.loc.expression.end_pos - ) + if node.arguments.empty? + nil + else + NodeMutation::Struct::Range.new( + node.arguments.first.loc.expression.begin_pos, + node.arguments.last.loc.expression.end_pos + ) + end + when %i[block body], %i[class body], %i[def body], %i[defs body], %i[module body] + if node.body.empty? + nil + else + NodeMutation::Struct::Range.new( + node.body.first.loc.expression.begin_pos, + node.body.last.loc.expression.end_pos + ) + end when %i[class name], %i[const name], %i[cvar name], %i[def name], %i[defs name], %i[gvar name], %i[ivar name], %i[lvar name] NodeMutation::Struct::Range.new(node.loc.name.begin_pos, node.loc.name.end_pos) when %i[const double_colon] NodeMutation::Struct::Range.new(node.loc.double_colon.begin_pos, node.loc.double_colon.end_pos) when %i[defs dot]