Commit b3740a5b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Integrate method calls detection.

parent c6a285d2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
require "jsduck/js/function"
require "jsduck/js/fires"
require "jsduck/js/method_calls"
require "jsduck/js/node"
require "jsduck/tag_registry"

@@ -318,6 +319,7 @@ module JsDuck
          :params => empty_array_to_nil(make_params(ast)),
          :chainable => chainable?(ast) && name != "constructor",
          :fires => empty_array_to_nil(detect_fires(ast)),
          :method_calls => empty_array_to_nil(detect_method_calls(ast)),
        }
      end

@@ -349,6 +351,14 @@ module JsDuck
        end
      end

      def detect_method_calls(ast)
        if ast.function? && !ast.ext_empty_fn?
          Js::MethodCalls.detect(ast)
        else
          []
        end
      end

      def make_event(name)
        return {
          :tagname => :event,
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ module JsDuck::Tag
      h[:params] = code[:params]
      h[:chainable] = code[:chainable]
      h[:fires] = code[:fires]
      h[:method_calls] = code[:method_calls]
      h
    end

+28 −0
Original line number Diff line number Diff line
require "mini_parser"

describe JsDuck::Aggregator do
  def parse(string)
    Helper::MiniParser.parse(string)
  end

  def parse_calls(string)
    parse(string)["global"][:members][0][:method_calls]
  end

  describe "function with method calls in code" do
    let(:calls) do
      parse_calls(<<-EOS)
        /** */
        function bar() {
            this.bar();
            this.foo();
        }
      EOS
    end

    it "detects these method calls" do
      calls.should == ["bar", "foo"]
    end
  end

end