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

Ignore auto-detected constructor when @constructor present.

Happens quite often in Ext JS code where class doc-comment contains
@constructor and further down the code inside Ext.define() is the actual
constructor code that is auto-detected by JSDuck.
parent 150ea229
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ module JsDuck

    # Expands class-docset into multiple docsets.
    def expand(docset)
      @constructor_found = false

      expand_comment(docset) + expand_code(docset)
    end

@@ -84,6 +86,10 @@ module JsDuck
        }
      end
      if groups[:constructor].length > 0
        # Remember that a constructor is already found and ignore if a
        # constructor is detected from code.
        @constructor_found = true

        results << {
          :tagname => :method,
          :type => docset[:type],
@@ -103,7 +109,7 @@ module JsDuck
      if docset[:code]

        (docset[:code][:members] || []).each do |m|
          results << code_to_docset(m)
          results << code_to_docset(m) unless @constructor_found && m[:name] == "constructor"
        end

        (docset[:code][:statics] || []).each do |m|
+21 −0
Original line number Diff line number Diff line
@@ -80,4 +80,25 @@ describe JsDuck::Aggregator do
    it_should_behave_like "constructor"
  end

  describe "class with both @constructor tag and constructor property inside Ext.define()" do
    let(:methods) do
      parse(<<-EOS)[0][:members][:method]
        /**
         * Comment here.
         * @constructor
         * This constructs the class
         * @param {Number} nr
         */
        Ext.define("MyClass", {
            constructor: function() {
            }
        });
      EOS
    end

    it "detects just one constructor" do
      methods.length.should == 1
    end
  end

end