@@ -16,6 +16,28 @@ import { Context } from '../context';
1616import { partition , uniq } from 'lodash' ;
1717import { SourceReference } from '../../models' ;
1818
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+
1941/**
2042 * Structure used by [[ContainerCommentHandler]] to store discovered module comments.
2143 */
@@ -37,7 +59,7 @@ interface ModuleComment {
3759}
3860
3961/**
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
4163 * the generated reflections.
4264 */
4365@Component ( { name : 'comment' } )
@@ -92,27 +114,27 @@ export class CommentPlugin extends ConverterComponent {
92114 private applyModifiers ( reflection : Reflection , comment : Comment ) {
93115 if ( comment . hasTag ( 'private' ) ) {
94116 reflection . setFlag ( ReflectionFlag . Private ) ;
95- CommentPlugin . removeTags ( comment , 'private' ) ;
117+ comment . removeTags ( 'private' ) ;
96118 }
97119
98120 if ( comment . hasTag ( 'protected' ) ) {
99121 reflection . setFlag ( ReflectionFlag . Protected ) ;
100- CommentPlugin . removeTags ( comment , 'protected' ) ;
122+ comment . removeTags ( 'protected' ) ;
101123 }
102124
103125 if ( comment . hasTag ( 'public' ) ) {
104126 reflection . setFlag ( ReflectionFlag . Public ) ;
105- CommentPlugin . removeTags ( comment , 'public' ) ;
127+ comment . removeTags ( 'public' ) ;
106128 }
107129
108130 if ( comment . hasTag ( 'event' ) ) {
109131 reflection . kind = ReflectionKind . Event ;
110132 // reflection.setFlag(ReflectionFlag.Event);
111- CommentPlugin . removeTags ( comment , 'event' ) ;
133+ comment . removeTags ( 'event' ) ;
112134 }
113135
114136 if ( reflection . kindOf ( ReflectionKind . ExternalModule ) ) {
115- CommentPlugin . removeTags ( comment , 'packagedocumentation' ) ;
137+ comment . removeTags ( 'packagedocumentation' ) ;
116138 }
117139 }
118140
@@ -172,11 +194,13 @@ export class CommentPlugin extends ConverterComponent {
172194 if ( reflection . kindOf ( ReflectionKind . FunctionOrMethod ) || ( reflection . kindOf ( ReflectionKind . Event ) && reflection [ 'signatures' ] ) ) {
173195 const comment = parseComment ( rawComment , reflection . comment ) ;
174196 this . applyModifiers ( reflection , comment ) ;
197+ this . removeBlacklistedTags ( comment ) ;
175198 } else if ( reflection . kindOf ( ReflectionKind . Module ) ) {
176199 this . storeModuleComment ( rawComment , reflection ) ;
177200 } else {
178201 const comment = parseComment ( rawComment , reflection . comment ) ;
179202 this . applyModifiers ( reflection , comment ) ;
203+ this . removeBlacklistedTags ( comment ) ;
180204 reflection . comment = comment ;
181205 }
182206 }
@@ -212,7 +236,7 @@ export class CommentPlugin extends ConverterComponent {
212236
213237 const info = this . comments [ id ] ;
214238 const comment = parseComment ( info . fullText ) ;
215- CommentPlugin . removeTags ( comment , 'preferred' ) ;
239+ comment . removeTags ( 'preferred' ) ;
216240
217241 this . applyModifiers ( info . reflection , comment ) ;
218242 info . reflection . comment = comment ;
@@ -261,14 +285,14 @@ export class CommentPlugin extends ConverterComponent {
261285 const comment = reflection . comment ;
262286 if ( comment && comment . hasTag ( 'returns' ) ) {
263287 comment . returns = comment . getTag ( 'returns' ) ! . text ;
264- CommentPlugin . removeTags ( comment , 'returns' ) ;
288+ comment . removeTags ( 'returns' ) ;
265289 }
266290
267291 signatures . forEach ( ( signature ) => {
268292 let childComment = signature . comment ;
269293 if ( childComment && childComment . hasTag ( 'returns' ) ) {
270294 childComment . returns = childComment . getTag ( 'returns' ) ! . text ;
271- CommentPlugin . removeTags ( childComment , 'returns' ) ;
295+ childComment . removeTags ( 'returns' ) ;
272296 }
273297
274298 if ( comment ) {
@@ -296,33 +320,29 @@ export class CommentPlugin extends ConverterComponent {
296320 } ) ;
297321 }
298322
299- CommentPlugin . removeTags ( childComment , 'param' ) ;
323+ childComment ? .removeTags ( 'param' ) ;
300324 } ) ;
301325
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 ) ;
303333 }
304334 }
305335
306336 /**
307337 * 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.
308340 *
309341 * @param comment The comment that should be modified.
310342 * @param tagName The name of the that that should be removed.
311343 */
312344 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 ) ;
326346 }
327347
328348 /**
@@ -346,7 +366,7 @@ export class CommentPlugin extends ConverterComponent {
346366 }
347367
348368 /**
349- * Determins whether or not a reflection has been hidden
369+ * Determines whether or not a reflection has been hidden
350370 *
351371 * @param reflection Reflection to check if hidden
352372 */
0 commit comments