@@ -16,6 +16,28 @@ import { Context } from '../context';
16
16
import { partition , uniq } from 'lodash' ;
17
17
import { SourceReference } from '../../models' ;
18
18
19
+ /**
20
+ * These tags are not useful to display in the generated documentation.
21
+ * They should be ignored when parsing comments. Any relevant type information
22
+ * (for JS users) will be consumed by TypeScript and need not be preserved
23
+ * in the comment.
24
+ *
25
+ * Note that param/arg/argument/return/returns are not present.
26
+ * These tags will have their type information stripped when parsing, but still
27
+ * provide useful information for documentation.
28
+ */
29
+ const TAG_BLACKLIST = [
30
+ 'augments' ,
31
+ 'callback' ,
32
+ 'class' ,
33
+ 'constructor' ,
34
+ 'enum' ,
35
+ 'extends' ,
36
+ 'this' ,
37
+ 'type' ,
38
+ 'typedef'
39
+ ] ;
40
+
19
41
/**
20
42
* Structure used by [[ContainerCommentHandler]] to store discovered module comments.
21
43
*/
@@ -37,7 +59,7 @@ interface ModuleComment {
37
59
}
38
60
39
61
/**
40
- * A handler that parses javadoc comments and attaches [[Models. Comment]] instances to
62
+ * A handler that parses TypeDoc comments and attaches [[Comment]] instances to
41
63
* the generated reflections.
42
64
*/
43
65
@Component ( { name : 'comment' } )
@@ -92,27 +114,27 @@ export class CommentPlugin extends ConverterComponent {
92
114
private applyModifiers ( reflection : Reflection , comment : Comment ) {
93
115
if ( comment . hasTag ( 'private' ) ) {
94
116
reflection . setFlag ( ReflectionFlag . Private ) ;
95
- CommentPlugin . removeTags ( comment , 'private' ) ;
117
+ comment . removeTags ( 'private' ) ;
96
118
}
97
119
98
120
if ( comment . hasTag ( 'protected' ) ) {
99
121
reflection . setFlag ( ReflectionFlag . Protected ) ;
100
- CommentPlugin . removeTags ( comment , 'protected' ) ;
122
+ comment . removeTags ( 'protected' ) ;
101
123
}
102
124
103
125
if ( comment . hasTag ( 'public' ) ) {
104
126
reflection . setFlag ( ReflectionFlag . Public ) ;
105
- CommentPlugin . removeTags ( comment , 'public' ) ;
127
+ comment . removeTags ( 'public' ) ;
106
128
}
107
129
108
130
if ( comment . hasTag ( 'event' ) ) {
109
131
reflection . kind = ReflectionKind . Event ;
110
132
// reflection.setFlag(ReflectionFlag.Event);
111
- CommentPlugin . removeTags ( comment , 'event' ) ;
133
+ comment . removeTags ( 'event' ) ;
112
134
}
113
135
114
136
if ( reflection . kindOf ( ReflectionKind . ExternalModule ) ) {
115
- CommentPlugin . removeTags ( comment , 'packagedocumentation' ) ;
137
+ comment . removeTags ( 'packagedocumentation' ) ;
116
138
}
117
139
}
118
140
@@ -172,11 +194,13 @@ export class CommentPlugin extends ConverterComponent {
172
194
if ( reflection . kindOf ( ReflectionKind . FunctionOrMethod ) || ( reflection . kindOf ( ReflectionKind . Event ) && reflection [ 'signatures' ] ) ) {
173
195
const comment = parseComment ( rawComment , reflection . comment ) ;
174
196
this . applyModifiers ( reflection , comment ) ;
197
+ this . removeBlacklistedTags ( comment ) ;
175
198
} else if ( reflection . kindOf ( ReflectionKind . Module ) ) {
176
199
this . storeModuleComment ( rawComment , reflection ) ;
177
200
} else {
178
201
const comment = parseComment ( rawComment , reflection . comment ) ;
179
202
this . applyModifiers ( reflection , comment ) ;
203
+ this . removeBlacklistedTags ( comment ) ;
180
204
reflection . comment = comment ;
181
205
}
182
206
}
@@ -212,7 +236,7 @@ export class CommentPlugin extends ConverterComponent {
212
236
213
237
const info = this . comments [ id ] ;
214
238
const comment = parseComment ( info . fullText ) ;
215
- CommentPlugin . removeTags ( comment , 'preferred' ) ;
239
+ comment . removeTags ( 'preferred' ) ;
216
240
217
241
this . applyModifiers ( info . reflection , comment ) ;
218
242
info . reflection . comment = comment ;
@@ -261,14 +285,14 @@ export class CommentPlugin extends ConverterComponent {
261
285
const comment = reflection . comment ;
262
286
if ( comment && comment . hasTag ( 'returns' ) ) {
263
287
comment . returns = comment . getTag ( 'returns' ) ! . text ;
264
- CommentPlugin . removeTags ( comment , 'returns' ) ;
288
+ comment . removeTags ( 'returns' ) ;
265
289
}
266
290
267
291
signatures . forEach ( ( signature ) => {
268
292
let childComment = signature . comment ;
269
293
if ( childComment && childComment . hasTag ( 'returns' ) ) {
270
294
childComment . returns = childComment . getTag ( 'returns' ) ! . text ;
271
- CommentPlugin . removeTags ( childComment , 'returns' ) ;
295
+ childComment . removeTags ( 'returns' ) ;
272
296
}
273
297
274
298
if ( comment ) {
@@ -296,33 +320,29 @@ export class CommentPlugin extends ConverterComponent {
296
320
} ) ;
297
321
}
298
322
299
- CommentPlugin . removeTags ( childComment , 'param' ) ;
323
+ childComment ? .removeTags ( 'param' ) ;
300
324
} ) ;
301
325
302
- CommentPlugin . removeTags ( comment , 'param' ) ;
326
+ comment ?. removeTags ( 'param' ) ;
327
+ }
328
+ }
329
+
330
+ private removeBlacklistedTags ( comment : Comment ) {
331
+ for ( const tag of TAG_BLACKLIST ) {
332
+ comment . removeTags ( tag ) ;
303
333
}
304
334
}
305
335
306
336
/**
307
337
* Remove all tags with the given name from the given comment instance.
338
+ * @deprecated Use [[Comment.removeTags]] instead.
339
+ * Warn in 0.17, remove in 0.18.
308
340
*
309
341
* @param comment The comment that should be modified.
310
342
* @param tagName The name of the that that should be removed.
311
343
*/
312
344
static removeTags ( comment : Comment | undefined , tagName : string ) {
313
- if ( ! comment || ! comment . tags ) {
314
- return ;
315
- }
316
-
317
- let i = 0 , c = comment . tags . length ;
318
- while ( i < c ) {
319
- if ( comment . tags [ i ] . tagName === tagName ) {
320
- comment . tags . splice ( i , 1 ) ;
321
- c -- ;
322
- } else {
323
- i ++ ;
324
- }
325
- }
345
+ comment ?. removeTags ( tagName ) ;
326
346
}
327
347
328
348
/**
@@ -346,7 +366,7 @@ export class CommentPlugin extends ConverterComponent {
346
366
}
347
367
348
368
/**
349
- * Determins whether or not a reflection has been hidden
369
+ * Determines whether or not a reflection has been hidden
350
370
*
351
371
* @param reflection Reflection to check if hidden
352
372
*/
0 commit comments