Commit 373206ef authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Inheritance of visibility for auto-detected members.

When parent member is public, the auto-detected child that overrides it
will also become public.  Similarly when parent is explicitly set to
private, the child will become private.

But when no parent at all, auto-detected members will be private.
parent a2233047
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ module JsDuck
          docset[:code] = cfg
        else
          cfg[:inheritdoc] = {:no_warnings => true}
          cfg[:private] = true
          cfg[:private] = :inherit
          configs << cfg
        end
      end
+29 −7
Original line number Diff line number Diff line
@@ -21,14 +21,33 @@ module JsDuck
      end
    end

    private

    # Copy over doc/params/return from parent member.
    def resolve(m)
      parent = find_parent(m)

      if parent
        m[:doc] = (m[:doc] + "\n\n" + parent[:doc]).strip
        m[:params] = parent[:params] if parent[:params]
        m[:return] = parent[:return] if parent[:return]
      end

      resolve_visibility(m, parent)
    end

    # For auto-detected members/classes (which have @private == :inherit)
    # Use the visibility from parent class (defaulting to private when no parent).
    def resolve_visibility(m, parent)
      if m[:private] == :inherit
        if parent
          m[:meta][:private] = m[:private] = parent[:private]
        else
          m[:meta][:private] = m[:private] = true
        end
      end
    end

    # Finds parent member of the given member.  When @inheritdoc names
    # a member to inherit from, finds that member instead.
    #
@@ -56,7 +75,7 @@ module JsDuck
        # Warn when no parent or mixins at all
        if !parent_cls && mixins.length == 0
          warn("parent class not found", m) unless inherit[:no_warnings]
          return m
          return nil
        end

        # First check for the member in all mixins, because members
@@ -75,7 +94,7 @@ module JsDuck
        # Only when both parent and mixins fail, throw warning
        if !parent
          warn("parent member not found", m) unless inherit[:no_warnings]
          return m
          return nil
        end
      end

@@ -90,8 +109,11 @@ module JsDuck
    # Copy over doc from parent class.
    def resolve_class(cls)
      parent = find_class_parent(cls)

      if parent
        cls[:doc] = (cls[:doc] + "\n\n" + parent[:doc]).strip
      end
    end

    def find_class_parent(cls)
      if cls[:inheritdoc][:cls]
@@ -114,7 +136,7 @@ module JsDuck
      msg = "@inheritdoc #{item[:inheritdoc][:cls]}"+ (i_member ? "#" + i_member : "") + " - " + msg
      Logger.instance.warn(:inheritdoc, msg, context[:filename], context[:linenr])

      return item
      return nil
    end

  end
+6 −4
Original line number Diff line number Diff line
@@ -36,12 +36,14 @@ describe JsDuck::Aggregator do
      cfg[0][:inheritdoc].should == {:no_warnings => true}
    end

    it "sets :private flag on config" do
      cfg[0][:private].should == true
    # The inheriting of :private will be solved by InheritDoc class.

    it "sets :private flag on config is :inherit" do
      cfg[0][:private].should == :inherit
    end

    it "sets meta :private flag on config" do
      cfg[0][:meta][:private].should == true
    it "sets :private flag on config is :inherit (meta)" do
      cfg[0][:meta][:private].should == :inherit
    end
  end

+77 −1
Original line number Diff line number Diff line
@@ -546,10 +546,86 @@ describe JsDuck::Aggregator do
        });
      EOF
      @cls = @docs["Child"]
      @cfg = @cls[:members][:cfg][0]
    end

    it "inherits docs from parent" do
      @cls[:members][:cfg][0][:doc].should == "My config."
      @cfg[:doc].should == "My config."
    end

    it "inherits being public from parent" do
      @cfg[:private].should == nil
    end

    it "inherits being public from parent (meta)" do
      @cfg[:meta][:private].should == nil
    end
  end

  describe "autoinherit with config:{} through two parents" do
    before do
      @docs = parse(<<-EOF)
        /** */
        Ext.define("Parent", {
            config: {
                /**
                 * My config.
                 */
                foo: 5
            }
        });
        /** */
        Ext.define("Middle", {
            extend: "Parent",
            config: {
                foo: 7
            }
        });
        /** */
        Ext.define("Child", {
            extend: "Middle",
            config: {
                foo: 10
            }
        });
      EOF
      @cls = @docs["Child"]
      @cfg = @cls[:members][:cfg][0]
    end

    it "inherits docs from parent" do
      @cfg[:doc].should == "My config."
    end

    it "inherits being public from parent" do
      @cfg[:private].should == nil
    end

    it "inherits being public from parent (meta)" do
      @cfg[:meta][:private].should == nil
    end
  end

  describe "autoinherit with config:{} and no parent" do
    before do
      @docs = parse(<<-EOF)
        /** */
        Ext.define("Child", {
            config: {
                foo: 10
            }
        });
      EOF
      @cls = @docs["Child"]
      @cfg = @cls[:members][:cfg][0]
    end

    it "becomes private" do
      @cfg[:private].should == true
    end

    it "becomes private (meta)" do
      @cfg[:meta][:private].should == true
    end
  end