From f1b6b2dc7ccaa5b74de4f952c0ea8de56e53ede6 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Tue, 13 Jan 2015 14:39:39 -0800 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20create=20empty=20`children`=20o?= =?UTF-8?q?bjects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jsdoc/name.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 8fc3cd04..afac40ca 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -337,7 +337,7 @@ exports.longnamesToTree = function longnamesToTree(longnames, doclets) { longnames.forEach(function(longname) { var currentLongname = ''; - var currentNavItem = tree; + var currentParent = tree; var nameInfo; var processed; @@ -352,14 +352,18 @@ exports.longnamesToTree = function longnamesToTree(longnames, doclets) { processed.chunks.forEach(function(chunk) { currentLongname += chunk; - if (!hasOwnProp.call(currentNavItem, chunk)) { - currentNavItem[chunk] = nameInfo[currentLongname]; + if (currentParent !== tree) { + currentParent.children = currentParent.children || {}; + currentParent = currentParent.children; } - if (currentNavItem[chunk]) { - currentNavItem[chunk].doclet = doclets ? doclets[currentLongname] : null; - currentNavItem[chunk].children = currentNavItem[chunk].children || {}; - currentNavItem = currentNavItem[chunk].children; + if (!hasOwnProp.call(currentParent, chunk)) { + currentParent[chunk] = nameInfo[currentLongname]; + } + + if (currentParent[chunk]) { + currentParent[chunk].doclet = doclets ? doclets[currentLongname] : null; + currentParent = currentParent[chunk]; } }); });