module TurboTest::StaticAnalysis::Constants::NodeProcessor

Private Instance Methods

add_children(node) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 81
def add_children(node)
  @all_nodes.reject! do |children_candidate|
    node.contains?(children_candidate).tap do |child|
      node.add_child(children_candidate) if child && children_candidate.definition == false
    end
  end
end
add_const_ref(token, top_level: false) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 89
def add_const_ref(token, top_level: false)
  node = new_node_from_token(token)
  node.top_level = top_level
  @const_refs[node_key(token)] = node
end
add_referenced_top_constant(name) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 95
def add_referenced_top_constant(name)
  @referenced_top_constants[name] = true
end
assign_children(node) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 71
def assign_children(node)
  if @referenced_top_constants.delete(node.name)
    @all_nodes.unshift(node)
    add_children(node)
  else
    add_children(node)
    @all_nodes.unshift(node)
  end
end
class_nodes_names_without_singletons_and_unknowns() click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 55
def class_nodes_names_without_singletons_and_unknowns
  @class_nodes.map(&:full_name).reject do |full_name|
    full_name.end_with?("singleton_class") || full_name.include?("unknown_ref")
  end.uniq
end
find_and_update_node(token) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 99
def find_and_update_node(token)
  @const_refs.delete(node_key(token[1])).tap do |node|
    node.end_pos = [lineno, column] if node
  end
end
node_key(token) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 9
def node_key(token)
  "#{token[1]}-#{token[2].join('-')}"
end
process_class_nodes() click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 24
def process_class_nodes
  @class_nodes.reject! do |class_node|
    next process_definition_class_node(class_node) if class_node.root.definition

    @referenced_constants[class_node.name] = true if class_node.named_singleton_with_parent?
    class_node.parent_is_named_singleton? || class_node.named_singleton_with_parent?
  end

  @defined_classes = class_nodes_names_without_singletons_and_unknowns
end
process_definition_class_node(node) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 35
def process_definition_class_node(node)
  container_node = @class_nodes.find do |class_node|
    class_node != node.root && class_node.contains?(node.root)
  end
  return false if container_node.nil?

  @referenced_constants[node.full_name] = true if node.name != "self"
  true
end
process_module(node) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 13
def process_module(node)
  @var_refs.reject! do |var_ref|
    (var_ref.name == node.name && var_ref.start_pos == node.start_pos) ||
      node.contains?(var_ref).tap do |condition|
        @referenced_constants[var_ref.name] = true if condition
      end
  end
  @class_nodes.push node
  assign_children(node)
end
process_var_refs() click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 45
def process_var_refs
  @var_refs.each do |var_ref|
    if @block_nodes.find { |node| node.contains?(var_ref) }
      @referenced_constants[var_ref.name] = true
    else
      @referenced_top_constants[var_ref.name] = true
    end
  end
end
reject_children_in_class_nodes(node) click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 105
def reject_children_in_class_nodes(node)
  @class_nodes.reject! do |class_node|
    node.contains?(class_node).tap do |child|
      @referenced_constants[class_node.full_name] = true if child
    end
  end
end
reject_unknown_constants() click to toggle source
# File lib/turbo_test_static_analysis/constants/node_processor.rb, line 61
def reject_unknown_constants
  @referenced_top_constants.reject! do |key, _value|
    key.include?("unknown_ref")
  end

  @referenced_constants.reject! do |key, _value|
    key.include?("unknown_ref")
  end
end