Commit 347a9e21 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Return type defaults to "void" and doc to "".

parent 8db9c37f
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ module JsDuck
        :name => detect_name(:method, doc_map, code),
        :doc => detect_doc(docs),
        :params => detect_params(docs, code),
        :return => doc_map[:return] ? doc_map[:return].first : nil,
        :return => detect_return(doc_map),
        :private => !!doc_map[:private],
        :static => !!doc_map[:static],
      }
@@ -235,6 +235,14 @@ module JsDuck
      docs.find_all {|tag| tag[:tagname] == :param}
    end

    def detect_return(doc_map)
      ret = doc_map[:return] ? doc_map[:return].first : {}
      return {
        :type => ret[:type] || "void",
        :doc => ret[:doc] || "",
      }
    end

    # Combines :doc-s of most tags
    # Ignores tags that have doc comment themselves
    def detect_doc(docs)
+3 −11
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ module JsDuck
    end

    def signature_suffix(item)
      @short_params.render(item[:params]) + " : " + return_type(item)
      @short_params.render(item[:params]) + " : " + item[:return][:type]
    end

    def extra_doc(item)
@@ -28,22 +28,14 @@ module JsDuck
    end

    def render_return(item)
      type = return_type(item)
      doc = return_doc(item)
      type = item[:return][:type]
      doc = item[:return][:doc]
      if type == "void" && doc.length == 0
        "<ul><li>void</li></ul>"
      else
        "<ul><li><code>#{type}</code><div class='sub-desc'>#{doc}</div></li></ul>"
      end
    end

    def return_type(item)
      item[:return] ? (item[:return][:type] || "void") : "void"
    end

    def return_doc(item)
      item[:return] ? (item[:return][:doc] || "") : ""
    end
  end

end
+9 −4
Original line number Diff line number Diff line
@@ -182,6 +182,14 @@ function f(foo, bar){}
    assert_equal("Some really\nlong comment.", docs[0][:return][:doc])
  end

  def test_default_return_type_is_void
    docs = JsDuck.parse("/**
 * @method foo
 */")
    assert_equal("void", docs[0][:return][:type])
    assert_equal("", docs[0][:return][:doc])
  end

  def test_returns_is_alias_for_return
    docs = JsDuck.parse("/**
 * @method
@@ -191,18 +199,15 @@ function f(foo, bar){}
    assert_equal("blah", docs[0][:return][:doc])
  end

  def test_typeless_param_and_return
  def test_typeless_param
    docs = JsDuck.parse("/**
 * @method
 * @param x doc1
 * @return doc2
 */")
    assert_equal("x", docs[0][:params][0][:name])
    assert_equal("doc1", docs[0][:params][0][:doc])
    assert_equal("doc2", docs[0][:return][:doc])

    assert_equal(nil, docs[0][:params][0][:type])
    assert_equal(nil, docs[0][:return][:type])
  end

  def test_event