clarify logic for resolving property parents

This commit is contained in:
Jeff Williams 2014-10-15 08:51:37 -07:00
parent 79a3be132c
commit 2b34c5167a

View File

@ -444,28 +444,28 @@ Parser.prototype.resolveThis = function(node) {
* an empty array if no doclets are found. * an empty array if no doclets are found.
*/ */
Parser.prototype.resolvePropertyParents = function(node) { Parser.prototype.resolvePropertyParents = function(node) {
var currentNode = node; var currentAncestor = node.parent;
var nextAncestor = currentAncestor ? currentAncestor.parent : null;
var doclet; var doclet;
var doclets = []; var doclets = [];
do { while (currentAncestor) {
if (currentNode.parent) { doclet = this._getDoclet(currentAncestor.nodeId);
doclet = this._getDoclet(currentNode.parent.nodeId); if (doclet) {
if (doclet) { doclets.push(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 (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; return doclets;
}; };