Skip to content

Commit 685ca41

Browse files
committed
fix: Comments on projects were broken
1 parent d746d85 commit 685ca41

File tree

4 files changed

+16
-74
lines changed

4 files changed

+16
-74
lines changed

src/lib/converter/converter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ export class Converter extends ChildableComponent<
310310
// Special case for when we're giving a single entry point, we don't need to
311311
// create modules for each entry. Register the project as this module.
312312
context.project.registerReflection(context.project, symbol);
313+
context.trigger(
314+
Converter.EVENT_CREATE_DECLARATION,
315+
context.project,
316+
node
317+
);
313318
moduleContext = context;
314319
} else {
315320
const reflection = context.createDeclarationReflection(

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,6 @@ const TAG_BLACKLIST = [
3838
"typedef",
3939
];
4040

41-
/**
42-
* Structure used by [[ContainerCommentHandler]] to store discovered module comments.
43-
*/
44-
interface ModuleComment {
45-
/**
46-
* The module reflection this comment is targeting.
47-
*/
48-
reflection: Reflection;
49-
50-
/**
51-
* The full text of the best matched comment.
52-
*/
53-
fullText: string;
54-
55-
/**
56-
* Has the full text been marked as being preferred?
57-
*/
58-
isPreferred: boolean;
59-
}
60-
6141
/**
6242
* A handler that parses TypeDoc comments and attaches [[Comment]] instances to
6343
* the generated reflections.
@@ -67,18 +47,11 @@ export class CommentPlugin extends ConverterComponent {
6747
@BindOption("excludeTags")
6848
excludeTags!: string[];
6949

70-
/**
71-
* List of discovered module comments.
72-
* Defined in this.onBegin
73-
*/
74-
private comments!: { [id: number]: ModuleComment };
75-
7650
/**
7751
* Create a new CommentPlugin instance.
7852
*/
7953
initialize() {
8054
this.listenTo(this.owner, {
81-
[Converter.EVENT_BEGIN]: this.onBegin,
8255
[Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,
8356
[Converter.EVENT_CREATE_SIGNATURE]: this.onDeclaration,
8457
[Converter.EVENT_CREATE_TYPE_PARAMETER]: this.onCreateTypeParameter,
@@ -87,29 +60,6 @@ export class CommentPlugin extends ConverterComponent {
8760
});
8861
}
8962

90-
private storeModuleComment(comment: string, reflection: Reflection) {
91-
const isPreferred = comment.toLowerCase().includes("@preferred");
92-
93-
if (this.comments[reflection.id]) {
94-
const info = this.comments[reflection.id];
95-
if (
96-
!isPreferred &&
97-
(info.isPreferred || info.fullText.length > comment.length)
98-
) {
99-
return;
100-
}
101-
102-
info.fullText = comment;
103-
info.isPreferred = isPreferred;
104-
} else {
105-
this.comments[reflection.id] = {
106-
reflection: reflection,
107-
fullText: comment,
108-
isPreferred: isPreferred,
109-
};
110-
}
111-
}
112-
11363
/**
11464
* Apply all comment tag modifiers to the given reflection.
11565
*
@@ -152,19 +102,15 @@ export class CommentPlugin extends ConverterComponent {
152102
}
153103

154104
if (
155-
reflection.kindOf(ReflectionKind.Module | ReflectionKind.Namespace)
105+
reflection.kindOf(
106+
ReflectionKind.Module | ReflectionKind.Namespace
107+
) ||
108+
reflection.kind === ReflectionKind.Project
156109
) {
157110
comment.removeTags("packagedocumentation");
158111
}
159112
}
160113

161-
/**
162-
* Triggered when the converter begins converting a project.
163-
*/
164-
private onBegin(_context: Context) {
165-
this.comments = {};
166-
}
167-
168114
/**
169115
* Triggered when the converter has created a type parameter reflection.
170116
*
@@ -227,14 +173,10 @@ export class CommentPlugin extends ConverterComponent {
227173
return;
228174
}
229175

230-
if (reflection.kindOf(ReflectionKind.Namespace)) {
231-
this.storeModuleComment(rawComment, reflection);
232-
} else {
233-
const comment = parseComment(rawComment, reflection.comment);
234-
this.applyModifiers(reflection, comment);
235-
this.removeExcludedTags(comment);
236-
reflection.comment = comment;
237-
}
176+
const comment = parseComment(rawComment, reflection.comment);
177+
this.applyModifiers(reflection, comment);
178+
this.removeExcludedTags(comment);
179+
reflection.comment = comment;
238180

239181
if (reflection.kindOf(ReflectionKind.Module)) {
240182
const tag = reflection.comment?.getTag("module");
@@ -251,14 +193,6 @@ export class CommentPlugin extends ConverterComponent {
251193
* @param context The context object describing the current state the converter is in.
252194
*/
253195
private onBeginResolve(context: Context) {
254-
for (const info of Object.values(this.comments)) {
255-
const comment = parseComment(info.fullText);
256-
comment.removeTags("preferred");
257-
258-
this.applyModifiers(info.reflection, comment);
259-
info.reflection.comment = comment;
260-
}
261-
262196
const excludeInternal = this.application.options.getValue(
263197
"excludeInternal"
264198
);

src/test/converter/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** */
2+
13
/**
24
* not included anywhere
35
* @typedef {Object} InterfaceIsh

src/test/converter/js/specs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"kind": 0,
55
"kindString": "Project",
66
"flags": {},
7+
"comment": {},
78
"children": [
89
{
910
"id": 11,

0 commit comments

Comments
 (0)