Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ GEM
parser_node_ext (1.3.0)
parser
prettier_print (1.2.1)
prism (0.25.0)
prism_ext (0.3.0)
prism (0.30.0)
prism_ext (0.3.4)
prism
pry (0.14.1)
coderay (~> 1.1)
Expand Down
3 changes: 2 additions & 1 deletion lib/node_mutation/action/append_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize(node, code, adapter:)
# @return [String] rewritten code.
def new_code
if rewritten_source.split("\n").length > 1
"\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") + "\n"
"\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }
.join("\n") + "\n"
else
indent(@node) + rewritten_source + "\n"
end
Expand Down
3 changes: 2 additions & 1 deletion lib/node_mutation/action/prepend_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize(node, code, adapter:)
# @return [String] rewritten code.
def new_code
if rewritten_source.split("\n").length > 1
"\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }.join("\n") + "\n"
"\n" + rewritten_source.split("\n").map { |line| indent(@node) + line }
.join("\n") + "\n"
else
indent(@node) + rewritten_source + "\n"
end
Expand Down
20 changes: 16 additions & 4 deletions lib/node_mutation/adapter/prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def child_node_range(node, child_name)
"#{direct_child_name} is not supported for #{get_source(node)}" unless child_node
return child_node_range(child_node, nested_child_name) if nested_child_name

return NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
return NodeMutation::Struct::Range.new(
child_node.location.start_character_offset,
child_node.location.end_character_offset
)
end

raise NodeMutation::MethodNotSupported,
Expand All @@ -133,7 +136,10 @@ def child_node_range(node, child_name)
child_node = node.send(direct_child_name)
return child_node_range(child_node, nested_child_name) if nested_child_name

return NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
return NodeMutation::Struct::Range.new(
child_node.location.start_character_offset,
child_node.location.end_character_offset
)
end

if node.respond_to?("#{child_name}_loc")
Expand All @@ -156,12 +162,18 @@ def child_node_range(node, child_name)

if child_node.is_a?(Prism::Node)
return(
NodeMutation::Struct::Range.new(child_node.location.start_character_offset, child_node.location.end_character_offset)
NodeMutation::Struct::Range.new(
child_node.location.start_character_offset,
child_node.location.end_character_offset
)
)
end

return(
NodeMutation::Struct::Range.new(child_node.first.location.start_character_offset, child_node.last.location.end_character_offset)
NodeMutation::Struct::Range.new(
child_node.first.location.start_character_offset,
child_node.last.location.end_character_offset
)
)
end
end
Expand Down