Commit 94cdbc4f authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for @inheritable for static members.

Only static members marked with @inheritable will be inherited.
parent 833ca9b9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -100,6 +100,11 @@ module JsDuck
        all_members.merge!(mix.members_hash(type, context))
      end

      # For static members, exclude everything not explicitly marked as inheritable
      if context == :statics
        all_members.delete_if {|key, member| !member[:inheritable] }
      end

      (@doc[context][type] || []).each do |m|
        all_members[m[:name]] = m if !m[:private]
      end
+2 −0
Original line number Diff line number Diff line
@@ -113,6 +113,8 @@ module JsDuck
          at_var
        elsif look(/@static\b/)
          boolean_at_tag(/@static/, :static)
        elsif look(/@inheritable\b/)
          boolean_at_tag(/@inheritable/, :inheritable)
        elsif look(/@(private|ignore|hide)\b/)
          boolean_at_tag(/@(private|ignore|hide)/, :private)
        elsif look(/@protected\b/)
+1 −0
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ module JsDuck
        :private => !!doc_map[:private],
        :protected => !!doc_map[:protected],
        :static => !!doc_map[:static],
        :inheritable => !!doc_map[:inheritable],
        :deprecated => detect_deprecated(doc_map),
        :alias => doc_map[:alias] ? doc_map[:alias].first : nil,
      })
+26 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ describe JsDuck::Aggregator do
    agr.result
  end

  describe "@static on single method" do
  describe "normal @static on single method" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
@@ -23,6 +23,31 @@ describe JsDuck::Aggregator do
    it "labels that method as static" do
      @doc[:static].should == true
    end

    it "doesn't detect inheritable property" do
      @doc[:inheritable].should_not == true
    end
  end

  describe "@static with @inheritable" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some function
         * @static
         * @inheritable
         */
        function bar() {}
      EOS
    end

    it "labels that method as static" do
      @doc[:static].should == true
    end

    it "detects the @inheritable property" do
      @doc[:inheritable].should == true
    end
  end

  describe "@static in class context" do
+71 −0
Original line number Diff line number Diff line
@@ -88,6 +88,77 @@ describe JsDuck::Class do
    end
  end

  describe "#members(:statics)" do

    before do
      @classes = {}
      @parent = JsDuck::Class.new({
          :name => "ParentClass",
          :statics => {
            :method => [
              {:name => "parentA", :owner => "ParentClass"},
              {:name => "parentB", :owner => "ParentClass", :inheritable => true},
            ]
          }
        });
      @classes["ParentClass"] = @parent
      @parent.relations = @classes

      @mixin = JsDuck::Class.new({
          :name => "MixinClass",
          :statics => {
            :method => [
              {:name => "mixinA", :owner => "MixinClass"},
              {:name => "mixinB", :owner => "MixinClass", :inheritable => true},
            ]
          }
        });
      @classes["MixinClass"] = @mixin
      @mixin.relations = @classes

      @child = JsDuck::Class.new({
          :name => "ChildClass",
          :extends => "ParentClass",
          :mixins => ["MixinClass"],
          :statics => {
            :method => [
              {:name => "childA", :owner => "ChildClass"},
              {:name => "childB", :owner => "ChildClass", :inheritable => true},
            ]
          }
        });
      @classes["ChildClass"] = @child
      @child.relations = @classes

      @members = @child.members_hash(:method, :statics)
    end

    it "returns normal statics in current class" do
      @members.should have_key("childA")
    end

    it "returns inheritableStatics in current class" do
      @members.should have_key("childB")
    end

    it "doesn't inherit normal statics from parent class" do
      @members.should_not have_key("parentA")
    end

    it "inherits inheritableStatics from parent class" do
      @members.should have_key("parentB")
    end

    it "doesn't inherit normal statics from mixins" do
      @members.should_not have_key("mixinA")
    end

    it "inherits inheritableStatics from mixins" do
      @members.should have_key("mixinB")
    end

  end

  describe "#members(:method)" do
    before do
      @classes = {}