diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index e386feee8..7cbd9a38b 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -46,11 +46,6 @@ export class CommentPlugin extends ConverterComponent { */ private comments!: {[id: number]: ModuleComment}; - /** - * List of hidden reflections. - */ - private hidden?: Reflection[]; - /** * Create a new CommentPlugin instance. */ @@ -114,16 +109,6 @@ export class CommentPlugin extends ConverterComponent { CommentPlugin.removeTags(comment, 'event'); } - if (comment.hasTag('hidden') - || comment.hasTag('ignore') - || (comment.hasTag('internal') && this.application.options.getCompilerOptions().stripInternal) - ) { - if (!this.hidden) { - this.hidden = []; - } - this.hidden.push(reflection); - } - if (reflection.kindOf(ReflectionKind.ExternalModule)) { CommentPlugin.removeTags(comment, 'packagedocumentation'); } @@ -135,7 +120,6 @@ export class CommentPlugin extends ConverterComponent { * @param context The context object describing the current state the converter is in. */ private onBegin(context: Context) { - this.hidden = undefined; this.comments = {}; } @@ -232,12 +216,22 @@ export class CommentPlugin extends ConverterComponent { info.reflection.comment = comment; } - if (this.hidden) { - const project = context.project; - for (const reflection of this.hidden) { - project.removeReflection(reflection, true); - } - } + const stripInternal = this.application.options.getCompilerOptions().stripInternal; + + const project = context.project; + const reflections = Object.values(project.reflections); + + // remove signatures + const hidden = reflections.filter(reflection => CommentPlugin.isHidden(reflection, stripInternal)); + hidden.forEach(reflection => project.removeReflection(reflection, true)); + + // remove functions with empty signatures after their signatures have been removed + const hiddenMethods = hidden.map(reflection => reflection.parent!) + .filter(method => + method.kindOf(ReflectionKind.FunctionOrMethod) + && method instanceof DeclarationReflection + && method.signatures?.length === 0); + hiddenMethods.forEach(reflection => project.removeReflection(reflection, true)); } /** @@ -345,4 +339,23 @@ export class CommentPlugin extends ConverterComponent { static removeReflection(project: ProjectReflection, reflection: Reflection) { project.removeReflection(reflection, true); } + + /** + * Determins whether or not a reflection has been hidden + * + * @param reflection Reflection to check if hidden + */ + private static isHidden(reflection: Reflection, stripInternal: boolean | undefined) { + const comment = reflection.comment; + + if (!comment) { + return false; + } + + return ( + comment.hasTag('hidden') + || comment.hasTag('ignore') + || (comment.hasTag('internal') && stripInternal) + ); + } } diff --git a/src/test/converter/comment/comment.ts b/src/test/converter/comment/comment.ts index af47b5852..fd4606841 100644 --- a/src/test/converter/comment/comment.ts +++ b/src/test/converter/comment/comment.ts @@ -38,6 +38,42 @@ export class CommentedClass { */ hiddenprop: string; + /** + * Hidden function + * @hidden + */ + hidden(...args: any[]): void {} + + /** + * Single hidden signature + * @hidden + */ + hiddenWithImplementation(arg: any); + hiddenWithImplementation(...args: any[]): void {} + + /** + * Multiple hidden 1 + * @hidden + */ + multipleHidden(arg: any); + /** + * Multiple hidden 2 + * @hidden + */ + multipleHidden(arg1: any, arg2: any); + multipleHidden(...args: any[]): void {} + + /** + * Mixed hidden 1 + * @hidden + */ + mixedHidden(arg: any); + /** + * Mixed hidden 2 + */ + mixedHidden(arg1: any, arg2: any); + mixedHidden(...args: any[]): void {} + /** * @ignore */ diff --git a/src/test/converter/comment/specs.json b/src/test/converter/comment/specs.json index 9e20563e6..25b01a784 100644 --- a/src/test/converter/comment/specs.json +++ b/src/test/converter/comment/specs.json @@ -62,6 +62,78 @@ "type": "intrinsic", "name": "string" } + }, + { + "id": 22, + "name": "mixedHidden", + "kind": 2048, + "kindString": "Method", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 25, + "name": "mixedHidden", + "kind": 4096, + "kindString": "Call signature", + "flags": { + "isExported": true + }, + "comment": { + "shortText": "Mixed hidden 2" + }, + "parameters": [ + { + "id": 26, + "name": "arg1", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isExported": true + }, + "type": { + "type": "intrinsic", + "name": "any" + } + }, + { + "id": 27, + "name": "arg2", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isExported": true + }, + "type": { + "type": "intrinsic", + "name": "any" + } + } + ], + "type": { + "type": "intrinsic", + "name": "any" + } + } + ], + "sources": [ + { + "fileName": "comment.ts", + "line": 70, + "character": 13 + }, + { + "fileName": "comment.ts", + "line": 74, + "character": 13 + }, + { + "fileName": "comment.ts", + "line": 75, + "character": 13 + } + ] } ], "groups": [ @@ -71,6 +143,13 @@ "children": [ 8 ] + }, + { + "title": "Methods", + "kind": 2048, + "children": [ + 22 + ] } ], "sources": [ @@ -82,7 +161,7 @@ ] }, { - "id": 11, + "id": 29, "name": "gh1164", "kind": 64, "kindString": "Function", @@ -91,7 +170,7 @@ }, "signatures": [ { - "id": 12, + "id": 30, "name": "gh1164", "kind": 4096, "kindString": "Call signature", @@ -104,7 +183,7 @@ }, "parameters": [ { - "id": 13, + "id": 31, "name": "scope", "kind": 32768, "kindString": "Parameter", @@ -129,7 +208,7 @@ "sources": [ { "fileName": "comment.ts", - "line": 52, + "line": 88, "character": 22 } ] @@ -147,7 +226,7 @@ "title": "Functions", "kind": 64, "children": [ - 11 + 29 ] } ], @@ -260,4 +339,4 @@ ] } ] -} \ No newline at end of file +}