Commit 51fdb209 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for auto-detection of inheritableStatics.

parent 05f9cb0a
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -204,6 +204,7 @@ module JsDuck

          statics = []
          statics += make_statics(cfg["statics"])
          statics += make_statics(cfg["inheritableStatics"], {:inheritable => true})
          cls[:statics] = statics.length > 0 ? statics : nil
        end
      end
@@ -282,12 +283,18 @@ module JsDuck
        end

        s[:meta] = {:static => true}
        s.merge!(defaults)

        docset = find_docset(p)
        if docset
          docset[:code] = s
        else
          if defaults[:inheritable]
            s[:inheritdoc] = {}
          else
            s[:private] = true
          end

          s[:autodetected] = true
          s[:linenr] = p["range"][2]
          statics << s
+3 −4
Original line number Diff line number Diff line
@@ -84,10 +84,9 @@ module JsDuck
      # Copy private to meta
      h[:meta][:private] = h[:private] if h[:private]

      # Copy :static flag from code if present
      if code[:meta] && code[:meta][:static]
        h[:meta][:static] = true
      end
      # Copy :static and :inheritable flags from code if present
      h[:meta][:static] = true if code[:meta] && code[:meta][:static]
      h[:inheritable] = true if code[:inheritable]

      # Remember auto-detection info
      h[:autodetected] = code[:autodetected] if code[:autodetected]
+35 −0
Original line number Diff line number Diff line
@@ -164,4 +164,39 @@ describe JsDuck::Aggregator do
    end
  end

  describe "Ext.define() with undocumented method in inheritableStatics:" do
    let(:statics) do
      parse(<<-EOS)[0][:statics]
        /**
         * Some documentation.
         */
        Ext.define("MyClass", {
            inheritableStatics: {
                bar: function() {}
            }
        });
      EOS
    end

    it "auto-detects one static method" do
      statics[:method].length.should == 1
    end

    describe "detects static method" do
      let(:method) { statics[:method][0] }

      it "with :static flag" do
        method[:meta][:static].should == true
      end

      it "with :inheritable flag" do
        method[:inheritable].should == true
      end

      it "with :inheritdoc flag" do
        method[:inheritdoc].should == {}
      end
    end
  end

end