Commit 64f47067 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Remove logging from Subproperties class.

Instead make the #nest method return two values where the list of
warnings is the second value.
parent ce00860a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
require 'jsduck/tag_registry'
require 'jsduck/subproperties'
require 'jsduck/logger'

module JsDuck

@@ -158,7 +159,9 @@ module JsDuck
    end

    def nest_properties(raw_items)
      Subproperties.nest(raw_items, @filename, @linenr)
      items, warnings = Subproperties.nest(raw_items)
      warnings.each {|msg| Logger.warn(:subproperty, msg, @filename, @linenr) }
      items
    end

    def detect_return(doc_map)
+9 −5
Original line number Diff line number Diff line
require 'jsduck/logger'
require 'jsduck/util/singleton'

module JsDuck
@@ -22,10 +21,13 @@ module JsDuck
    #         {:name => "baz"}]},
    #     {:name => "zap"},
    #
    def nest(raw_items, filename, linenr)
    # NOTE: It returns two values: the resulting nested items array
    # and warnings array of :subproperty warnings that should get
    # printed out.
    def nest(raw_items)
      # First item can't be namespaced, if it is ignore the rest.
      if raw_items[0] && raw_items[0][:name] =~ /\./
        return [raw_items[0]]
        return [raw_items[0]], []
      end

      # build name-index of all items
@@ -36,6 +38,7 @@ module JsDuck
      # Otherwise look up the parent of item and add it as the
      # property of that parent.
      items = []
      warnings = []
      raw_items.each do |it|
        if it[:name] =~ /^(.+)\.([^.]+)$/
          it[:name] = $2
@@ -44,13 +47,14 @@ module JsDuck
            parent[:properties] = [] unless parent[:properties]
            parent[:properties] << it
          else
            Logger.warn(:subproperty, "Ignoring subproperty #{$1}.#{$2}, no parent found with name '#{$1}'.", filename, linenr)
            warnings << "Ignoring subproperty #{$1}.#{$2}, no parent found with name '#{$1}'."
          end
        else
          items << it
        end
      end
      items

      return items, warnings
    end

  end