Commit 9b445087 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add @inheritdoc tag to autodetected configs.

But add a special :no_warnings flag so the InheritDoc class won't throw
warnings when it founds nothing to inherit from.
parent abfab627
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -196,7 +196,7 @@ module JsDuck
          cls[:aliases] = make_string_list(cfg["alias"])
          cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype }
          cls[:members] = {}
          cls[:members][:cfg] = make_config(cfg["config"])
          cls[:members][:cfg] = make_configs(cfg["config"])
        end
      end

@@ -232,7 +232,7 @@ module JsDuck
      cfg_value && to_value(cfg_value) == true
    end

    def make_config(ast)
    def make_configs(ast)
      return nil unless ast && ast["type"] == "ObjectExpression"

      configs = []
@@ -245,6 +245,7 @@ module JsDuck
        if docset
          docset[:code] = cfg
        else
          cfg[:inheritdoc] = {:no_warnings => true}
          configs << cfg
        end
      end
+8 −2
Original line number Diff line number Diff line
@@ -53,7 +53,10 @@ module JsDuck
        mixins = @relations[m[:owner]].mixins

        # Warn when no parent or mixins at all
        return warn("parent class not found", m) unless parent_cls || mixins.length > 0
        if !parent_cls && mixins.length == 0
          warn("parent class not found", m) unless m[:no_warnings]
          return m
        end

        # First check for the member in all mixins, because members
        # from mixins override those from parent class.  Looking first
@@ -69,7 +72,10 @@ module JsDuck
        end

        # Only when both parent and mixins fail, throw warning
        return warn("parent member not found", m) unless parent
        if !parent
          warn("parent member not found", m) unless m[:no_warnings]
          return m
        end
      end

      return parent[:inheritdoc] ? find_parent(parent) : parent
+3 −3
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ module JsDuck
        :properties => detect_subproperties(docs, :cfg),
        :accessor => !!doc_map[:accessor],
        :evented => !!doc_map[:evented],
      }, doc_map)
      }, doc_map, code)
    end

    def create_property(docs, code)
@@ -189,10 +189,10 @@ module JsDuck
    end

    # Detects properties common for each doc-object and adds them
    def add_shared(hash, doc_map)
    def add_shared(hash, doc_map, code={})
      hash.merge!({
        :inheritable => !!doc_map[:inheritable],
        :inheritdoc => doc_map[:inheritdoc] ? doc_map[:inheritdoc].first : nil,
        :inheritdoc => doc_map[:inheritdoc] ? doc_map[:inheritdoc].first : code[:inheritdoc],
        :meta => detect_meta(doc_map),
      })
      # copy :private also to main hash
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ describe JsDuck::Aggregator do
    it "finds two configs" do
      cfg.length.should == 2
    end

    it "sets :inheritdoc flag on config" do
      cfg[0][:inheritdoc].should == {:no_warnings => true}
    end
  end

  describe "detecting Ext.define() with commented config" do
+28 −0
Original line number Diff line number Diff line
@@ -525,5 +525,33 @@ describe JsDuck::Aggregator do
    end
  end

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

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

end