Skip to content

Commit bcd9545

Browse files
Allow to hide reflections via @hidden tag, resolves #62
1 parent 6d9276d commit bcd9545

File tree

5 files changed

+167
-1
lines changed

5 files changed

+167
-1
lines changed

bin/typedoc.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,10 @@ declare module td {
502502
* List of discovered module comments.
503503
*/
504504
private comments;
505+
/**
506+
* List of hidden reflections.
507+
*/
508+
private hidden;
505509
/**
506510
* Create a new CommentPlugin instance.
507511
*
@@ -558,6 +562,10 @@ declare module td {
558562
* @param tagName The name of the that that should be removed.
559563
*/
560564
static removeTags(comment: Comment, tagName: string): void;
565+
/**
566+
* Remove the given reflection from the project.
567+
*/
568+
static removeReflection(project: ProjectReflection, reflection: Reflection): void;
561569
/**
562570
* Parse the given doc comment string.
563571
*

bin/typedoc.js

+71
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,11 @@ var td;
22052205
reflection.setFlag(4 /* Public */);
22062206
CommentPlugin.removeTags(comment, 'public');
22072207
}
2208+
if (comment.hasTag('hidden')) {
2209+
if (!this.hidden)
2210+
this.hidden = [];
2211+
this.hidden.push(reflection);
2212+
}
22082213
};
22092214
CommentPlugin.prototype.onFunctionImplementation = function (event) {
22102215
var comment = CommentPlugin.getComment(event.node);
@@ -2225,8 +2230,14 @@ var td;
22252230
var info = this.comments[id];
22262231
var comment = CommentPlugin.parseComment(info.fullText);
22272232
CommentPlugin.removeTags(comment, 'preferred');
2233+
this.applyAccessModifiers(info.reflection, comment);
22282234
info.reflection.comment = comment;
22292235
}
2236+
if (this.hidden) {
2237+
this.hidden.forEach(function (reflection) {
2238+
CommentPlugin.removeReflection(event.getProject(), reflection);
2239+
});
2240+
}
22302241
};
22312242
/**
22322243
* Triggered when the dispatcher resolves a reflection.
@@ -2351,6 +2362,66 @@ var td;
23512362
}
23522363
}
23532364
};
2365+
/**
2366+
* Remove the given reflection from the project.
2367+
*/
2368+
CommentPlugin.removeReflection = function (project, reflection) {
2369+
reflection.traverse(function (child) { return CommentPlugin.removeReflection(project, child); });
2370+
var parent = reflection.parent;
2371+
parent.traverse(function (child, property) {
2372+
if (child == reflection) {
2373+
switch (property) {
2374+
case 0 /* Children */:
2375+
if (parent.children) {
2376+
var index = parent.children.indexOf(reflection);
2377+
if (index != -1)
2378+
parent.children.splice(index, 1);
2379+
}
2380+
break;
2381+
case 6 /* GetSignature */:
2382+
delete parent.getSignature;
2383+
break;
2384+
case 5 /* IndexSignature */:
2385+
delete parent.indexSignature;
2386+
break;
2387+
case 1 /* Parameters */:
2388+
if (reflection.parent.parameters) {
2389+
var index = reflection.parent.parameters.indexOf(reflection);
2390+
if (index != -1)
2391+
reflection.parent.parameters.splice(index, 1);
2392+
}
2393+
break;
2394+
case 7 /* SetSignature */:
2395+
delete parent.setSignature;
2396+
break;
2397+
case 4 /* Signatures */:
2398+
if (parent.signatures) {
2399+
var index = parent.signatures.indexOf(reflection);
2400+
if (index != -1)
2401+
parent.signatures.splice(index, 1);
2402+
}
2403+
break;
2404+
case 2 /* TypeLiteral */:
2405+
parent.type = new td.IntrinsicType('Object');
2406+
break;
2407+
case 3 /* TypeParameter */:
2408+
if (parent.typeParameters) {
2409+
var index = parent.typeParameters.indexOf(reflection);
2410+
if (index != -1)
2411+
parent.typeParameters.splice(index, 1);
2412+
}
2413+
break;
2414+
}
2415+
}
2416+
});
2417+
var id = reflection.id;
2418+
delete project.reflections[id];
2419+
for (var key in project.symbolMapping) {
2420+
if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] == id) {
2421+
delete project.symbolMapping[key];
2422+
}
2423+
}
2424+
};
23542425
/**
23552426
* Parse the given doc comment string.
23562427
*

examples/basic/src/access.ts

+9
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ export class PrivateClass
5151
* @protected
5252
*/
5353
fakeProtectedFunction() {}
54+
}
55+
56+
/**
57+
* A module that is documented as being private.
58+
* @private
59+
*/
60+
export module PrivateModule
61+
{
62+
export function functionInsidePrivateModule() {}
5463
}

examples/basic/src/modules.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
/**
6-
* This is a module. Unfortunately TypeScript does not parse comments above modules.
6+
* This is a module.
77
*/
88
export module MyModule
99
{

src/td/converter/plugins/CommentPlugin.ts

+78
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module td
3333
*/
3434
private comments:{[id:number]:IModuleComment};
3535

36+
/**
37+
* List of hidden reflections.
38+
*/
39+
private hidden:Reflection[];
40+
3641

3742
/**
3843
* Create a new CommentPlugin instance.
@@ -134,6 +139,11 @@ module td
134139
reflection.setFlag(ReflectionFlag.Public);
135140
CommentPlugin.removeTags(comment, 'public');
136141
}
142+
143+
if (comment.hasTag('hidden')) {
144+
if (!this.hidden) this.hidden = [];
145+
this.hidden.push(reflection);
146+
}
137147
}
138148

139149

@@ -160,8 +170,15 @@ module td
160170
var comment = CommentPlugin.parseComment(info.fullText);
161171
CommentPlugin.removeTags(comment, 'preferred');
162172

173+
this.applyAccessModifiers(info.reflection, comment);
163174
info.reflection.comment = comment;
164175
}
176+
177+
if (this.hidden) {
178+
this.hidden.forEach((reflection) => {
179+
CommentPlugin.removeReflection(event.getProject(), reflection);
180+
});
181+
}
165182
}
166183

167184

@@ -300,6 +317,67 @@ module td
300317
}
301318

302319

320+
/**
321+
* Remove the given reflection from the project.
322+
*/
323+
static removeReflection(project:ProjectReflection, reflection:Reflection) {
324+
reflection.traverse((child) => CommentPlugin.removeReflection(project, child));
325+
326+
var parent = <DeclarationReflection>reflection.parent;
327+
parent.traverse((child:Reflection, property:TraverseProperty) => {
328+
if (child == reflection) {
329+
switch (property) {
330+
case TraverseProperty.Children:
331+
if (parent.children) {
332+
var index = parent.children.indexOf(<DeclarationReflection>reflection);
333+
if (index != -1) parent.children.splice(index, 1);
334+
}
335+
break;
336+
case TraverseProperty.GetSignature:
337+
delete parent.getSignature;
338+
break;
339+
case TraverseProperty.IndexSignature:
340+
delete parent.indexSignature;
341+
break;
342+
case TraverseProperty.Parameters:
343+
if ((<SignatureReflection>reflection.parent).parameters) {
344+
var index = (<SignatureReflection>reflection.parent).parameters.indexOf(<ParameterReflection>reflection);
345+
if (index != -1) (<SignatureReflection>reflection.parent).parameters.splice(index, 1);
346+
}
347+
break;
348+
case TraverseProperty.SetSignature:
349+
delete parent.setSignature;
350+
break;
351+
case TraverseProperty.Signatures:
352+
if (parent.signatures) {
353+
var index = parent.signatures.indexOf(<SignatureReflection>reflection);
354+
if (index != -1) parent.signatures.splice(index, 1);
355+
}
356+
break;
357+
case TraverseProperty.TypeLiteral:
358+
parent.type = new IntrinsicType('Object');
359+
break;
360+
case TraverseProperty.TypeParameter:
361+
if (parent.typeParameters) {
362+
var index = parent.typeParameters.indexOf(<TypeParameterReflection>reflection);
363+
if (index != -1) parent.typeParameters.splice(index, 1);
364+
}
365+
break;
366+
}
367+
}
368+
});
369+
370+
var id = reflection.id;
371+
delete project.reflections[id];
372+
373+
for (var key in project.symbolMapping) {
374+
if (project.symbolMapping.hasOwnProperty(key) && project.symbolMapping[key] == id) {
375+
delete project.symbolMapping[key];
376+
}
377+
}
378+
}
379+
380+
303381
/**
304382
* Parse the given doc comment string.
305383
*

0 commit comments

Comments
 (0)