Commit 1a6efa4c authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Eliminate the complex parameter merging logic.

Stick with the simple: if @param in comment, use that, otherwise
use params auto-detected from code.  This means the auto-merging
takes completely care of that.  So the merge method only needs to
set the defaults and report warnings.

This change eliminates support for the syntax where one defines
variabled types in doc-comment and names in code.  But that's a
very silly syntax anyway as one can't use it when one also wants
to document the variable.  So it's now gone and we have simplified
the code considerably.
parent 54520abf
Loading
Loading
Loading
Loading
+9 −23
Original line number Diff line number Diff line
@@ -32,7 +32,14 @@ module JsDuck::Tag
    end

    def merge(h, docs, code)
      h[:params] = merge_params(docs, code, h[:files].first)
      # Ensure the existance of params array.
      h[:params] = [] unless h[:params]
      # Default type of each parameter to "Object"
      h[:params].each do |p|
        p[:type] = "Object" unless p[:type]
      end

      print_warnings(docs, code, h[:files].first)
    end

    def format(m, formatter)
@@ -45,30 +52,9 @@ module JsDuck::Tag

    private

    def merge_params(docs, code, file)
    def print_warnings(docs, code, file)
      explicit = docs[:params] || []
      implicit = JsDuck::DocsCodeComparer.matches?(docs, code) ? (code[:params] || []) : []
      print_warnings(explicit, implicit, file)

      # Override implicit parameters with explicit ones
      # But if explicit ones exist, don't append the implicit ones.
      params = []
      (explicit.length > 0 ? explicit.length : implicit.length).times do |i|
        im = implicit[i] || {}
        ex = explicit[i] || {}
        params << {
          :type => ex[:type] || im[:type] || "Object",
          :name => ex[:name] || im[:name] || "",
          :doc => ex[:doc] || im[:doc] || "",
          :optional => ex[:optional] || false,
          :default => ex[:default],
          :properties => ex[:properties] || [],
        }
      end
      params
    end

    def print_warnings(explicit, implicit, file)
      ex_len = explicit.length
      im_len = implicit.length

+2 −2
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ describe JsDuck::Aggregator do
      EOS
    end
    it "doesn't make parameter optional" do
      @param[:optional].should == false
      @param[:optional].should_not == true
    end
  end

@@ -76,7 +76,7 @@ describe JsDuck::Aggregator do
      EOS
    end
    it "doesn't make parameter optional" do
      @param[:optional].should == false
      @param[:optional].should_not == true
    end
  end

+6 −1
Original line number Diff line number Diff line
@@ -133,7 +133,12 @@ describe JsDuck::Aggregator do
        function foo(x, y) {}
      EOS
    end
    it_should_behave_like "two parameters"

    it_should_behave_like "parameter types"

    it "detects no parameter names" do
      @doc[0][:name].should == nil
      @doc[1][:name].should == nil
    end
  end
end