use doop() to break circular refs in enums, and add test for circular refs in enums

This commit is contained in:
Jeff Williams 2012-07-02 20:49:26 -07:00
parent 08da5ce4f6
commit 5f23be1251
2 changed files with 11 additions and 2 deletions

View File

@ -310,14 +310,17 @@ exports.Parser.prototype.addDocletRef = function(e) {
} }
exports.Parser.prototype.resolveEnum = function(e) { exports.Parser.prototype.resolveEnum = function(e) {
var parent = currentParser.resolvePropertyParent(e.code.node); var doop = require("jsdoc/util/doop").doop,
parent = currentParser.resolvePropertyParent(e.code.node);
if (parent && parent.doclet.isEnum) { if (parent && parent.doclet.isEnum) {
if (!parent.doclet.properties) { parent.doclet.properties = []; } if (!parent.doclet.properties) { parent.doclet.properties = []; }
// members of an enum inherit the enum's type // members of an enum inherit the enum's type
if (parent.doclet.type && !e.doclet.type) { e.doclet.type = parent.doclet.type; } if (parent.doclet.type && !e.doclet.type) { e.doclet.type = parent.doclet.type; }
delete e.doclet.undocumented; delete e.doclet.undocumented;
e.doclet.defaultvalue = e.doclet.meta.code.value; e.doclet.defaultvalue = e.doclet.meta.code.value;
parent.doclet.properties.push(e.doclet); // add the doclet to the parent's properties
// use a copy of the doclet to avoid circular references
parent.doclet.properties.push( doop(e.doclet) );
} }
} }

View File

@ -22,4 +22,10 @@ describe("@enum tag", function() {
it('If a @type is given for the property it is reflected in the property value.', function() { it('If a @type is given for the property it is reflected in the property value.', function() {
expect(tristate.properties[2].type.names.join(', ')).toEqual('boolean'); expect(tristate.properties[2].type.names.join(', ')).toEqual('boolean');
}); });
it('An enum does not contain any circular references.', function() {
var dump = require("jsdoc/util/dumper").dump;
expect( dump(tristate) ).not.toMatch("<CircularRef>");
});
}); });