diff --git a/lib/jsdoc/src/parser.js b/lib/jsdoc/src/parser.js index 08c958e7..24bafb7f 100644 --- a/lib/jsdoc/src/parser.js +++ b/lib/jsdoc/src/parser.js @@ -444,28 +444,28 @@ Parser.prototype.resolveThis = function(node) { * an empty array if no doclets are found. */ Parser.prototype.resolvePropertyParents = function(node) { - var currentNode = node; + var currentAncestor = node.parent; + var nextAncestor = currentAncestor ? currentAncestor.parent : null; var doclet; var doclets = []; - do { - if (currentNode.parent) { - doclet = this._getDoclet(currentNode.parent.nodeId); - if (doclet) { - doclets.push(doclet); - } - - // if the parent is an assignment expression (for example, `exports.FOO` in - // `var foo = exports.FOO = { x: 1 }`, keep walking upwards - if (currentNode.parent.parent.type === Syntax.AssignmentExpression) { - currentNode = currentNode.parent; - } - // otherwise, we're done - else { - currentNode = null; - } + while (currentAncestor) { + doclet = this._getDoclet(currentAncestor.nodeId); + if (doclet) { + doclets.push(doclet); } - } while (currentNode); + + // if the next ancestor's parent is an assignment expression (for example, `exports.FOO` in + // `var foo = exports.FOO = { x: 1 }`, keep walking upwards + if (nextAncestor && nextAncestor.type === Syntax.AssignmentExpression) { + nextAncestor = nextAncestor.parent; + currentAncestor = currentAncestor.parent; + } + // otherwise, we're done + else { + currentAncestor = null; + } + } return doclets; };