Commit 47261b3b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Don't auto-merge code when names don't match.

Move name-detection to merger class and get rid of Tag::Name class
completely.
parent cc10d44d
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
require 'jsduck/class'
require 'jsduck/tag_registry'
require 'jsduck/docs_code_comparer'

module JsDuck

@@ -18,6 +19,7 @@ module JsDuck

      h = {
        :tagname => docset[:tagname],
        :name => docs[:name] || code[:name] || "",
        :files => [{:filename => filename, :linenr => linenr}],
      }

@@ -48,15 +50,19 @@ module JsDuck

    # Applies default merge algorithm to the rest of the data.
    def general_merge(h, docs, code)
      # Merge in all items in docs that don't occour already in result.
      # Add all items in docs not already in result.
      docs.each_pair do |key, value|
        h[key] = value unless h.has_key?(key) || Merger::explicit?(key)
      end
      # Then add all in the items from code not already in result.

      # Add all items in code not already in result.
      # But only if the explicit and auto-detected names don't conflict.
      if DocsCodeComparer.matches?(docs, code)
        code.each_pair do |key, value|
          h[key] = value unless h.has_key?(key) || Merger::explicit?(key)
        end
      end
    end

    # True when given key gets merged explicitly and should therefore
    # be skipped when auto-merging.

lib/jsduck/tag/name.rb

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
require "jsduck/tag/tag"

module JsDuck::Tag
  # There is no @name tag.
  #
  # The :name field is generated by several tags like @class, @method,
  # @cfg, ...
  #
  # This class exists to take care of the merging of :name field.
  class Name < Tag
    def initialize
      @merge_context = [:class, :member]
    end

    # When docs contains :name, it's taken from there.
    # When code contains :name, it's taken from there.
    # When neither, defaults to empty string.
    def merge(h, docs, code)
      if docs[:name]
        h[:name] = docs[:name]
      elsif code[:name]
        h[:name] = code[:name]
      else
        h[:name] = ""
      end
    end
  end
end
+16 −0
Original line number Diff line number Diff line
@@ -286,4 +286,20 @@ describe JsDuck::Aggregator do
      cls[:members][0][:return][:type].should == "OtherClass"
    end
  end

  describe "different implicit and explicit method names" do
    let(:cls) do
      parse(<<-EOS)["MyClass"]
        /** @class MyClass */
        /** @method foo */
        function bar() {
            return this;
        }
      EOS
    end

    it "doesn't detect chainable from code" do
      cls[:members][0][:chainable].should_not == true
    end
  end
end