Skip to content

Commit

Permalink
fix: regression in toc causing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
rhendric committed Sep 4, 2017
1 parent 5bdbf1f commit 125a577
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
11 changes: 11 additions & 0 deletions __tests__/__snapshots__/test.js.snap
Expand Up @@ -50,6 +50,10 @@ This function is third
This function is first
### first
forgot a memberof here... sure hope that doesn't crash anything!
## Bravo
Contains a subsection!
Expand Down Expand Up @@ -80,6 +84,13 @@ second::bar
- \`beans\`
- \`rice\`
## AClass
### second
shares a name with a top level item referenced in the TOC... sure hope
that doesn't crash anything!
"
`;

Expand Down
15 changes: 15 additions & 0 deletions __tests__/fixture/sections.input.js
Expand Up @@ -3,6 +3,21 @@
*/
function first() {}

/** */
class AClass {
/**
* forgot a memberof here... sure hope that doesn't crash anything!
* @method first
*/
first(x, y) {}

/**
* shares a name with a top level item referenced in the TOC... sure hope
* that doesn't crash anything!
*/
second() {}
}

/**
* This class has some members
*/
Expand Down
5 changes: 3 additions & 2 deletions src/sort.js
Expand Up @@ -64,9 +64,10 @@ module.exports = function sortDocs(comments: Array<Comment>, options: Object) {
options.toc.forEach(walk.bind(null, []));
var unfixed = [];
comments.forEach(function(comment) {
const commentPath = paths[comment.name];
if (commentPath) {
let commentPath;
if (!comment.memberof && (commentPath = paths[comment.name])) {
comment.path = commentPath;
delete paths[comment.name];
}

// If comment is of kind 'note', this means that we must be _re_ sorting
Expand Down

0 comments on commit 125a577

Please sign in to comment.