Commit 6bf5167b authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move creation of :files field from File to Merger.

This way the Tag#merge method will have access to both the filename and linenr,
which is useful for error reporting.

Previously the Merger introduced :linenr field, which was largely unused, except
for some tests checking it.  This resulted in exported JSON containing both :linenr
and :files fields - but the latter already has :linenr inside it.  So another good
step towards more consistency.
parent 84463d9b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,13 +12,13 @@ module JsDuck

    # Takes a docset and merges the :comment and :code inside it,
    # producing hash as a result.
    def merge(docset)
    def merge(docset, filename="", linenr=0)
      docs = docset[:comment]
      code = docset[:code]

      h = {
        :tagname => docset[:tagname],
        :linenr => docset[:linenr],
        :files => [{:filename => filename, :linenr => linenr}],
      }

      invoke_merge_in_tags(h, docs, code)
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ module JsDuck
      docset[:comment] = @doc_processor.process(docset[:tagname], docset[:doc_map])
      docset.delete(:doc_map)

      @merger.merge(docset)
      @merger.merge(docset, @filename, docset[:linenr])
    end
  end

+6 −9
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ module JsDuck
        @links = {}

        @docs.map do |docset|
          link(docset[:linenr], docset)
          link(docset)
        end
      end

@@ -75,15 +75,12 @@ module JsDuck

      # Creates two-way link between sourcefile and doc-object.
      # Returns the modified doc-object after done.
      def link(linenr, doc)
      def link(docset)
        file = docset[:files].first
        linenr = file[:linenr]
        @links[linenr] = [] unless @links[linenr]
        file = {
          :filename => @filename,
          :linenr => linenr,
        }
        @links[linenr] << {:doc => doc, :file => file}
        doc[:files] = [file]
        doc
        @links[linenr] << {:doc => docset, :file => file}
        docset
      end

    end
+1 −1
Original line number Diff line number Diff line
@@ -152,7 +152,7 @@ describe JsDuck::Aggregator do
      end

      it "with :linenr field" do
        member[:linenr].should == 6
        member[:files][0][:linenr].should == 6
      end
    end
  end
+4 −5
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@ require "jsduck/merger"

describe JsDuck::Merger do

  def merge(docset)
    return JsDuck::Merger.new.merge(docset)
  def merge(docset, filename="", linenr=0)
    return JsDuck::Merger.new.merge(docset, filename, linenr)
  end

  describe "only name in code" do
@@ -20,8 +20,7 @@ describe JsDuck::Merger do
          :tagname => :property,
          :name => "option",
        },
        :linenr => 15,
      })
      }, "somefile.js", 15)
    end

    it "gets tagname from doc" do
@@ -37,7 +36,7 @@ describe JsDuck::Merger do
      @doc[:name].should == "option"
    end
    it "keeps line number data" do
      @doc[:linenr].should == 15
      @doc[:files][0][:linenr].should == 15
    end
  end