Commit 0100fc9e authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Process @return subproperties inside Tag::Return.

The :return field in the final hash will now be nil when no @return
tags was encountered - no more will it default to "undefined" type.
parent e8e78fbb
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ module JsDuck
        return add_shared({
            :tagname => :method,
            :doc => detect_doc(:method, doc_map),
            :return => detect_return(doc_map),
          }, doc_map)
      end

@@ -152,17 +151,6 @@ module JsDuck
        items
      end

      def detect_return(doc_map)
        has_return_tag = !!extract(doc_map, :return)
        ret = extract(doc_map, :return) || {}
        return {
          :type => ret[:type] || (has_return_tag ? "Object" : "undefined"),
          :name => ret[:name] || "return",
          :doc => ret[:doc] || "",
          :properties => doc_map[:return] ? detect_subproperties(:return, doc_map[:return]) : []
        }
      end

      # Returns documentation for class or member.
      def detect_doc(tagname, doc_map)
        doc = extract(doc_map, :doc, :doc) || ""
+6 −3
Original line number Diff line number Diff line
@@ -50,17 +50,20 @@ module JsDuck
      end

      def add_return_this(m)
        if m[:return][:type] == "undefined" && m[:return][:doc] == ""
        if m[:return] == nil
          m[:return] = {:type => @cls[:name], :doc => "this"}
        end
      end

      def add_return_new(m)
        if m[:return][:type] == "undefined" || m[:return][:type] == "Object"
        if m[:return] == nil || m[:return][:type] == "Object"
          # Create a whole new :return hash.
          # If we were to just change the :type field it would modify
          # the type of all the inherited constructor docs.
          m[:return] = {:type => @cls[:name], :doc => m[:return][:doc]}
          m[:return] = {
            :type => @cls[:name],
            :doc => m[:return] ? m[:return][:doc] : "",
          }
        end
      end
    end
+0 −1
Original line number Diff line number Diff line
@@ -326,7 +326,6 @@ module JsDuck
    end

    def render_return(ret)
      return if ret[:type] == "undefined"
      return [
        "<h3 class='pa'>Returns</h3>",
        "<ul>",
+1 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ module JsDuck
    end

    def method_with_return?
      @m[:tagname] == :method && @m[:return][:type] != "undefined"
      @m[:tagname] == :method && @m[:return] != nil
    end

    def render_tag_signature
+18 −0
Original line number Diff line number Diff line
require "jsduck/tag/tag"
require "jsduck/doc/subproperties"

module JsDuck::Tag
  class Return < Tag
    def initialize
      @pattern = ["return", "returns"]
      @key = :return
    end

    # @return {Type} return.name ...
@@ -21,5 +23,21 @@ module JsDuck::Tag
        "return"
      end
    end

    def process_doc(h, tags, pos)
      ret = tags[0]
      h[:return] = {
        :type => ret[:type] || "Object",
        :name => ret[:name] || "return",
        :doc => ret[:doc] || "",
        :properties => nest_properties(tags, pos)[0][:properties]
      }
    end

    def nest_properties(tags, pos)
      items, warnings = JsDuck::Doc::Subproperties.nest(tags)
      warnings.each {|msg| JsDuck::Logger.warn(:subproperty, msg, pos[:filename], pos[:linenr]) }
      items
    end
  end
end
Loading