class Unparser::AST::LocalVariableScopeEnumerator

Local variable scope enumerator

def self.each(node:, stack:, &block)

Enumerate each node with its local variable scope
def self.each(node:, stack:, &block)
  new(stack: stack).each(node: node, &block)
end

def current

def current
  @stack.last
end

def define(name)

def define(name)
  current << name
end

def each(node:, &block)

Other tags:
    Api: - private

Returns:
  • (Enumerator>) - ]
  • (self) -
def each(node:, &block)
  visit(node, &block)
end

def enter(node)

def enter(node)
  case node.type
  when *RESET_NODES
    push_reset
  when ASSIGN_NODES
    value = node.children.first and define(value)
  when *INHERIT_NODES
    push_inherit
  end
end

def initialize(stack:)

Other tags:
    Api: - private

Returns:
  • (undefined) -
def initialize(stack:)
  @stack = [stack]
end

def leave(node)

def leave(node)
  pop if CLOSE_NODES.include?(node.type)
end

def pop

def pop
  @stack.pop
end

def push_inherit

def push_inherit
  @stack << current.dup
end

def push_reset

def push_reset
  @stack << Set.new
end

def visit(node, &block)

def visit(node, &block)
  before = current.dup
  enter(node)
  yield node, current.dup, before
  node.children.each do |child|
    visit(child, &block) if child.instance_of?(Parser::AST::Node)
  end
  leave(node)
end