Merge pull request #137 from hegemonic/circular-refs

Parser creates circular references in enums
This commit is contained in:
Michael Mathews 2012-07-03 15:26:31 -07:00
commit afb2a3226a
5 changed files with 34 additions and 35 deletions

View File

@ -1,3 +1,4 @@
var doop = require("jsdoc/util/doop").doop;
(function() { (function() {
var hasOwnProperty = Object.prototype.hasOwnProperty; var hasOwnProperty = Object.prototype.hasOwnProperty;
@ -74,20 +75,6 @@
return members; return members;
} }
function doop(o) {
if (o instanceof Object && o.constructor != Function) {
var clone = o instanceof Array ? [] : {}, prop;
for (prop in o){
if ( hasOwnProperty.call(o, prop) ) {
clone[prop] = (o[prop] instanceof Object)? doop(o[prop]) : o[prop];
}
}
return clone;
}
return o;
};
var Sorter = function(dependencies) { var Sorter = function(dependencies) {
this.dependencies = dependencies; this.dependencies = dependencies;
this.visited = {}; this.visited = {};

View File

@ -5,6 +5,8 @@
@license Apache License 2.0 - See file 'LICENSE.md' in this project. @license Apache License 2.0 - See file 'LICENSE.md' in this project.
*/ */
var doop = require("jsdoc/util/doop").doop;
// requires docs to have been indexed: docs.index must be defined here // requires docs to have been indexed: docs.index must be defined here
/** /**
Take a copy of the docs for borrowed symbols and attach them to the Take a copy of the docs for borrowed symbols and attach them to the
@ -47,22 +49,3 @@ exports.resolveBorrows = function(docs) {
} }
}); });
} }
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
Deep clone a simple object.
@private
*/
function doop(o) {
if (o instanceof Object && o.constructor != Function) {
var clone = o instanceof Array ? [] : {}, prop;
for (prop in o){
if ( hasOwnProperty.call(o, prop) ) {
clone[prop] = (o[prop] instanceof Object)? doop(o[prop]) : o[prop];
}
}
return clone;
}
return o;
};

View File

@ -304,14 +304,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

@ -0,0 +1,20 @@
/**
Deep clone a simple object.
@private
*/
var doop = exports.doop = function(o) {
var clone,
hasOwnProp = Object.prototype.hasOwnProperty,
prop;
if (o instanceof Object && o.constructor != Function) {
clone = o instanceof Array ? [] : {};
for (prop in o){
if ( hasOwnProp.call(o, prop) ) {
clone[prop] = (o[prop] instanceof Object)? doop(o[prop]) : o[prop];
}
}
return clone;
}
return o;
};

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>");
});
}); });