diff --git a/lib/jsduck/class_formatter.rb b/lib/jsduck/class_formatter.rb index 6b3d8cc55391290194a9f79e87ae894f6bb7e973..43c5e310f07ca900cb725173b15f803f2dc06b8e 100644 --- a/lib/jsduck/class_formatter.rb +++ b/lib/jsduck/class_formatter.rb @@ -48,6 +48,7 @@ module JsDuck m[:html_type] = (@include_types && !is_css_tag) ? format_type(m[:type]) : m[:type] if m[:type] m[:params] = m[:params].map {|p| format_item(p, is_css_tag) } if m[:params] m[:return] = format_item(m[:return], is_css_tag) if m[:return] + m[:throws] = m[:throws].map {|t| format_item(t, is_css_tag) } if m[:throws] m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties] m[:html_meta] = format_meta_data(m) m diff --git a/lib/jsduck/doc_parser.rb b/lib/jsduck/doc_parser.rb index 5a639ee1ce4b5124b725805801ea9da36c100f91..1e9c6e3805a9d417cc3fe0aa281af0d7f33b35c1 100644 --- a/lib/jsduck/doc_parser.rb +++ b/lib/jsduck/doc_parser.rb @@ -132,6 +132,8 @@ module JsDuck at_alias elsif look(/@var\b/) at_var + elsif look(/@throws\b/) + at_throws elsif look(/@inheritable\b/) boolean_at_tag(/@inheritable/, :inheritable) elsif look(/@accessor\b/) @@ -276,6 +278,14 @@ module JsDuck skip_white end + # matches @throws {type} ... + def at_throws + match(/@throws/) + add_tag(:throws) + maybe_type + skip_white + end + # matches @type {type} or @type type # # The presence of @type implies that we are dealing with property. diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index 999107ab1258ccb20670ca419ef91a723c3cc9e5..ac54bc2e85a4527ff8bf9d4d55de007efd2875cc 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -162,6 +162,7 @@ module JsDuck :doc => detect_doc(docs), :params => detect_params(:method, doc_map, code), :return => detect_return(doc_map, name == "constructor" ? "Object" : "undefined"), + :throws => detect_throws(doc_map), }, doc_map) end @@ -477,6 +478,17 @@ module JsDuck } end + def detect_throws(doc_map) + return unless doc_map[:throws] + + doc_map[:throws].map do |throws| + { + :type => throws[:type] || "Object", + :doc => throws[:doc] || "", + } + end + end + # Combines :doc-s of most tags # Ignores tags that have doc comment themselves and subproperty tags def detect_doc(docs) diff --git a/lib/jsduck/renderer.rb b/lib/jsduck/renderer.rb index f0ea108bc47e9dffbf206fbc34eeb033ccccc444..844d84a68bfdf1d7d1b543e8271c40ec34b6cff2 100644 --- a/lib/jsduck/renderer.rb +++ b/lib/jsduck/renderer.rb @@ -318,6 +318,10 @@ module JsDuck doc << render_return(ret) end + if item[:throws] + doc << render_throws(item[:throws]) + end + doc end @@ -351,6 +355,22 @@ module JsDuck "", ] end + + def render_throws(throws) + return [ + "
#{throws[:doc]}
-