Skip to content

Commit 4dac6cd

Browse files
committed
Fix missing comments on type-only classes/functions
Resolves #2970
1 parent d47f04c commit 4dac6cd

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ title: Changelog
44

55
## Unreleased
66

7+
### Bug Fixes
8+
9+
- Classes and functions exported with `export { type X }` are no longer missing comments, #2970.
10+
711
## v0.28.6 (2025-06-27)
812

913
### Features

src/lib/converter/comments/discovery.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
8080
[ReflectionKind.Interface]: [
8181
ts.SyntaxKind.InterfaceDeclaration,
8282
ts.SyntaxKind.TypeAliasDeclaration,
83+
ts.SyntaxKind.ClassDeclaration, // type only exports
8384
],
8485
[ReflectionKind.Constructor]: [ts.SyntaxKind.Constructor],
8586
[ReflectionKind.Property]: variablePropertyKinds,
@@ -104,7 +105,12 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
104105
[ReflectionKind.Accessor]: [ts.SyntaxKind.PropertyDeclaration],
105106
[ReflectionKind.GetSignature]: [ts.SyntaxKind.GetAccessor],
106107
[ReflectionKind.SetSignature]: [ts.SyntaxKind.SetAccessor],
107-
[ReflectionKind.TypeAlias]: [ts.SyntaxKind.TypeAliasDeclaration],
108+
[ReflectionKind.TypeAlias]: [
109+
ts.SyntaxKind.TypeAliasDeclaration,
110+
ts.SyntaxKind.FunctionDeclaration, // type only exports
111+
// Intentionally not included to avoid comments being copied for variable/alias combos
112+
// ts.SyntaxKind.VariableDeclaration,
113+
],
108114
[ReflectionKind.Reference]: [
109115
ts.SyntaxKind.NamespaceExport,
110116
ts.SyntaxKind.ExportSpecifier,

src/test/converter2/issues/gh2970.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Comment */
2+
class Class {}
3+
4+
/** Comment */
5+
const Var = 123;
6+
7+
/** Comment */
8+
function Func() {}
9+
10+
export type { Class, Func, Var };

src/test/issues.c2.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,4 +2126,13 @@ describe("Issue Tests", () => {
21262126
const project = convert();
21272127
equal(project.children?.map(c => c.name), ["third"]);
21282128
});
2129+
2130+
it("#2970 includes comments on type only exports", () => {
2131+
const project = convert();
2132+
equal(project.children?.map(c => [c.name, Comment.combineDisplayParts(c.comment?.summary)]), [
2133+
["Class", "Comment"],
2134+
["Func", "Comment"],
2135+
["Var", "Comment"],
2136+
]);
2137+
});
21292138
});

0 commit comments

Comments
 (0)