Skip to content

Commit fda20f3

Browse files
committed
Implement @throws as builtin tag.
1 parent 838f3ff commit fda20f3

File tree

6 files changed

+49
-52
lines changed

6 files changed

+49
-52
lines changed

lib/jsduck/class_formatter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def format_member(m)
4848
m[:html_type] = (@include_types && !is_css_tag) ? format_type(m[:type]) : m[:type] if m[:type]
4949
m[:params] = m[:params].map {|p| format_item(p, is_css_tag) } if m[:params]
5050
m[:return] = format_item(m[:return], is_css_tag) if m[:return]
51+
m[:throws] = m[:throws].map {|t| format_item(t, is_css_tag) } if m[:throws]
5152
m[:properties] = m[:properties].map {|b| format_item(b, is_css_tag) } if m[:properties]
5253
m[:html_meta] = format_meta_data(m)
5354
m

lib/jsduck/doc_parser.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ def parse_loop
132132
at_alias
133133
elsif look(/@var\b/)
134134
at_var
135+
elsif look(/@throws\b/)
136+
at_throws
135137
elsif look(/@inheritable\b/)
136138
boolean_at_tag(/@inheritable/, :inheritable)
137139
elsif look(/@accessor\b/)
@@ -276,6 +278,14 @@ def at_var
276278
skip_white
277279
end
278280

281+
# matches @throws {type} ...
282+
def at_throws
283+
match(/@throws/)
284+
add_tag(:throws)
285+
maybe_type
286+
skip_white
287+
end
288+
279289
# matches @type {type} or @type type
280290
#
281291
# The presence of @type implies that we are dealing with property.

lib/jsduck/merger.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def create_method(docs, code)
162162
:doc => detect_doc(docs),
163163
:params => detect_params(:method, doc_map, code),
164164
:return => detect_return(doc_map, name == "constructor" ? "Object" : "undefined"),
165+
:throws => detect_throws(doc_map),
165166
}, doc_map)
166167
end
167168

@@ -477,6 +478,17 @@ def detect_return(doc_map, default_type="undefined")
477478
}
478479
end
479480

481+
def detect_throws(doc_map)
482+
return unless doc_map[:throws]
483+
484+
doc_map[:throws].map do |throws|
485+
{
486+
:type => throws[:type] || "Object",
487+
:doc => throws[:doc] || "",
488+
}
489+
end
490+
end
491+
480492
# Combines :doc-s of most tags
481493
# Ignores tags that have doc comment themselves and subproperty tags
482494
def detect_doc(docs)

lib/jsduck/renderer.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ def render_params_and_return(item)
318318
doc << render_return(ret)
319319
end
320320

321+
if item[:throws]
322+
doc << render_throws(item[:throws])
323+
end
324+
321325
doc
322326
end
323327

@@ -351,6 +355,22 @@ def render_return(ret)
351355
"</ul>",
352356
]
353357
end
358+
359+
def render_throws(throws)
360+
return [
361+
"<h3 class='pa'>Throws</h3>",
362+
"<ul>",
363+
throws.map do |thr|
364+
[
365+
"<li>",
366+
"<span class='pre'>#{thr[:html_type]}</span>",
367+
"<div class='sub-desc'>#{thr[:doc]}</div>",
368+
"</li>",
369+
]
370+
end,
371+
"</ul>",
372+
]
373+
end
354374
end
355375

356376
end

lib/jsduck/tag/throws.rb

Lines changed: 0 additions & 46 deletions
This file was deleted.

spec/aggregator_throws_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def parse(string)
2121
end
2222

2323
it "detects one throws tag" do
24-
@doc[:meta][:throws].length.should == 1
24+
@doc[:throws].length.should == 1
2525
end
2626

2727
it "detects type of exception" do
28-
@doc[:meta][:throws][0][:type].should == "Error"
28+
@doc[:throws][0][:type].should == "Error"
2929
end
3030

3131
it "detects description" do
32-
@doc[:meta][:throws][0][:doc].should == "Some text\non multiple lines."
32+
@doc[:throws][0][:doc].should == "Some text\non multiple lines."
3333
end
3434
end
3535

@@ -44,11 +44,11 @@ def parse(string)
4444
end
4545

4646
it "detects type as Object" do
47-
@doc[:meta][:throws][0][:type].should == "Object"
47+
@doc[:throws][0][:type].should == "Object"
4848
end
4949

5050
it "detects description" do
51-
@doc[:meta][:throws][0][:doc].should == "Some description"
51+
@doc[:throws][0][:doc].should == "Some description"
5252
end
5353
end
5454

@@ -64,7 +64,7 @@ def parse(string)
6464
end
6565

6666
it "detects two throws tags" do
67-
@doc[:meta][:throws].length.should == 2
67+
@doc[:throws].length.should == 2
6868
end
6969
end
7070

0 commit comments

Comments
 (0)