Loading lib/jsduck/class.rb +9 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ module JsDuck # When parent and child have members with same name, # member from child overrides tha parent member. def members_hash(type, context=:members) # Singletons have no static members if @doc[:singleton] && context == :statics # Warn if singleton has static members if @doc[context][type].length > 0 Logger.instance.warn("Singleton class #{@doc[:name]} can't have static members, remove the @static tag.") end return {} end all_members = parent ? parent.members_hash(type, context) : {} mixins.each do |mix| Loading spec/class_spec.rb +40 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,15 @@ describe JsDuck::Class do }); @classes["ChildClass"] = @child @child.relations = @classes @singletonChild = JsDuck::Class.new({ :name => "Singleton", :extends => "ParentClass", :mixins => ["MixinClass"], :singleton => true, }); @classes["Singleton"] = @singletonChild @singletonChild.relations = @classes end it "returns constructor as first method" do Loading Loading @@ -113,6 +122,21 @@ describe JsDuck::Class do it "overrides parent class members with the same name" do @members["foo"][:owner].should == "ChildClass" end describe "singleton class" do before do @members = @singletonChild.members_hash(:method) end it "inherits all instance members from parent" do @members.should have_key("baz") @members.should have_key("foo") end it "inherites all instace members from mixins" do @members.should have_key("xxx") end end end describe "(:method, :statics)" do Loading Loading @@ -143,6 +167,22 @@ describe JsDuck::Class do it "inherits inheritableStatics from mixins" do @members.should have_key("mixinB") end describe "singleton class" do before do @members = @singletonChild.members_hash(:method, :statics) end it "doesn't inherit any static members from parent" do @members.should_not have_key("parentA") @members.should_not have_key("parentB") end it "doesn't inherit any static members from mixins" do @members.should_not have_key("mixinA") @members.should_not have_key("mixinB") end end end end Loading Loading
lib/jsduck/class.rb +9 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ module JsDuck # When parent and child have members with same name, # member from child overrides tha parent member. def members_hash(type, context=:members) # Singletons have no static members if @doc[:singleton] && context == :statics # Warn if singleton has static members if @doc[context][type].length > 0 Logger.instance.warn("Singleton class #{@doc[:name]} can't have static members, remove the @static tag.") end return {} end all_members = parent ? parent.members_hash(type, context) : {} mixins.each do |mix| Loading
spec/class_spec.rb +40 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,15 @@ describe JsDuck::Class do }); @classes["ChildClass"] = @child @child.relations = @classes @singletonChild = JsDuck::Class.new({ :name => "Singleton", :extends => "ParentClass", :mixins => ["MixinClass"], :singleton => true, }); @classes["Singleton"] = @singletonChild @singletonChild.relations = @classes end it "returns constructor as first method" do Loading Loading @@ -113,6 +122,21 @@ describe JsDuck::Class do it "overrides parent class members with the same name" do @members["foo"][:owner].should == "ChildClass" end describe "singleton class" do before do @members = @singletonChild.members_hash(:method) end it "inherits all instance members from parent" do @members.should have_key("baz") @members.should have_key("foo") end it "inherites all instace members from mixins" do @members.should have_key("xxx") end end end describe "(:method, :statics)" do Loading Loading @@ -143,6 +167,22 @@ describe JsDuck::Class do it "inherits inheritableStatics from mixins" do @members.should have_key("mixinB") end describe "singleton class" do before do @members = @singletonChild.members_hash(:method, :statics) end it "doesn't inherit any static members from parent" do @members.should_not have_key("parentA") @members.should_not have_key("parentB") end it "doesn't inherit any static members from mixins" do @members.should_not have_key("mixinA") @members.should_not have_key("mixinB") end end end end Loading