Loading lib/jsduck/ast.rb +14 −2 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ module JsDuck cls[:singleton] = make_singleton(cfg["singleton"]) cls[:aliases] = make_string_list(cfg["alias"]) cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype } cls[:members] = {} cls[:members][:cfg] = make_config(cfg["config"]) end end Loading Loading @@ -202,6 +204,16 @@ module JsDuck cfg_value && to_value(cfg_value) == true end def make_config(ast) return nil unless ast && ast["type"] == "ObjectExpression" configs = [] object_expression_to_hash(ast).each_pair do |key, value| configs << make_property(key, value, :cfg) end configs end def make_method(name, ast=nil) return { :tagname => :method, Loading @@ -218,9 +230,9 @@ module JsDuck end end def make_property(name=nil, ast=nil) def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => :property, :tagname => tagname, :name => name, :type => make_value_type(ast), :default => make_default(ast), Loading spec/ast_cfg_spec.rb 0 → 100644 +47 −0 Original line number Diff line number Diff line require "jsduck/ast" require "jsduck/esprima_parser" describe "JsDuck::Ast detecting" do def detect(string) node = JsDuck::EsprimaParser.new(string).parse[0] return JsDuck::Ast.new.detect(node[:code]) end describe "Ext.define()" do let (:members) do detect(<<-EOS)[:members] /** */ Ext.define('MyClass', { config: { foo: true, bar: 5 } }); EOS end it "adds :members as hash" do members.should be_kind_of(Hash) end let(:cfg) { members[:cfg] } it "finds :cfg as array" do cfg.should be_kind_of(Array) end it "finds two cfgs with :cfg tagname" do cfg[0][:tagname].should == :cfg cfg[1][:tagname].should == :cfg end it "finds cfg foo" do cfg[0][:name].should == "foo" end it "finds cfg bar" do cfg[1][:name].should == "bar" end end end Loading
lib/jsduck/ast.rb +14 −2 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ module JsDuck cls[:singleton] = make_singleton(cfg["singleton"]) cls[:aliases] = make_string_list(cfg["alias"]) cls[:aliases] += make_string_list(cfg["xtype"]).map {|xtype| "widget."+xtype } cls[:members] = {} cls[:members][:cfg] = make_config(cfg["config"]) end end Loading Loading @@ -202,6 +204,16 @@ module JsDuck cfg_value && to_value(cfg_value) == true end def make_config(ast) return nil unless ast && ast["type"] == "ObjectExpression" configs = [] object_expression_to_hash(ast).each_pair do |key, value| configs << make_property(key, value, :cfg) end configs end def make_method(name, ast=nil) return { :tagname => :method, Loading @@ -218,9 +230,9 @@ module JsDuck end end def make_property(name=nil, ast=nil) def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => :property, :tagname => tagname, :name => name, :type => make_value_type(ast), :default => make_default(ast), Loading
spec/ast_cfg_spec.rb 0 → 100644 +47 −0 Original line number Diff line number Diff line require "jsduck/ast" require "jsduck/esprima_parser" describe "JsDuck::Ast detecting" do def detect(string) node = JsDuck::EsprimaParser.new(string).parse[0] return JsDuck::Ast.new.detect(node[:code]) end describe "Ext.define()" do let (:members) do detect(<<-EOS)[:members] /** */ Ext.define('MyClass', { config: { foo: true, bar: 5 } }); EOS end it "adds :members as hash" do members.should be_kind_of(Hash) end let(:cfg) { members[:cfg] } it "finds :cfg as array" do cfg.should be_kind_of(Array) end it "finds two cfgs with :cfg tagname" do cfg[0][:tagname].should == :cfg cfg[1][:tagname].should == :cfg end it "finds cfg foo" do cfg[0][:name].should == "foo" end it "finds cfg bar" do cfg[1][:name].should == "bar" end end end