Commit 22e80122 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for @constructor.

@constructor is equivalent of @function with name "constructor".
parent 5e5e6270
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ module JsDuck
          at_event
        elsif look(/@function\b/) then
          at_function
        elsif look(/@constructor\b/) then
          at_constructor
        elsif look(/@param\b/) then
          at_param
        elsif look(/@return\b/) then
@@ -143,7 +145,7 @@ module JsDuck
      skip_white
    end

    # matches @return {type} ...
    # matches @function name ...
    def at_function
      match(/@function/)
      @current_tag = @tags[:function] = {:doc => ""}
@@ -154,6 +156,14 @@ module JsDuck
      skip_white
    end

    # matches @constructor ...
    # Which is equivalent of: @function constructor ...
    def at_constructor
      match(/@constructor/)
      @current_tag = @tags[:function] = {:doc => "", :name => "constructor"}
      skip_white
    end

    # matches @param {type} variable ...
    def at_param
      match(/@param/)
+9 −0
Original line number Diff line number Diff line
@@ -28,6 +28,15 @@ class TestDocComment < Test::Unit::TestCase
    assert_equal("resulting value", doc[:return][:doc])
  end

  def test_constructor
    doc = JsDuck::DocComment.new("/**
 * @constructor
 * Some docs.
 */")
    assert_equal("constructor", doc[:function][:name])
    assert_equal("Some docs.", doc[:function][:doc])
  end

  def test_class
    doc = JsDuck::DocComment.new("/**
 * @class my.package.Foo