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

Ensure all orphans with @member get their classes created.

There was a conflict with one method looping over array while
other deleting items from it at the same time.

Fixes: #378
parent d38e9ce4
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -156,7 +156,9 @@ module JsDuck
    # Creates classes for orphans that have :owner property defined,
    # and then inserts orphans to these classes.
    def classify_orphans
      @orphans.each do |orph|
      # Clone the orphans array first to avoid problems with
      # #inster_orphan method deleting items from @orphans array.
      @orphans.clone.each do |orph|
        if orph[:owner]
          class_name = orph[:owner]
          if !@classes[class_name]
+23 −0
Original line number Diff line number Diff line
@@ -52,4 +52,27 @@ describe JsDuck::Aggregator do
    end
  end

  def parse_to_classes(string)
    agr = JsDuck::Aggregator.new
    agr.aggregate(JsDuck::Source::File.new(string))
    agr.classify_orphans
    agr.result
  end

  it "creates classes for all orphans with @member defined" do
    classes = parse_to_classes(<<-EOS)
      /**
       * @cfg foo
       * @member FooCls
       */
      /**
       * @cfg bar
       * @member BarCls
       */
    EOS

    classes[0][:name].should == "FooCls"
    classes[1][:name].should == "BarCls"
  end

end