Commit 897b8ef6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Added @function to explicitly document function.

parent 14b72ebf
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -102,9 +102,11 @@ module JsDuck

    # sets the name and properties of the default at-tag
    def set_default(tagname, attrs={})
      if !@tags[tagname] then
        @tags[tagname] = attrs
        @tags[tagname][:doc] = @tags[:default][:doc]
      end
    end

    def [](tagname)
      @tags[tagname]
@@ -133,6 +135,8 @@ module JsDuck
          at_return
        elsif look(/@param\b/) then
          at_param
        elsif look(/@function\b/) then
          at_function
        elsif look(/@/) then
          @current_tag[:doc] += @input.scan(/@/)
        elsif look(/[^@]/) then
@@ -172,6 +176,17 @@ module JsDuck
      skip_white
    end

    # matches @return {type} ...
    def at_function
      match(/@function/)
      @current_tag = @tags[:function] = {:doc => ""}
      skip_white
      if look(/\w/) then
        @current_tag[:name] = ident
      end
      skip_white
    end

    # matches {...} and returns text inside brackets
    def typedef
      match(/\{/)
+25 −0
Original line number Diff line number Diff line
@@ -117,5 +117,30 @@ function foo() {
")
    assert_equal([], docs)
  end

  def test_explicit_function_doc
    docs = JsDuck.parse("
/**
 * @function hello
 * Just some function
 */
eval('hello = new Function();');
")
    assert_equal("hello", docs[0][:function][:name])
    assert_equal("Just some function", docs[0][:function][:doc])
  end

  def test_explicit_function_doc_overrides_implicit_code
    docs = JsDuck.parse("
/**
 * @function hello
 * Just some function
 */
function goodby(){}
")
    assert_equal("hello", docs[0][:function][:name])
    assert_equal("Just some function", docs[0][:function][:doc])
  end

end