Sha256: c973918c5316353ca79004734c3e8daf15111677e1cdfa398c862944a4e9f3db

Contents?: true

Size: 555 Bytes

Versions: 2

Compression:

Stored size: 555 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
    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
      Node.each_child(node) do |child|
        visit(child, ancestors: child_ancestors, result: result)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
packwerk-2.0.0 lib/packwerk/node_visitor.rb
packwerk-1.4.0 lib/packwerk/node_visitor.rb