Loading lib/jsduck/aliases.rb +14 −3 Original line number Diff line number Diff line Loading @@ -15,14 +15,25 @@ module JsDuck end end # Copy over doc/params/return from original methods to aliases. # Copy over doc/params/return from original member to alias. def resolve(al) al_def = al[:alias] orig = @relations[al_def[:cls]].get_member(al_def[:member], al_def[:type] || al[:tagname]) orig = find_original(al) al[:doc] = al[:doc] + "\n\n" + orig[:doc] al[:params] = orig[:params] if orig[:params] al[:return] = orig[:return] if orig[:return] end # Given aliased member, finds the original member. # If the original also happens to be an alias, continue recursively. def find_original(al) al_def = al[:alias] orig = @relations[al_def[:cls]].get_member(al_def[:member], al_def[:type] || al[:tagname]) if orig[:alias] find_original(orig) else orig end end end end spec/aggregator_alias_spec.rb +38 −0 Original line number Diff line number Diff line Loading @@ -213,5 +213,43 @@ describe JsDuck::Aggregator do it_behaves_like "@alias" end describe "recursive @aliases" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @method bar * Original comment. * @param arg1 * @param arg2 * @return {String} */ /** @class HyperCore */ /** * @method zap * Alias2 comment. * @alias Core#foobar */ /** @class Core */ /** * @method foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs["Foo"][:members][:method][0] @alias = @docs["Core"][:members][:method][0] @alias2 = @docs["HyperCore"][:members][:method][0] end it_behaves_like "@alias" it "alias2 inherites params from first method" do @alias2[:params].length.should == 2 end end end Loading
lib/jsduck/aliases.rb +14 −3 Original line number Diff line number Diff line Loading @@ -15,14 +15,25 @@ module JsDuck end end # Copy over doc/params/return from original methods to aliases. # Copy over doc/params/return from original member to alias. def resolve(al) al_def = al[:alias] orig = @relations[al_def[:cls]].get_member(al_def[:member], al_def[:type] || al[:tagname]) orig = find_original(al) al[:doc] = al[:doc] + "\n\n" + orig[:doc] al[:params] = orig[:params] if orig[:params] al[:return] = orig[:return] if orig[:return] end # Given aliased member, finds the original member. # If the original also happens to be an alias, continue recursively. def find_original(al) al_def = al[:alias] orig = @relations[al_def[:cls]].get_member(al_def[:member], al_def[:type] || al[:tagname]) if orig[:alias] find_original(orig) else orig end end end end
spec/aggregator_alias_spec.rb +38 −0 Original line number Diff line number Diff line Loading @@ -213,5 +213,43 @@ describe JsDuck::Aggregator do it_behaves_like "@alias" end describe "recursive @aliases" do before do @docs = parse(<<-EOF) /** @class Foo */ /** * @method bar * Original comment. * @param arg1 * @param arg2 * @return {String} */ /** @class HyperCore */ /** * @method zap * Alias2 comment. * @alias Core#foobar */ /** @class Core */ /** * @method foobar * Alias comment. * @alias Foo#bar */ EOF @orig = @docs["Foo"][:members][:method][0] @alias = @docs["Core"][:members][:method][0] @alias2 = @docs["HyperCore"][:members][:method][0] end it_behaves_like "@alias" it "alias2 inherites params from first method" do @alias2[:params].length.should == 2 end end end