diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index 310f8e2dac799a2b7ebc5cca916a513ebc8cdc26..2c38f66313e466ca35a9fcbcba9a87fe338e6d64 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -246,22 +246,21 @@ module JsDuck def detect_type(tagname, doc_map, code) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:type] - main_tag[:type] + return main_tag[:type] elsif doc_map[:type] - doc_map[:type].first[:type] - elsif code[:type] == :function - "Function" - elsif code[:type] == :assignment && code[:right] - if code[:right][:type] == :function - "Function" - elsif code[:right][:type] == :literal - code[:right][:class] - else - "Object" + return doc_map[:type].first[:type] + elsif code_matches_doc?(tagname, doc_map, code) + if code[:type] == :function + return "Function" + elsif code[:type] == :assignment && code[:right] + if code[:right][:type] == :function + return "Function" + elsif code[:right][:type] == :literal + return code[:right][:class] + end end - else - "Object" end + return "Object" end def detect_extends(doc_map, code) @@ -279,11 +278,19 @@ module JsDuck main_tag = doc_map[tagname] ? doc_map[tagname].first : {} if main_tag[:default] main_tag[:default] - elsif code[:type] == :assignment && code[:right] + elsif code_matches_doc?(tagname, doc_map, code) && code[:type] == :assignment && code[:right] code[:right][:value] end end + # True if the name detected from code matches with explicitly documented name. + # Also true when no explicit name documented. + def code_matches_doc?(tagname, doc_map, code) + explicit_name = detect_name(tagname, doc_map, {}) + implicit_name = detect_name(tagname, {}, code) + return explicit_name == "" || explicit_name == implicit_name + end + def detect_optional(tagname, doc_map) main_tag = doc_map[tagname] ? doc_map[tagname].first : {} return main_tag[:optional] != false diff --git a/spec/aggregator_default_values_spec.rb b/spec/aggregator_default_values_spec.rb index 4146b992e007e4adad3d967ee2e6099bcc5e2326..e85368c413464adfa9a528054b32575705f19273 100644 --- a/spec/aggregator_default_values_spec.rb +++ b/spec/aggregator_default_values_spec.rb @@ -304,6 +304,40 @@ describe JsDuck::Aggregator do end end + describe "cfg with implicit name followed by code field with another name" do + before do + @doc = parse(<<-EOS)[0] + /** + * @cfg foo + */ + bar: true + EOS + end + it "doesn't get the default value from code" do + @doc[:default].should == nil + end + it "doesn't get the type from code" do + @doc[:type].should == "Object" + end + end + + describe "cfg without implicit name followed by code" do + before do + @doc = parse(<<-EOS)[0] + /** + * @cfg + */ + bar: true + EOS + end + it "gets default value from code" do + @doc[:default].should == "true" + end + it "gets the type from code" do + @doc[:type].should == "Boolean" + end + end + describe "a normal config option" do before do @doc = parse(<<-EOS)[0]