Class: JsDuck::FunctionAst

Inherits:
Object
  • Object
show all
Includes:
Util::Singleton
Defined in:
lib/jsduck/function_ast.rb

Overview

Analyzes the AST of a FunctionDeclaration or FunctionExpression.

Instance Method Summary collapse

Methods included from Util::Singleton

included

Instance Method Details

#return_types(ast) ⇒ Object

Detects possible return types of the given function.

For now there are three possible detected return values:

  • :this - the code contins ‘return this;’

  • “undefined” - the code finishes by returning undefined or without explicitly returning anything

  • :other - some other value is returned.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jsduck/function_ast.rb', line 22

def return_types(ast)
  h = return_types_hash(ast["body"]["body"])

  # Replace the special :void value that signifies possibility of
  # exiting without explicitly returning anything
  if h[:void]
    h["undefined"] = true
    h.delete(:void)
  end

  h.keys
end