Commit 449c2053 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Don't hide static members for singleton classes.

Although singleton classes shouldn't have its members marked as
static, excluding them completely from the docs isn't the right thing to
do.
parent cf9c2b46
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -120,13 +120,28 @@ module JsDuck
        all_members.delete_if {|key, member| !member[:inheritable] }
      end

      (@doc[context][type] || []).each do |m|
        all_members[m[:name]] = m if !m[:private]
      all_members.merge!(local_members_hash(type, context))

      # If singleton has static members, include them as if they were
      # instance members.  Otherwise they will be completely excluded
      # from the docs, as the static members block is not created for
      # singletons.
      if @doc[:singleton] && @doc[:statics][type].length > 0
        all_members.merge!(local_members_hash(type, :statics))
      end

      all_members
    end

    # Helper method to get the direct members of this class
    def local_members_hash(type, context)
      local_members = {}
      (@doc[context][type] || []).each do |m|
        local_members[m[:name]] = m if !m[:private]
      end
      local_members
    end

    # Returns member by name.
    #
    # Optionally one can also specify type name to differenciate
+29 −1
Original line number Diff line number Diff line
@@ -2,6 +2,12 @@ require "jsduck/class"

describe JsDuck::Class do

  # Avoid printed warnings in output
  class JsDuck::Logger
    def warn(msg)
    end
  end

  describe "#members" do

    before do
@@ -70,6 +76,16 @@ describe JsDuck::Class do
          :extends => "ParentClass",
          :mixins => ["MixinClass"],
          :singleton => true,
          :members => {
            :method => [
              {:name => "sing", :owner => "Singleton"},
            ]
          },
          :statics => {
            :method => [
              {:name => "singStat", :owner => "Singleton"},
            ]
          }
        });
      @classes["Singleton"] = @singletonChild
      @singletonChild.relations = @classes
@@ -133,9 +149,17 @@ describe JsDuck::Class do
          @members.should have_key("foo")
        end

        it "inherites all instace members from mixins" do
        it "inherits all instace members from mixins" do
          @members.should have_key("xxx")
        end

        it "lists its instance members" do
          @members.should have_key("sing")
        end

        it "lists its static members as if they were instance members" do
          @members.should have_key("singStat")
        end
      end
    end

@@ -182,6 +206,10 @@ describe JsDuck::Class do
          @members.should_not have_key("mixinA")
          @members.should_not have_key("mixinB")
        end

        it "doesn't list any of his own static members" do
          @members.should_not have_key("singStat")
        end
      end
    end
  end