Skip to content

Commit

Permalink
Merge branch 'pr/1169'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jan 14, 2020
2 parents 9ac6973 + 99d738f commit 1c89283
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 28 deletions.
57 changes: 35 additions & 22 deletions src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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');
}
Expand All @@ -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 = {};
}

Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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)
);
}
}
36 changes: 36 additions & 0 deletions src/test/converter/comment/comment.ts
Expand Up @@ -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
*/
Expand Down
91 changes: 85 additions & 6 deletions src/test/converter/comment/specs.json
Expand Up @@ -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": [
Expand All @@ -71,6 +143,13 @@
"children": [
8
]
},
{
"title": "Methods",
"kind": 2048,
"children": [
22
]
}
],
"sources": [
Expand All @@ -82,7 +161,7 @@
]
},
{
"id": 11,
"id": 29,
"name": "gh1164",
"kind": 64,
"kindString": "Function",
Expand All @@ -91,7 +170,7 @@
},
"signatures": [
{
"id": 12,
"id": 30,
"name": "gh1164",
"kind": 4096,
"kindString": "Call signature",
Expand All @@ -104,7 +183,7 @@
},
"parameters": [
{
"id": 13,
"id": 31,
"name": "scope",
"kind": 32768,
"kindString": "Parameter",
Expand All @@ -129,7 +208,7 @@
"sources": [
{
"fileName": "comment.ts",
"line": 52,
"line": 88,
"character": 22
}
]
Expand All @@ -147,7 +226,7 @@
"title": "Functions",
"kind": 64,
"children": [
11
29
]
}
],
Expand Down Expand Up @@ -260,4 +339,4 @@
]
}
]
}
}

0 comments on commit 1c89283

Please sign in to comment.