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

Only auto-merge fields that aren't merged explicitly.

This solves the problem of @method getting an auto-detected :default
field which doesn't make sense for methods.
parent 76dcf0e7
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -45,14 +45,32 @@ module JsDuck
    def general_merge(h, docs, code)
      # Merge in all items in docs that don't occour already in result.
      docs.each_pair do |key, value|
        h[key] = value unless h.has_key?(key)
        h[key] = value unless h.has_key?(key) || Merger::explicit?(key)
      end
      # Then add all in the items from code not already in result.
      code.each_pair do |key, value|
        h[key] = value unless h.has_key?(key)
        h[key] = value unless h.has_key?(key) || Merger::explicit?(key)
      end
    end

    # True when given key gets merged explicitly and should therefore
    # be skipped when auto-merging.
    def self.explicit?(key)
      @explicit = explictly_merged_fields unless @explicit
      @explicit[key]
    end

    # Generates a lookup-hash of tagnames which are explicitly merged.
    def self.explictly_merged_fields
      mergers = {}
      member_types = TagRegistry.member_type_names + [:class]
      tags = member_types.map {|type| TagRegistry.mergers(type) }.flatten.uniq
      tags.each do |tag|
        mergers[tag.tagname] = true
      end
      mergers
    end

  end

end
+1 −1
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ module JsDuck
      expand_merger(:member)
      expand_merger(:method_like)
      expand_merger(:property_like)
      @mergers_expanded
      @mergers_expanded = true
    end

    def expand_merger(type_name)
+18 −0
Original line number Diff line number Diff line
@@ -495,4 +495,22 @@ describe JsDuck::Aggregator do
    end
  end

  describe "auto-detected property turned into @method" do
    before do
      @doc = parse_member(<<-EOS)
      ({/**
         * @method
         * My method.
         */
        bar: true })
      EOS
    end
    it "loses the auto-detected default value" do
      @doc[:default].should == nil
    end
    it "loses the auto-detected type" do
      @doc[:type].should == nil
    end
  end

end