From d765f7414b5090a4a2dd24d9d5576b5327c60696 Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Thu, 6 Oct 2011 14:17:09 +0300 Subject: [PATCH] Support for xtype property in Ext.define. --- lib/jsduck/js_parser.rb | 12 ++++++++++- lib/jsduck/merger.rb | 11 ++++++++-- spec/aggregator_xtypes_spec.rb | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/jsduck/js_parser.rb b/lib/jsduck/js_parser.rb index 1214cfdc..674884b0 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 bbe1bd36..f32f0d96 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 550c04d4..2b6e7370 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] -- GitLab