Skip to content

Commit

Permalink
Fix comment discovery if there are multiple comments
Browse files Browse the repository at this point in the history
Closes #1961.
  • Loading branch information
Gerrit0 committed Jun 26, 2022
1 parent 9515e99 commit b6d1bdd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/lib/converter/comments/discovery.ts
Expand Up @@ -88,7 +88,7 @@ export function discoverComment(
): [ts.SourceFile, ts.CommentRange[]] | undefined {
// For a module comment, we want the first one defined in the file,
// not the last one, since that will apply to the import or declaration.
const reverse = symbol.declarations?.some(ts.isSourceFile);
const reverse = !symbol.declarations?.some(ts.isSourceFile);

const discovered: [ts.SourceFile, ts.CommentRange[]][] = [];

Expand Down Expand Up @@ -118,7 +118,7 @@ export function discoverComment(
);

if (reverse) {
comments?.reverse();
comments.reverse();
}

const selectedDocComment = comments.find((ranges) =>
Expand Down
2 changes: 1 addition & 1 deletion src/test/converter/exports/specs.json
Expand Up @@ -762,7 +762,7 @@
"summary": [
{
"kind": "text",
"text": "Doc comment for Mod"
"text": "A simple named export that will be exported from export.ts"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/test/converter/exports/specs.nodoc.json
Expand Up @@ -145,7 +145,7 @@
"summary": [
{
"kind": "text",
"text": "Doc comment for Mod"
"text": "A simple named export that will be exported from export.ts"
}
]
},
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh1961.ts
@@ -0,0 +1,4 @@
/** first */

/** second */
export class WithDocs1 {}
9 changes: 9 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -516,4 +516,13 @@ export const issueTests: {
equal(query(project, "Foo.B").type, new IntrinsicType("number"));
equal(query(project, "Bar.C").type, new LiteralType("C"));
},

gh1961(project) {
equal(
Comment.combineDisplayParts(
query(project, "WithDocs1").comment?.summary
),
"second"
);
},
};

0 comments on commit b6d1bdd

Please sign in to comment.