From c31195ad42929848d1e8a676dc8b18b0cb4db97e Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Tue, 26 Jul 2011 16:14:59 +0300 Subject: [PATCH] Make object properties work with @property. --- lib/jsduck/doc_parser.rb | 2 +- lib/jsduck/merger.rb | 10 +++++---- spec/aggregator_object_properties_spec.rb | 26 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/jsduck/doc_parser.rb b/lib/jsduck/doc_parser.rb index 4791b104..1ff74916 100644 --- a/lib/jsduck/doc_parser.rb +++ b/lib/jsduck/doc_parser.rb @@ -220,7 +220,7 @@ module JsDuck match(/@property/) add_tag(:property) maybe_type - maybe_name + maybe_ident_chain(:name) skip_white end diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index 6dbf44e0..4df308bf 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -164,7 +164,7 @@ module JsDuck :owner => detect_owner(doc_map) || owner, :type => detect_type(:cfg, doc_map, code), :doc => detect_doc(docs), - :properties => detect_subproperties(docs), + :properties => detect_subproperties(docs, :cfg), }, doc_map) end @@ -176,6 +176,7 @@ module JsDuck :owner => detect_owner(doc_map), :type => detect_type(:property, doc_map, code), :doc => detect_doc(docs), + :properties => detect_subproperties(docs, :property), }, doc_map) end @@ -339,8 +340,9 @@ module JsDuck combine_properties(docs.find_all {|tag| tag[:tagname] == :param}) end - def detect_subproperties(docs) - combine_properties(docs.find_all {|tag| tag[:tagname] == :cfg})[0][:properties] + def detect_subproperties(docs, tagname) + prop_docs = docs.find_all {|tag| tag[:tagname] == tagname} + prop_docs.length > 0 ? combine_properties(prop_docs)[0][:properties] : [] end def combine_properties(raw_items) @@ -382,7 +384,7 @@ module JsDuck end def subproperty?(tag) - tag[:tagname] == :cfg && tag[:name] =~ /\./ + (tag[:tagname] == :cfg || tag[:tagname] == :property) && tag[:name] =~ /\./ end # Build map of at-tags for quick lookup diff --git a/spec/aggregator_object_properties_spec.rb b/spec/aggregator_object_properties_spec.rb index 6913b3a8..d599b137 100644 --- a/spec/aggregator_object_properties_spec.rb +++ b/spec/aggregator_object_properties_spec.rb @@ -132,4 +132,30 @@ describe JsDuck::Aggregator do it_should_behave_like "object with properties" end end + + describe "property with properties" do + before do + @doc = parse(<<-EOS) + /** + * @property {Object} coord Geographical coordinates + * @property {Object} coord.lat Latitude + * @property {Number} coord.lat.numerator Numerator part of a fraction + * @property {Number} coord.lat.denominator Denominator part of a fraction + * @property {Number} coord.lng Longitude + */ + EOS + end + + it "is interpreted as single property" do + @doc.length.should == 1 + end + + describe "the property" do + before do + @obj = @doc[0] + end + + it_should_behave_like "object with properties" + end + end end -- GitLab