prevent a crash if a doclet has an empty longname

This commit is contained in:
Jeff Williams 2014-08-07 13:17:54 -07:00
parent c2d3d0041b
commit d09c654d36

View File

@ -9,6 +9,8 @@
var _ = require('underscore');
var escape = require('escape-string-regexp');
var hasOwnProp = Object.prototype.hasOwnProperty;
/**
* Longnames that have a special meaning in JSDoc.
*
@ -315,20 +317,32 @@ exports.longnamesToTree = function longnamesToTree(longnames, doclets) {
var tree = {};
longnames.forEach(function(longname) {
var processed = splitLongname(longname, splitOptions);
var nameInfo = processed.nameInfo;
var chunk;
var currentLongname = '';
var currentNavItem = tree;
var nameInfo;
var processed;
// don't try to add empty longnames to the tree
if (!longname) {
return;
}
processed = splitLongname(longname, splitOptions);
nameInfo = processed.nameInfo;
processed.chunks.forEach(function(chunk) {
currentLongname += chunk;
currentNavItem[chunk] = currentNavItem[chunk] || nameInfo[currentLongname];
currentNavItem[chunk].doclet = doclets ? doclets[currentLongname] : null;
currentNavItem[chunk].children = currentNavItem[chunk].children || {};
if (!hasOwnProp.call(currentNavItem, chunk)) {
currentNavItem[chunk] = nameInfo[currentLongname];
}
currentNavItem = currentNavItem[chunk].children;
if (currentNavItem[chunk]) {
currentNavItem[chunk].doclet = doclets ? doclets[currentLongname] : null;
currentNavItem[chunk].children = currentNavItem[chunk].children || {};
currentNavItem = currentNavItem[chunk].children;
}
});
});