Skip to content

Commit

Permalink
Merge 4f45af8 into 1decb24
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Apr 1, 2021
2 parents 1decb24 + 4f45af8 commit ddb5292
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions lib/synvert/core/node_ext.rb
Expand Up @@ -362,12 +362,23 @@ def child_node_range(child_name)
when :dot
loc.dot
when :message
loc.operator ? Parser::Source::Range.new('(string)', loc.selector.begin_pos, loc.operator.end_pos) : loc.selector
if loc.operator
Parser::Source::Range.new('(string)', loc.selector.begin_pos, loc.operator.end_pos)
else
loc.selector
end
when :arguments
Parser::Source::Range.new('(string)', arguments.first.loc.expression.begin_pos, arguments.last.loc.expression.end_pos) unless arguments.empty?
unless arguments.empty?
Parser::Source::Range.new(
'(string)',
arguments.first.loc.expression.begin_pos,
arguments.last.loc.expression.end_pos
)
end
end
else
raise Synvert::Core::MethodNotSupported, "child_node_range is not handled for #{evaluated.inspect}, child_name: #{child_name}"
raise Synvert::Core::MethodNotSupported,
"child_node_range is not handled for #{evaluated.inspect}, child_name: #{child_name}"
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/synvert/core/rewriter/action/delete_action_spec.rb
Expand Up @@ -5,18 +5,18 @@
module Synvert::Core
describe Rewriter::DeleteAction do
subject {
source = "arr.map {}.flatten"
source = 'arr.map {}.flatten'
node = Parser::CurrentRuby.parse(source)
instance = double(current_node: node)
Rewriter::DeleteAction.new(instance, :dot, :message)
}

it 'gets begin_pos' do
expect(subject.begin_pos).to eq "arr.map {}".length
expect(subject.begin_pos).to eq 'arr.map {}'.length
end

it 'gets end_pos' do
expect(subject.end_pos).to eq "arr.map {}.flatten".length
expect(subject.end_pos).to eq 'arr.map {}.flatten'.length
end

it 'gets rewritten_code' do
Expand Down

0 comments on commit ddb5292

Please sign in to comment.