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

Make @inheritdoc work with mixins.

Previously @inheritdoc only looked for member with same name from
parent class, now we also look from mixins.
parent ffd91cc7
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -49,12 +49,27 @@ module JsDuck
        end
      else
        parent_cls = @relations[m[:owner]].parent
        unless parent_cls
        mixins = @relations[m[:owner]].mixins
        # Warn when no parent or mixins at all
        if !parent_cls && mixins.length == 0
          warn("@inheritdoc - parent class not found", context)
          return m
        end
        # First check for the member in all mixins, because members
        # from mixins override those from parent class.  Looking first
        # from mixins is probably a bit slower, but it's the correct
        # order to do things.
        if mixins.length > 0
          parent = mixins.map do |mix|
            mix.get_members(m[:name], m[:tagname], m[:meta][:static])[0]
          end.compact.first
        end
        # When not found, try looking from parent class
        if !parent && parent_cls
          parent = parent_cls.get_members(m[:name], m[:tagname], m[:meta][:static])[0]
        unless parent
        end
        # Only when both parent and mixins fail, throw warning
        if !parent
          warn("@inheritdoc - parent member not found", context)
          return m
        end
+27 −0
Original line number Diff line number Diff line
@@ -425,5 +425,32 @@ describe JsDuck::Aggregator do
    end
  end

  describe "@inheritdoc in method overriding mixin method" do
    before do
      @docs = parse(<<-EOF)
        /**
         * @class Mixin
         */
          /**
           * @method foo
           * Docs in mixin.
           */
        /**
         * @class Child
         * @mixins Mixin
         */
          /**
           * @method foo
           * @inheritdoc
           */
      EOF
      @method = @docs["Child"][:members][:method][0]
    end

    it "inherits docs from mixin" do
      @method[:doc].should == "Docs in mixin."
    end
  end

end