Loading lib/jsduck/ast.rb +10 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ module JsDuck cls[:extends] = make_extends(cfg["extend"]) cls[:requires] = make_requires(cfg["requires"]) cls[:uses] = make_requires(cfg["uses"]) cls[:mixins] = make_mixins(cfg["mixins"]) end end Loading @@ -148,6 +149,15 @@ module JsDuck return classes.all? {|c| c.is_a? String } ? classes : [] end def make_mixins(cfg_value) return [] unless cfg_value v = to_value(cfg_value) classes = v.is_a?(Hash) ? v.values : Array(v) return classes.all? {|c| c.is_a? String } ? classes : [] end def object_expression_to_hash(ast) h = {} if ast && ast["type"] == "ObjectExpression" Loading lib/jsduck/evaluator.rb +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,14 @@ module JsDuck case ast["type"] when "ArrayExpression" ast["elements"].map {|e| to_value(e) } when "ObjectExpression" h = {} ast["properties"].each do |p| key = p["key"]["type"] == "Identifier" ? p["key"]["name"] : to_value(p["key"]) value = to_value(p["value"]) h[key] = value end h when "Identifier" ast["name"] when "Literal" Loading spec/ast_class_spec.rb +51 −0 Original line number Diff line number Diff line Loading @@ -158,4 +158,55 @@ describe "JsDuck::Ast detects class with" do EOS end end describe "mixins in" do it "Ext.define() with mixins as string" do detect(<<-EOS)[:mixins].should == ["Some.Class", "Other.Class"] /** */ Ext.define('MyClass', { mixins: ["Some.Class", "Other.Class"] }); EOS end it "Ext.define() with mixins as array of strings" do detect(<<-EOS)[:mixins].should == ["Other.Class"] /** */ Ext.define('MyClass', { mixins: "Other.Class" }); EOS end it "Ext.define() with mixins as object" do detect(<<-EOS)[:mixins].should == ["Some.Class", "Other.Class"] /** */ Ext.define('MyClass', { mixins: { some: "Some.Class", other: "Other.Class" } }); EOS end end describe "no mixins in" do it "Ext.define() without mixins" do detect(<<-EOS)[:mixins].should == [] /** */ Ext.define('MyClass', { }); EOS end it "Ext.define() with mixins as nested object" do detect(<<-EOS)[:mixins].should == [] /** */ Ext.define('MyClass', { mixins: {foo: {bar: "foo"}} }); EOS end end end Loading
lib/jsduck/ast.rb +10 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,7 @@ module JsDuck cls[:extends] = make_extends(cfg["extend"]) cls[:requires] = make_requires(cfg["requires"]) cls[:uses] = make_requires(cfg["uses"]) cls[:mixins] = make_mixins(cfg["mixins"]) end end Loading @@ -148,6 +149,15 @@ module JsDuck return classes.all? {|c| c.is_a? String } ? classes : [] end def make_mixins(cfg_value) return [] unless cfg_value v = to_value(cfg_value) classes = v.is_a?(Hash) ? v.values : Array(v) return classes.all? {|c| c.is_a? String } ? classes : [] end def object_expression_to_hash(ast) h = {} if ast && ast["type"] == "ObjectExpression" Loading
lib/jsduck/evaluator.rb +8 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,14 @@ module JsDuck case ast["type"] when "ArrayExpression" ast["elements"].map {|e| to_value(e) } when "ObjectExpression" h = {} ast["properties"].each do |p| key = p["key"]["type"] == "Identifier" ? p["key"]["name"] : to_value(p["key"]) value = to_value(p["value"]) h[key] = value end h when "Identifier" ast["name"] when "Literal" Loading
spec/ast_class_spec.rb +51 −0 Original line number Diff line number Diff line Loading @@ -158,4 +158,55 @@ describe "JsDuck::Ast detects class with" do EOS end end describe "mixins in" do it "Ext.define() with mixins as string" do detect(<<-EOS)[:mixins].should == ["Some.Class", "Other.Class"] /** */ Ext.define('MyClass', { mixins: ["Some.Class", "Other.Class"] }); EOS end it "Ext.define() with mixins as array of strings" do detect(<<-EOS)[:mixins].should == ["Other.Class"] /** */ Ext.define('MyClass', { mixins: "Other.Class" }); EOS end it "Ext.define() with mixins as object" do detect(<<-EOS)[:mixins].should == ["Some.Class", "Other.Class"] /** */ Ext.define('MyClass', { mixins: { some: "Some.Class", other: "Other.Class" } }); EOS end end describe "no mixins in" do it "Ext.define() without mixins" do detect(<<-EOS)[:mixins].should == [] /** */ Ext.define('MyClass', { }); EOS end it "Ext.define() with mixins as nested object" do detect(<<-EOS)[:mixins].should == [] /** */ Ext.define('MyClass', { mixins: {foo: {bar: "foo"}} }); EOS end end end