Sha256: b7585476450ae94d23cfe734fff58212cebcc0597ec8a324616de0be8cfc2244

Contents?: true

Size: 636 Bytes

Versions: 3

Compression:

Stored size: 636 Bytes

Contents

# typed: true
# 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

    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
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
packwerk-2.3.0 lib/packwerk/node_visitor.rb
packwerk-2.2.2 lib/packwerk/node_visitor.rb
packwerk-2.2.1 lib/packwerk/node_visitor.rb