lib/rbi/rewriters/remove_known_definitions.rb in rbi-0.0.8 vs lib/rbi/rewriters/remove_known_definitions.rb in rbi-0.0.9
- old
+ new
@@ -81,16 +81,16 @@
case node
when RBI::Scope
visit_all(node.nodes)
previous = previous_definition_for(node)
- delete_node(node, previous) if previous && node.empty?
+ delete_node(node, previous) if previous && can_delete_node?(node, previous)
when RBI::Tree
visit_all(node.nodes)
when RBI::Indexable
previous = previous_definition_for(node)
- delete_node(node, previous) if previous
+ delete_node(node, previous) if previous && can_delete_node?(node, previous)
end
end
private
@@ -99,9 +99,27 @@
node.index_ids.each do |id|
previous = @index[id].first
return previous if previous
end
nil
+ end
+
+ sig { params(node: Node, previous: Node).returns(T::Boolean) }
+ def can_delete_node?(node, previous)
+ return false unless node.class == previous.class
+
+ case node
+ when Scope
+ node.empty?
+ when Attr
+ previous = T.cast(previous, Attr)
+ node.names == previous.names && node.sigs == previous.sigs
+ when Method
+ previous = T.cast(previous, Method)
+ node.params == previous.params && node.sigs == previous.sigs
+ else
+ true
+ end
end
sig { params(node: RBI::Node, previous: RBI::Node).void }
def delete_node(node, previous)
node.detach