Class: Tapioca::Compilers::SymbolTable::SymbolLoader::SymbolTableParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tapioca/compilers/symbol_table/symbol_loader.rb

Class Method Summary collapse

Class Method Details

.parse(object, parents = []) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tapioca/compilers/symbol_table/symbol_loader.rb', line 57

def self.parse(object, parents = [])
  symbols = Set.new

  children = object.fetch("children", [])

  children.each do |child|
    kind = child.fetch("kind")
    name = child.fetch("name")
    name = name.fetch("name") if name.is_a?(Hash)

    next if kind.nil? || name.nil?

    # TODO: CLASS is removed since v0.4.4730 of Sorbet
    # but keeping here for backward compatibility. Remove
    # once the minimum version is moved past that.
    next unless ["CLASS", "CLASS_OR_MODULE", "STATIC_FIELD"].include?(kind)
    next if name =~ /[<>()$]/
    next if name =~ /^[0-9]+$/
    next if name == "T::Helpers"

    parents << name

    symbols.add(parents.join("::"))
    symbols.merge(parse(child, parents))

    parents.pop
  end
  symbols
end