Loading lib/jsduck/doc_type.rb +11 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,8 @@ module JsDuck :method elsif var && function?(var["init"]) :method elsif property?(ast) && function?(ast["value"]) :method elsif doc_map[:return] || doc_map[:param] :method else Loading Loading @@ -75,13 +77,21 @@ module JsDuck end def function?(ast) ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" || empty_fn?(ast) end def empty_fn?(ast) ast["type"] == "MemberExpression" && to_s(ast) == "Ext.emptyFn" end def var?(ast) ast["type"] == "VariableDeclaration" end def property?(ast) ast["type"] == "Property" end # Class name begins with upcase char def class_name?(ast) return to_s(ast).split(/\./).last =~ /\A[A-Z]/ Loading spec/doc_type_spec.rb +36 −0 Original line number Diff line number Diff line Loading @@ -79,9 +79,45 @@ describe JsDuck::DocType do detect("/** */ foo = function() {}").should == :method end it "assignment of Ext.emptyFn" do detect("/** */ foo = Ext.emptyFn").should == :method end it "var initialized with function" do detect("/** */ var foo = function() {}").should == :method end it "vari initialized with Ext.emptyFn" do detect("/** */ var foo = Ext.emptyFn").should == :method end it "object property initialized with function" do detect(<<-EOS).should == :method Foo = { /** */ bar: function(){} }; EOS end it "object property in comma-first notation initialized with function" do detect(<<-EOS).should == :method Foo = { foo: 5 /** */ , bar: function(){} }; EOS end it "object property initialized with Ext.emptyFn" do detect(<<-EOS).should == :method Foo = { /** */ bar: Ext.emptyFn }; EOS end end describe "detects as event" do Loading Loading
lib/jsduck/doc_type.rb +11 −1 Original line number Diff line number Diff line Loading @@ -48,6 +48,8 @@ module JsDuck :method elsif var && function?(var["init"]) :method elsif property?(ast) && function?(ast["value"]) :method elsif doc_map[:return] || doc_map[:param] :method else Loading Loading @@ -75,13 +77,21 @@ module JsDuck end def function?(ast) ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" || empty_fn?(ast) end def empty_fn?(ast) ast["type"] == "MemberExpression" && to_s(ast) == "Ext.emptyFn" end def var?(ast) ast["type"] == "VariableDeclaration" end def property?(ast) ast["type"] == "Property" end # Class name begins with upcase char def class_name?(ast) return to_s(ast).split(/\./).last =~ /\A[A-Z]/ Loading
spec/doc_type_spec.rb +36 −0 Original line number Diff line number Diff line Loading @@ -79,9 +79,45 @@ describe JsDuck::DocType do detect("/** */ foo = function() {}").should == :method end it "assignment of Ext.emptyFn" do detect("/** */ foo = Ext.emptyFn").should == :method end it "var initialized with function" do detect("/** */ var foo = function() {}").should == :method end it "vari initialized with Ext.emptyFn" do detect("/** */ var foo = Ext.emptyFn").should == :method end it "object property initialized with function" do detect(<<-EOS).should == :method Foo = { /** */ bar: function(){} }; EOS end it "object property in comma-first notation initialized with function" do detect(<<-EOS).should == :method Foo = { foo: 5 /** */ , bar: function(){} }; EOS end it "object property initialized with Ext.emptyFn" do detect(<<-EOS).should == :method Foo = { /** */ bar: Ext.emptyFn }; EOS end end describe "detects as event" do Loading