Loading lib/jsduck/doc_type.rb +9 −0 Original line number Diff line number Diff line Loading @@ -28,11 +28,14 @@ module JsDuck :cfg else exp = expression?(ast) ? ast["expression"] : nil var = var?(ast) ? ast["declarations"][0] : nil if exp && call?(exp) && ext_define?(exp["callee"]) :class elsif exp && assignment?(exp) && class_name?(exp["left"]) :class elsif var && class_name?(var["id"]) :class elsif function?(ast) && class_name?(ast["id"]) :class elsif ast[:type] == :css_mixin Loading @@ -43,6 +46,8 @@ module JsDuck :method elsif exp && assignment?(exp) && function?(exp["right"]) :method elsif var && function?(var["init"]) :method elsif doc_map[:return] || doc_map[:param] :method else Loading Loading @@ -73,6 +78,10 @@ module JsDuck ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" end def var?(ast) ast["type"] == "VariableDeclaration" 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 +16 −0 Original line number Diff line number Diff line Loading @@ -29,10 +29,22 @@ describe JsDuck::DocType do detect("/** */ MyClass = function() {}").should == :class end it "function assignment to uppercase property" do detect("/** */ foo.MyClass = function() {}").should == :class end it "uppercase var initialization with function" do detect("/** */ var MyClass = function() {}").should == :class end it "Ext.extend()" do detect("/** */ MyClass = Ext.extend(Your.Class, { });").should == :class end it "var initialized with Ext.extend()" do detect("/** */ var MyClass = Ext.extend(Your.Class, { });").should == :class end it "Ext.define()" do detect(<<-EOS).should == :class /** */ Loading Loading @@ -66,6 +78,10 @@ describe JsDuck::DocType do it "assignment of function" do detect("/** */ foo = function() {}").should == :method end it "var initialized with function" do detect("/** */ var foo = function() {}").should == :method end end describe "detects as event" do Loading Loading
lib/jsduck/doc_type.rb +9 −0 Original line number Diff line number Diff line Loading @@ -28,11 +28,14 @@ module JsDuck :cfg else exp = expression?(ast) ? ast["expression"] : nil var = var?(ast) ? ast["declarations"][0] : nil if exp && call?(exp) && ext_define?(exp["callee"]) :class elsif exp && assignment?(exp) && class_name?(exp["left"]) :class elsif var && class_name?(var["id"]) :class elsif function?(ast) && class_name?(ast["id"]) :class elsif ast[:type] == :css_mixin Loading @@ -43,6 +46,8 @@ module JsDuck :method elsif exp && assignment?(exp) && function?(exp["right"]) :method elsif var && function?(var["init"]) :method elsif doc_map[:return] || doc_map[:param] :method else Loading Loading @@ -73,6 +78,10 @@ module JsDuck ast["type"] == "FunctionDeclaration" || ast["type"] == "FunctionExpression" end def var?(ast) ast["type"] == "VariableDeclaration" 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 +16 −0 Original line number Diff line number Diff line Loading @@ -29,10 +29,22 @@ describe JsDuck::DocType do detect("/** */ MyClass = function() {}").should == :class end it "function assignment to uppercase property" do detect("/** */ foo.MyClass = function() {}").should == :class end it "uppercase var initialization with function" do detect("/** */ var MyClass = function() {}").should == :class end it "Ext.extend()" do detect("/** */ MyClass = Ext.extend(Your.Class, { });").should == :class end it "var initialized with Ext.extend()" do detect("/** */ var MyClass = Ext.extend(Your.Class, { });").should == :class end it "Ext.define()" do detect(<<-EOS).should == :class /** */ Loading Loading @@ -66,6 +78,10 @@ describe JsDuck::DocType do it "assignment of function" do detect("/** */ foo = function() {}").should == :method end it "var initialized with function" do detect("/** */ var foo = function() {}").should == :method end end describe "detects as event" do Loading