diff --git a/lib/jsduck/js_parser.rb b/lib/jsduck/js_parser.rb index 1214cfdc146e4939d497198de3c39eb21cdfd504..674884b074167b4e1b88143f19fd167a1d5a54ed 100644 --- a/lib/jsduck/js_parser.rb +++ b/lib/jsduck/js_parser.rb @@ -234,7 +234,7 @@ module JsDuck end # := "{" ( | | | | - # | | | )* + # | | | | )* def ext_define_cfg match("{") cfg = {} @@ -249,6 +249,8 @@ module JsDuck cfg[:alternateClassNames] = found elsif found = ext_define_alias cfg[:alias] = found + elsif found = ext_define_xtype + cfg[:xtype] = found elsif found = ext_define_requires cfg[:requires] = found elsif found = ext_define_uses @@ -301,6 +303,14 @@ module JsDuck end end + # := "xtype" ":" + def ext_define_xtype + if look("xtype", ":") + match("xtype", ":") + string_or_list + end + end + # := "requires" ":" def ext_define_requires if look("requires", ":") diff --git a/lib/jsduck/merger.rb b/lib/jsduck/merger.rb index bbe1bd36656c720a976f4d096ff0a6bb6013688f..f32f0d96f346b21a5f2b1cd4bd3b06a9b455369c 100644 --- a/lib/jsduck/merger.rb +++ b/lib/jsduck/merger.rb @@ -320,9 +320,16 @@ module JsDuck def detect_xtypes(doc_map, code) if doc_map[:xtype] {"widget" => doc_map[:xtype].map {|tag| tag[:name] } } - elsif code[:alias] + elsif code[:xtype] || code[:alias] xtypes = {} - code[:alias].each do |a| + (code[:xtype] || []).each do |a| + if xtypes["widget"] + xtypes["widget"] << a + else + xtypes["widget"] = [a] + end + end + (code[:alias] || []).each do |a| if a =~ /^(\w+)\.(\w+)$/ if xtypes[$1] xtypes[$1] << $2 diff --git a/spec/aggregator_xtypes_spec.rb b/spec/aggregator_xtypes_spec.rb index 550c04d40b8e181c2f3051f31607581f5d150da1..2b6e7370344e3f3ccfe597ca15a1898f7e553074 100644 --- a/spec/aggregator_xtypes_spec.rb +++ b/spec/aggregator_xtypes_spec.rb @@ -114,6 +114,43 @@ describe JsDuck::Aggregator do end end + describe "Ext.define() with xtype property" do + before do + @doc = parse(<<-EOS)[0] + /** */ + Ext.define('MyClass', { + xtype: 'foo' + }); + EOS + end + it_should_behave_like "single xtype" + end + + describe "Ext.define() with array xtype property" do + before do + @doc = parse(<<-EOS)[0] + /** */ + Ext.define('MyClass', { + xtype: ['foo', 'bar'] + }); + EOS + end + it_should_behave_like "multiple xtypes" + end + + describe "Ext.define() with both xtype and alias" do + before do + @doc = parse(<<-EOS)[0] + /** */ + Ext.define('MyClass', { + xtype: 'foo', + alias: 'widget.bar' + }); + EOS + end + it_should_behave_like "multiple xtypes" + end + describe "one class many times" do before do @doc = parse(<<-EOS)[0]