Merge pull request #83 from tschaub/extends

Properly inherit members from grandparents.
This commit is contained in:
Jannon Frank 2012-03-15 17:49:29 -07:00
commit 51d148fddd
4 changed files with 42 additions and 13 deletions

View File

@ -4,18 +4,17 @@
exports.addInherited = function(docs) {
var dependencies = mapDependencies(docs.index);
var sorted = sort(dependencies);
var additions = [];
sorted.forEach(function(name) {
var doclets = docs.index[name];
Array.prototype.push.apply(additions, getAdditions(doclets, docs));
});
additions.forEach(function(doc) {
var name = doc.longname;
if (!(docs.index.hasOwnProperty(name))) {
docs.index[name] = [];
}
docs.index[name].push(doc);
docs.push(doc);
var additions = getAdditions(doclets, docs);
additions.forEach(function(doc) {
var name = doc.longname;
if (!(docs.index.hasOwnProperty(name))) {
docs.index[name] = [];
}
docs.index[name].push(doc);
docs.push(doc);
});
});
}

View File

@ -1,3 +1,3 @@
From the project root, run the following command in the terminal:
java -jar lib/js.jar jsdoc.js -T
java -jar lib/js.jar -modules rhino_modules -modules node_modules jsdoc.js -T

View File

@ -25,7 +25,7 @@ Foo.prototype.method2 = function() {};
/**
* @constructor
* @extends Foo
* @extends Foo
*/
function Bar() {
/** Thrid prop **/
@ -37,3 +37,17 @@ function Bar() {
*/
Bar.prototype.method2 = function() {};
/**
* @constructor
* @extends Bar
*/
function Baz() {
/** Override prop1 */
this.prop1 = "new";
}
/**
* Third grandchild method.
*/
Baz.prototype.method3 = function() {};

View File

@ -12,6 +12,12 @@
barProp3 = docSet.getByLongname('Bar#prop3')[0],
barMethod1 = docSet.getByLongname('Bar#method1')[0],
barMethod2 = docSet.getByLongname('Bar#method2')[0];
bazProp1 = docSet.getByLongname('Baz#prop1')[0],
bazProp2 = docSet.getByLongname('Baz#prop2')[0],
bazProp3 = docSet.getByLongname('Baz#prop3')[0],
bazMethod1 = docSet.getByLongname('Baz#method1')[0],
bazMethod2 = docSet.getByLongname('Baz#method2')[0];
bazMethod3 = docSet.getByLongname('Baz#method3')[0];
test('When a symbol has an @augments tag, the doclet has a augments property that includes that value.', function() {
assert.equal(typeof bar.augments, 'object');
@ -47,5 +53,15 @@
assert.equal(barMethod2.description, "Second child method.");
});
test('When an object is extended, it inherits properties set on grandparent prototype', function() {
assert.equal(fooProp1.memberof, "Foo");
assert.equal(barProp1.memberof, "Bar");
assert.equal(bazProp1.memberof, "Baz");
assert.equal(bazProp1.description, "Override prop1");
assert.equal(bazMethod1.memberof, "Baz");
assert.equal(bazMethod2.memberof, "Baz");
assert.equal(bazMethod3.memberof, "Baz");
});
})();
})();