Skip to content

Commit

Permalink
Fix auto-inheriting of overrides.
Browse files Browse the repository at this point in the history
Overrides shouldn't be inherited, but the code in InheritMembers
happened to inherit them along with all the other things, causing
auto-detected members to share the same overrides array, resulting
in bogus lists of overridden members.

This fix should take care of bug #465.
  • Loading branch information
nene committed Oct 9, 2013
1 parent 3b71e45 commit b6b94b1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/jsduck/process/inherit_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def auto_inherit(m, parent)
m[:doc] = parent[:doc] if m[:doc].empty?

parent.each_pair do |key, value|
if key == :type || !m[key]
if key == :overrides
# overrides can't be inherited.
elsif key == :type || !m[key]
m[key] = value
end
end
Expand Down
72 changes: 71 additions & 1 deletion spec/aggregator_overrides_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

describe JsDuck::Aggregator do
def parse(string)
Helper::MiniParser.parse(string, {:overrides => true, :filename => "blah.js"})
Helper::MiniParser.parse(string, {
:overrides => true,
:inherit_doc => true,
:filename => "blah.js"
})
end

shared_examples_for "override" do
Expand Down Expand Up @@ -76,4 +80,70 @@ def parse(string)
end
end

# Test for bug #465
describe "overriding with multiple auto-detected members" do
before do
@docs = parse(<<-EOF)
/** */
Ext.define('Base', {
/** */
foo: 1
});
/** */
Ext.define('Child', {
extend: 'Base',
foo: 2
});
/** */
Ext.define('GrandChild', {
extend: 'Child',
foo: 3
});
/** */
Ext.define('GrandGrandChild', {
extend: 'GrandChild',
foo: 4
});
EOF
end

def get_overrides(cls)
@docs[cls].find_members(:name => "foo")[0][:overrides]
end


it "lists just one override in Child class" do
get_overrides("Child").length.should == 1
end

it "lists just one override in GrandChild class" do
get_overrides("GrandChild").length.should == 1
end

it "lists just one override in GrandGrandChild class" do
get_overrides("GrandGrandChild").length.should == 1
end


it "lists Base as overridden in Child class" do
get_overrides("Child")[0][:owner].should == "Base"
end

it "lists Child as overridden in GrandChild class" do
get_overrides("GrandChild")[0][:owner].should == "Child"
end

it "lists GrandChild as overridden in GrandGrandChild class" do
get_overrides("GrandGrandChild")[0][:owner].should == "GrandChild"
end

end


end

0 comments on commit b6b94b1

Please sign in to comment.