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

Make @inheritdoc #membername work.

Previously #membername always had to be prefixed with full class name.
Now one can just use member name to reference member from current class.
parent 8614ee52
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -325,8 +325,11 @@ module JsDuck

      add_tag(:inheritdoc)
      skip_horiz_white

      if look(@ident_chain_pattern)
        @current_tag[:cls] = ident_chain
      end

      if look(/#\w/)
        @input.scan(/#/)
        if look(/static-/)
@@ -339,7 +342,7 @@ module JsDuck
        end
        @current_tag[:member] = ident
      end
      end

      skip_white
    end

+7 −0
Original line number Diff line number Diff line
@@ -48,6 +48,13 @@ module JsDuck
          warn("@inheritdoc #{inherit[:cls]}##{inherit[:member]} - member not found", context)
          return m
        end
      elsif inherit[:member]
        cls = @relations[m[:owner]]
        parent = cls.get_members(inherit[:member], inherit[:type] || m[:tagname], inherit[:static] || m[:meta][:static])[0]
        unless parent
          warn("@inheritdoc ##{inherit[:member]} - member not found", context)
          return m
        end
      else
        parent_cls = @relations[m[:owner]].parent
        mixins = @relations[m[:owner]].mixins
+24 −0
Original line number Diff line number Diff line
@@ -344,6 +344,30 @@ describe JsDuck::Aggregator do
    end
  end

  describe "@inheritdoc with member name parameter" do
    before do
      @docs = parse(<<-EOF)
        /**
         * @class Child
         */
          /**
           * @method bar
           * Original comment.
           */
          /**
           * @method foobar
           * @inheritdoc #bar
           * New comment.
           */
      EOF
      @inheritdoc = @docs["Child"][:members][:method][1]
    end

    it "merges comment from referenced member" do
      @inheritdoc[:doc].should == "New comment.\n\nOriginal comment."
    end
  end

  describe "@inheritdoc without parameter" do
    before do
      @docs = parse(<<-EOF)