Skip to content

Commit

Permalink
Handle comments on destructured exported elements
Browse files Browse the repository at this point in the history
Resolves #1770
  • Loading branch information
Gerrit0 committed Feb 16, 2022
1 parent f3402fc commit 7c49a6d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
- Fixed off by one error in warnings for types referenced but not included in the documentation.
- TypeDoc will no longer render a `Type Parameters` heading if there are no type parameters in some cases.
- Improved source location detection for constructors.
- Improved comment discovery on destructured exported functions, #1770.

## v0.22.11 (2022-01-18)

Expand Down
21 changes: 17 additions & 4 deletions src/lib/converter/comments/discovery.ts
Expand Up @@ -13,6 +13,7 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
[ReflectionKind.Namespace]: [
ts.SyntaxKind.ModuleDeclaration,
ts.SyntaxKind.SourceFile,
ts.SyntaxKind.BindingElement,
],
[ReflectionKind.Enum]: [
ts.SyntaxKind.EnumDeclaration,
Expand All @@ -23,9 +24,18 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
// This is here so that @enum gets it
ts.SyntaxKind.PropertyAssignment,
],
[ReflectionKind.Variable]: [ts.SyntaxKind.VariableDeclaration],
[ReflectionKind.Function]: [ts.SyntaxKind.FunctionDeclaration],
[ReflectionKind.Class]: [ts.SyntaxKind.ClassDeclaration],
[ReflectionKind.Variable]: [
ts.SyntaxKind.VariableDeclaration,
ts.SyntaxKind.BindingElement,
],
[ReflectionKind.Function]: [
ts.SyntaxKind.FunctionDeclaration,
ts.SyntaxKind.BindingElement,
],
[ReflectionKind.Class]: [
ts.SyntaxKind.ClassDeclaration,
ts.SyntaxKind.BindingElement,
],
[ReflectionKind.Interface]: [ts.SyntaxKind.InterfaceDeclaration],
[ReflectionKind.Constructor]: [ts.SyntaxKind.Constructor],
[ReflectionKind.Property]: [
Expand Down Expand Up @@ -88,9 +98,12 @@ export function discoverComment(
// Special behavior here! We temporarily put the implementation comment
// on the reflection which contains all the signatures. This lets us pull
// the comment on the implementation if some signature does not have a comment.
// However, we don't want to skip the node if it is a reference to something.
// See the gh1770 test for an example.
if (
kind & ReflectionKind.ContainsCallSignatures &&
!(node as ts.FunctionDeclaration).body
!(node as ts.FunctionDeclaration).body &&
node.kind !== ts.SyntaxKind.BindingElement
) {
continue;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/converter2/issues/gh1770.ts
@@ -0,0 +1,18 @@
const api = (): {
sym1: () => number;
sym2: number;
} => {
return null!;
};

export const {
/**
* Docs for Sym1
*/
sym1,

/**
* Docs for Sym2
*/
sym2,
} = api();
14 changes: 14 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -331,6 +331,20 @@ export const issueTests: {
);
},

gh1770(project) {
const sym1 = query(project, "sym1");
equal(
Comment.combineDisplayParts(sym1.signatures?.[0].comment?.summary),
"Docs for Sym1"
);

const sym2 = query(project, "sym2");
equal(
Comment.combineDisplayParts(sym2.comment?.summary),
"Docs for Sym2"
);
},

gh1795(project) {
equal(
project.children?.map((c) => c.name),
Expand Down

0 comments on commit 7c49a6d

Please sign in to comment.