lib/partial-details.js
function partialForCallTree (name, partials, visitedNodes) {
  const cycleFound = visitedNodes[name]
  try {
    visitedNodes[name] = true
    const partial = partials[name]
    if (!partial) {
      throw new Error(`Missing partial "${name}"`)
    }
    let children
    if (!cycleFound) {
      children = partial.callsPartial
        .map((callee) => callee.name)
        // Remove redundant names (only take the first one)
        .filter((name, index, array) => array.indexOf(name) === index)
        .map((name) => partialForCallTree(name, partials, visitedNodes))
    }
    return {
      name,
      type: 'partial',
      comments: partial.comments,
      path: partial.path,
      children,
      cycleFound
    }
  } finally {
    if (!cycleFound) {
      delete visitedNodes[name]
    }
  }
}
function partialForCallTree (name, partials, visitedNodes) {
  const cycleFound = visitedNodes[name]
  try {
    visitedNodes[name] = true
    const partial = partials[name]
    if (!partial) {
      throw new Error(`Missing partial "${name}"`)
    }
    let children
    if (!cycleFound) {
      children = partial.callsPartial
        .map((callee) => callee.name)
        // Remove redundant names (only take the first one)
        .filter((name, index, array) => array.indexOf(name) === index)
        .map((name) => partialForCallTree(name, partials, visitedNodes))
    }
    return {
      name,
      type: 'partial',
      comments: partial.comments,
      path: partial.path,
      children,
      cycleFound
    }
  } finally {
    if (!cycleFound) {
      delete visitedNodes[name]
    }
  }
}
function partialForCallTree ( name , partials , visitedNodes ) { const cycleFound = visitedNodes [ name ] try { visitedNodes [ name ] = true const partial = partials [ name ] if ( ! partial ) { throw new Error ( ` ${ name } ` ) } let children if ( ! cycleFound ) { children = partial . callsPartial . map ( ( callee ) => callee . name ) // Remove redundant names (only take the first one) . filter ( ( name , index , array ) => array . indexOf ( name ) === index ) . map ( ( name ) => partialForCallTree ( name , partials , visitedNodes ) ) } return { name , type : 'partial' , comments : partial . comments , path : partial . path , children , cycleFound } } finally { if ( ! cycleFound ) { delete visitedNodes [ name ] } } }
Inner function that returns a partial and its callees as tree
@param {string} name the name of the partial
@param {object} partials an object of all partials (by name). This is assumed to be an augmentedPartial with comment
and  callee
@param {object<boolean>=} visitedNodes names of the visited nodes for breaking cycles (values are alwasy "true")
@returns {{name: *, type: string, comment}}
Inner function that returns a partial and its callees as tree