Class: JsDuck::Js::MethodCalls

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

Overview

Looks the AST of a FunctionDeclaration or FunctionExpression for calls to methods of the owner class.

Instance Method Summary collapse

Methods included from Util::Singleton

included

Instance Method Details

#detect(function_node) ⇒ Object

Returns array of method names called by the given function. When no methods called, empty array is returned.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jsduck/js/method_calls.rb', line 14

def detect(function_node)
  @traverser = Js::ScopedTraverser.new

  methods = []
  @traverser.traverse(function_node["body"]) do |node|
    if method_call?(node)
      methods << node["callee"]["property"].to_s
    end
  end

  methods.sort.uniq
end