Module: Solargraph::Parser::Legacy::NodeMethods::DeepInference

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

Constant Summary collapse

CONDITIONAL =
[:if, :unless]
REDUCEABLE =
[:begin, :kwbegin]
SKIPPABLE =
[:def, :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>)


228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/solargraph/parser/legacy/node_methods.rb', line 228

def get_return_nodes node
  return [] unless node.is_a?(::Parser::AST::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])
    # result.push NIL_NODE unless node.children[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 == :block
    result.push node
    result.concat get_return_nodes_only(node.children[2])
  elsif node.type == :case
    node.children[1..-1].each do |cc|
      if cc.nil?
        result.push NIL_NODE
      else
        result.concat reduce_to_value_nodes(cc.children[1..-2]) unless cc.children.length < 1
        result.concat reduce_to_value_nodes([cc.children.last])
      end
    end
  else
    result.push node
  end
  result
end