Commit 5a0ce3d2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Fix the parameter inheritance of Ext4 events.

Ignore the auto-inserted eOpts parameter.
parent dc5067f7
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -79,13 +79,7 @@ module JsDuck
      def inherit(m, parent)
        m[:doc] = parent[:doc] if m[:doc].empty?

        # Don't inherit params from parent when:
        # - member itself has params and these are not auto-detected
        # - or the params in parent are auto-detected.
        unless m[:params] && m[:params].length > 0 && !auto?(m, :params) || auto?(parent, :params)
          m[:params] = parent[:params]
        end

        m[:params] = parent[:params] if inherit_params?(m, parent)
        m[:return] = parent[:return] unless m[:return]
        m[:throws] = parent[:throws] unless m[:throws] && m[:throws].length > 0

@@ -97,6 +91,21 @@ module JsDuck
        end
      end

      def inherit_params?(m, parent)
        # ignore the eOpts auto-inserted param of Ext4-style events
        params = (m[:params] || []).reject {|p| p[:name] == "eOpts" }

        if params.length > 0 && !auto?(m, :params)
          # member itself has params and these are not auto-detected
          false
        elsif auto?(parent, :params)
          # Params in parent are auto-detected.
          false
        else
          true
        end
      end

      def auto_inherit(m, parent)
        m[:doc] = parent[:doc] if m[:doc].empty?

+43 −0
Original line number Diff line number Diff line
require "mini_parser"

describe JsDuck::Aggregator do
  def parse(string)
    Helper::MiniParser.parse(string, {:ext4_events => true, :inherit_doc => true})
  end

  describe "@inheritdoc in Ext JS 4 event" do
    before do
      @docs = parse(<<-EOF)
        /** */
        Ext.define("Foo", {
          /**
           * @event foo
           * Original comment.
           * @param arg1
           * @param arg2
           */
        });

        /** */
        Ext.define("Inh1", {
          /**
           * @event foo
           * @inheritdoc Foo#foo
           */
        });
      EOF
      @orig = @docs["Foo"][:members][0]
      @inh1 = @docs["Inh1"][:members][0]
    end

    it "generates 3rd param to original event" do
      @orig[:params].length.should == 3
    end

    it "inherits all three parameters" do
      @inh1[:params].length.should == 3
    end

  end

end