Loading lib/jsduck/js/class.rb +9 −1 Original line number Diff line number Diff line Loading @@ -106,7 +106,15 @@ module JsDuck cls[:members] = [] cls[:code_type] = :ext_define ast["arguments"][1].each_property do |key, value, pair| definition_node = ast["arguments"][1] # Support both function and object notation if definition_node.function_expression? definition_node = definition_node.return_statement_expression return if definition_node.nil? end definition_node.each_property do |key, value, pair| if tag = Js::ExtDefine.get_tag_by_pattern(key) tag.parse_ext_define(cls, value) else Loading lib/jsduck/js/node.rb +27 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,33 @@ module JsDuck return nil end # Returns the return statement's expression for the current function # expression. def return_statement_expression return unless function_expression? node = child("body") if node.block_statement? node["body"].each do |node| if node.return_statement? node = node["argument"] return node.object_expression? ? node : nil end end end return nil end def block_statement? @node["type"] == "BlockStatement" end def return_statement? @node["type"] == "ReturnStatement" end # Returns line number in parsed source where the Node resides. def linenr # Get line number from third place at range array. Loading spec/ast_class_spec.rb +31 −1 Original line number Diff line number Diff line Loading @@ -32,13 +32,20 @@ describe "JsDuck::Js::Ast detects class with" do detect("/** */ var MyClass = Ext.extend(Your.Class, { });")[:name].should == "MyClass" end it "Ext.define()" do it "Ext.define() with object literal" do detect(<<-EOS)[:name].should == "MyClass" /** */ Ext.define('MyClass', { }); EOS end it "Ext.define() with function" do detect(<<-EOS)[:name].should == "MyClass" /** */ Ext.define('MyClass', function() {}); EOS end end describe "extends in" do Loading Loading @@ -77,6 +84,29 @@ describe "JsDuck::Js::Ast detects class with" do EOS end it "Ext.define() with function returning object" do detect(<<-EOS)[:extends].should == "Your.Class" /** */ Ext.define('MyClass', function() { return {extend: "Your.Class"}; }); EOS end # TODO: Doesn't work at the moment # # it "Ext.define() with function returning two possible objects" do # detect(<<-EOS)[:extends].should == "Ext.Base" # /** */ # Ext.define('MyClass', function() { # if (someCondition) { # return {extend: "Your.Class1"}; # } # return {extend: "Your.Class2"}; # }); # EOS # end it "Ext.define() with no extend: in config object" do detect(<<-EOS)[:extends].should == "Ext.Base" /** */ Loading Loading
lib/jsduck/js/class.rb +9 −1 Original line number Diff line number Diff line Loading @@ -106,7 +106,15 @@ module JsDuck cls[:members] = [] cls[:code_type] = :ext_define ast["arguments"][1].each_property do |key, value, pair| definition_node = ast["arguments"][1] # Support both function and object notation if definition_node.function_expression? definition_node = definition_node.return_statement_expression return if definition_node.nil? end definition_node.each_property do |key, value, pair| if tag = Js::ExtDefine.get_tag_by_pattern(key) tag.parse_ext_define(cls, value) else Loading
lib/jsduck/js/node.rb +27 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,33 @@ module JsDuck return nil end # Returns the return statement's expression for the current function # expression. def return_statement_expression return unless function_expression? node = child("body") if node.block_statement? node["body"].each do |node| if node.return_statement? node = node["argument"] return node.object_expression? ? node : nil end end end return nil end def block_statement? @node["type"] == "BlockStatement" end def return_statement? @node["type"] == "ReturnStatement" end # Returns line number in parsed source where the Node resides. def linenr # Get line number from third place at range array. Loading
spec/ast_class_spec.rb +31 −1 Original line number Diff line number Diff line Loading @@ -32,13 +32,20 @@ describe "JsDuck::Js::Ast detects class with" do detect("/** */ var MyClass = Ext.extend(Your.Class, { });")[:name].should == "MyClass" end it "Ext.define()" do it "Ext.define() with object literal" do detect(<<-EOS)[:name].should == "MyClass" /** */ Ext.define('MyClass', { }); EOS end it "Ext.define() with function" do detect(<<-EOS)[:name].should == "MyClass" /** */ Ext.define('MyClass', function() {}); EOS end end describe "extends in" do Loading Loading @@ -77,6 +84,29 @@ describe "JsDuck::Js::Ast detects class with" do EOS end it "Ext.define() with function returning object" do detect(<<-EOS)[:extends].should == "Your.Class" /** */ Ext.define('MyClass', function() { return {extend: "Your.Class"}; }); EOS end # TODO: Doesn't work at the moment # # it "Ext.define() with function returning two possible objects" do # detect(<<-EOS)[:extends].should == "Ext.Base" # /** */ # Ext.define('MyClass', function() { # if (someCondition) { # return {extend: "Your.Class1"}; # } # return {extend: "Your.Class2"}; # }); # EOS # end it "Ext.define() with no extend: in config object" do detect(<<-EOS)[:extends].should == "Ext.Base" /** */ Loading