Sha256: 1b1ee099c9dee95e47d6ebd3634d26bff5b70353cd2d9f3768bb8bb5d114b24b
Contents?: true
Size: 1.04 KB
Versions: 28
Compression:
Stored size: 1.04 KB
Contents
require "jsduck/util/singleton" require "jsduck/js/scoped_traverser" module JsDuck module Js # Looks the AST of a FunctionDeclaration or FunctionExpression for # calls to methods of the owner class. class MethodCalls include Util::Singleton # Returns array of method names called by the given function. # When no methods called, empty array is returned. 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 # True when node is this.someMethod() call. # Also true for me.someMethod() when me == this. def method_call?(node) node.call_expression? && node["callee"].member_expression? && node["callee"].raw["computed"] == false && @traverser.this?(node["callee"]["object"].to_s) end end end end
Version data entries
28 entries across 28 versions & 3 rubygems