class JsDuck::Js::MethodCalls

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

Public Instance Methods

detect(function_node) click to toggle source

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

# 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

Private Instance Methods

method_call?(node) click to toggle source

True when node is this.someMethod() call. Also true for me.someMethod() when me == this.

# File lib/jsduck/js/method_calls.rb, line 31
def method_call?(node)
  node.call_expression? &&
    node["callee"].member_expression? &&
    node["callee"].raw["computed"] == false &&
    @traverser.this?(node["callee"]["object"].to_s)
end