Sha256: 44e31807978a3c6e700760552dd8bf08a47cb169ee15a4240d4da912cf1049da

Contents?: true

Size: 845 Bytes

Versions: 6

Compression:

Stored size: 845 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module Packwerk
  # Visits all nodes of an AST, processing them using a given node processor.
  class NodeVisitor
    extend T::Sig

    sig { params(node_processor: NodeProcessor).void }
    def initialize(node_processor:)
      @node_processor = node_processor
    end

    sig do
      params(
        node: Parser::AST::Node,
        ancestors: T::Array[Parser::AST::Node],
        result: T::Array[UnresolvedReference],
      ).void
    end
    def visit(node, ancestors:, result:)
      reference = @node_processor.call(node, ancestors)
      result << reference if reference

      child_ancestors = [node] + ancestors
      NodeHelpers.each_child(node) do |child|
        visit(child, ancestors: child_ancestors, result: result)
      end
    end
  end

  private_constant :NodeVisitor
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
packwerk-3.2.2 lib/packwerk/node_visitor.rb
packwerk-3.2.1 lib/packwerk/node_visitor.rb
packwerk-3.2.0 lib/packwerk/node_visitor.rb
packwerk-3.1.0 lib/packwerk/node_visitor.rb
packwerk-3.0.1 lib/packwerk/node_visitor.rb
packwerk-3.0.0 lib/packwerk/node_visitor.rb