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

Default to Object when no type specified by @return.

This fixes the issue of return value docs being completely missing
in case @return wasn't followed by {TypeDef}.
parent 09057c7b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -257,9 +257,10 @@ module JsDuck
    end

    def detect_return(doc_map)
      has_return_tag = !!extract(doc_map, :return)
      ret = extract(doc_map, :return) || {}
      return {
        :type => ret[:type] || "undefined",
        :type => ret[:type] || (has_return_tag ? "Object" : "undefined"),
        :name => ret[:name] || "return",
        :doc => ret[:doc] || "",
        :properties => doc_map[:return] ? detect_subproperties(:return, doc_map[:return]) : []
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ module JsDuck
    end

    def add_return_new(m)
      if m[:return][:type] == "undefined"
      if m[:return][:type] == "undefined" || m[:return][:type] == "Object"
        # Create a whole new :return hash.
        # If we were to just change the :type field it would modify
        # the type of all the inherited constructor docs.
+18 −0
Original line number Diff line number Diff line
@@ -23,6 +23,24 @@ describe JsDuck::Aggregator do
    end
  end

  describe "method with @return that has no type" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some function
         * @return Some value.
         */
        function foo() {}
      EOS
    end
    it "defaults return type to Object" do
      @doc[:return][:type].should == "Object"
    end
    it "recognizes documentation of return value" do
      @doc[:return][:doc].should == "Some value."
    end
  end

  shared_examples_for "has return" do
    it "detects return type" do
      @doc[:return][:type].should == "String"