Commit ff720bb2 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Make object properties work with @cfg.

parent 7d7027e1
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -189,7 +189,6 @@ module JsDuck
      match(/@param/)
      add_tag(:param)
      maybe_type
      #maybe_name
      maybe_ident_chain(:name)
      skip_white
    end
@@ -207,7 +206,7 @@ module JsDuck
      match(/@cfg/)
      add_tag(:cfg)
      maybe_type
      maybe_name
      maybe_ident_chain(:name)
      skip_white
    end

+11 −2
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@ module JsDuck
        :owner => detect_owner(doc_map) || owner,
        :type => detect_type(:cfg, doc_map, code),
        :doc => detect_doc(docs),
        :properties => detect_subproperties(docs),
      }, doc_map)
    end

@@ -338,6 +339,10 @@ module JsDuck
      combine_properties(docs.find_all {|tag| tag[:tagname] == :param})
    end

    def detect_subproperties(docs)
      combine_properties(docs.find_all {|tag| tag[:tagname] == :cfg})[0][:properties]
    end

    def combine_properties(raw_items)
      # build name-index of all items
      index = {}
@@ -369,13 +374,17 @@ module JsDuck
    end

    # Combines :doc-s of most tags
    # Ignores tags that have doc comment themselves
    # Ignores tags that have doc comment themselves and subproperty tags
    def detect_doc(docs)
      ignore_tags = [:param, :return]
      doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) }
      doc_tags = docs.find_all { |tag| !ignore_tags.include?(tag[:tagname]) && !subproperty?(tag) }
      doc_tags.map { |tag| tag[:doc] }.compact.join(" ")
    end

    def subproperty?(tag)
      tag[:tagname] == :cfg && tag[:name] =~ /\./
    end

    # Build map of at-tags for quick lookup
    def build_doc_map(docs)
      map = {}
+89 −60
Original line number Diff line number Diff line
@@ -9,49 +9,26 @@ describe JsDuck::Aggregator do
    agr.result
  end

  describe "method parameter with properties" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some function
         * @param {Object} coord Geographical coordinates
         * @param {Object} coord.lat Latitude
         * @param {Number} coord.lat.numerator Numerator part of a fraction
         * @param {Number} coord.lat.denominator Denominator part of a fraction
         * @param {Number} coord.lng Longitude
         */
        function foo(x, y) {}
      EOS
    end

    it "is interpreted as single parameter" do
      @doc[:params].length.should == 1
    end

    describe "single param" do
      before do
        @param = @doc[:params][0]
      end

  shared_examples_for "object with properties" do
    it "has name" do
        @param[:name].should == "coord"
      @obj[:name].should == "coord"
    end

    it "has type" do
        @param[:type].should == "Object"
      @obj[:type].should == "Object"
    end

    it "has doc" do
        @param[:doc].should == "Geographical coordinates"
      @obj[:doc].should == "Geographical coordinates"
    end

    it "contains 2 properties" do
        @param[:properties].length.should == 2
      @obj[:properties].length.should == 2
    end

    describe "first property" do
      before do
          @prop = @param[:properties][0]
        @prop = @obj[:properties][0]
      end

      it "has name without namespace" do
@@ -85,7 +62,7 @@ describe JsDuck::Aggregator do

    describe "second property" do
      before do
          @prop = @param[:properties][1]
        @prop = @obj[:properties][1]
      end

      it "has name without namespace" do
@@ -101,6 +78,58 @@ describe JsDuck::Aggregator do
      end
    end
  end

  describe "method parameter with properties" do
    before do
      @doc = parse(<<-EOS)[0]
        /**
         * Some function
         * @param {Object} coord Geographical coordinates
         * @param {Object} coord.lat Latitude
         * @param {Number} coord.lat.numerator Numerator part of a fraction
         * @param {Number} coord.lat.denominator Denominator part of a fraction
         * @param {Number} coord.lng Longitude
         */
        function foo(x, y) {}
      EOS
    end

    it "is interpreted as single parameter" do
      @doc[:params].length.should == 1
    end

    describe "single param" do
      before do
        @obj = @doc[:params][0]
      end

      it_should_behave_like "object with properties"
    end
  end

  describe "cfg with properties" do
    before do
      @doc = parse(<<-EOS)
        /**
         * @cfg {Object} coord Geographical coordinates
         * @cfg {Object} coord.lat Latitude
         * @cfg {Number} coord.lat.numerator Numerator part of a fraction
         * @cfg {Number} coord.lat.denominator Denominator part of a fraction
         * @cfg {Number} coord.lng Longitude
         */
      EOS
    end

    it "is interpreted as single config" do
      @doc.length.should == 1
    end

    describe "the config" do
      before do
        @obj = @doc[0]
      end

      it_should_behave_like "object with properties"
    end
  end
end