Module: Solargraph::Parser::Rubyvm::NodeMethods::DeepInference

Defined in:
lib/solargraph/parser/rubyvm/node_methods.rb

Constant Summary collapse

CONDITIONAL =
[:IF, :UNLESS]
REDUCEABLE =
[:BLOCK]
SKIPPABLE =
[:DEFN, :DEFS, :CLASS, :SCLASS, :MODULE]

Class Method Summary collapse

Class Method Details

.get_return_nodes(node) ⇒ Array<Parser::AST::Node>

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (Array<Parser::AST::Node>)


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/solargraph/parser/rubyvm/node_methods.rb', line 213

def get_return_nodes node
  return [] unless node.is_a?(RubyVM::AbstractSyntaxTree::Node)
  result = []
  if REDUCEABLE.include?(node.type)
    result.concat get_return_nodes_from_children(node)
  elsif CONDITIONAL.include?(node.type)
    result.concat reduce_to_value_nodes(node.children[1..-1])
  elsif node.type == :RESCUE
    result.concat reduce_to_value_nodes([node.children[0]])
    result.concat reduce_to_value_nodes(node.children[1..-2])
  elsif node.type == :OR
    result.concat reduce_to_value_nodes(node.children)
  elsif node.type == :RETURN
    result.concat reduce_to_value_nodes([node.children[0]])
  elsif node.type == :ITER
    result.push node
    result.concat get_return_nodes_only(node.children[1])
  elsif node.type == :CASE
    node.children[1..-1].each do |cc|
      result.concat reduce_to_value_nodes(cc.children[1..-1])
    end
  else
    result.push node
  end
  result
end