Loading lib/jsduck/ast.rb +7 −1 Original line number Diff line number Diff line require "jsduck/serializer" require "jsduck/evaluator" require "jsduck/function_ast" module JsDuck Loading Loading @@ -392,7 +393,8 @@ module JsDuck return { :tagname => :method, :name => name, :params => make_params(ast) :params => make_params(ast), :chainable => chainable?(ast), } end Loading @@ -404,6 +406,10 @@ module JsDuck end end def chainable?(ast) FunctionAst.new.returns(ast) == "this" end def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => tagname, Loading lib/jsduck/merger.rb +1 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ module JsDuck def merge_like_method(docs, code) h = do_merge(docs, code) h[:params] = merge_params(docs, code) h[:meta][:chainable] = code[:chainable] if code[:chainable] h end Loading spec/aggregator_chainable_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -159,4 +159,25 @@ describe JsDuck::Aggregator do end end describe "function with 'return this;' in code" do let(:cls) do parse(<<-EOS)["MyClass"] /** */ Ext.define("MyClass", { /** */ bar: function() { return this; } }); EOS end it "adds @chainable tag" do cls[:members][0][:meta][:chainable].should == true end it "adds @return {MyClass} this" do cls[:members][0][:return][:type].should == "MyClass" cls[:members][0][:return][:doc].should == "this" end end end Loading
lib/jsduck/ast.rb +7 −1 Original line number Diff line number Diff line require "jsduck/serializer" require "jsduck/evaluator" require "jsduck/function_ast" module JsDuck Loading Loading @@ -392,7 +393,8 @@ module JsDuck return { :tagname => :method, :name => name, :params => make_params(ast) :params => make_params(ast), :chainable => chainable?(ast), } end Loading @@ -404,6 +406,10 @@ module JsDuck end end def chainable?(ast) FunctionAst.new.returns(ast) == "this" end def make_property(name=nil, ast=nil, tagname=:property) return { :tagname => tagname, Loading
lib/jsduck/merger.rb +1 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ module JsDuck def merge_like_method(docs, code) h = do_merge(docs, code) h[:params] = merge_params(docs, code) h[:meta][:chainable] = code[:chainable] if code[:chainable] h end Loading
spec/aggregator_chainable_spec.rb +21 −0 Original line number Diff line number Diff line Loading @@ -159,4 +159,25 @@ describe JsDuck::Aggregator do end end describe "function with 'return this;' in code" do let(:cls) do parse(<<-EOS)["MyClass"] /** */ Ext.define("MyClass", { /** */ bar: function() { return this; } }); EOS end it "adds @chainable tag" do cls[:members][0][:meta][:chainable].should == true end it "adds @return {MyClass} this" do cls[:members][0][:return][:type].should == "MyClass" cls[:members][0][:return][:doc].should == "this" end end end