Skip to content

Commit

Permalink
Implemented '--excludeProtected' option similar to the '--excludePriv… (
Browse files Browse the repository at this point in the history
#666)

Implemented '--excludeProtected' option similar to the '--excludePrivate' option.
  • Loading branch information
shabbir-genetech authored and aciccarello committed Dec 31, 2017
1 parent e9b866e commit 32bf528
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -67,6 +67,8 @@ in order to change the behaviour of TypeDoc.
Prevent externally resolved TypeScript files from being documented.
* `--excludePrivate`<br>
Prevent private members from being included in the generated documentation.
* `--excludeProtected`<br>
Prevent protected members from being included in the generated documentation.

#### TypeScript compiler
* `--module <commonjs, amd, system or umd>`<br>
Expand Down
7 changes: 7 additions & 0 deletions src/lib/converter/converter.ts
Expand Up @@ -74,6 +74,13 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
})
excludePrivate: boolean;

@Option({
name: 'excludeProtected',
help: 'Ignores protected variables and methods',
type: ParameterType.Boolean
})
excludeProtected: boolean;

private compilerHost: CompilerHost;

private nodeConverters: {[syntaxKind: number]: ConverterNodeComponent<ts.Node>};
Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/nodes/class.ts
Expand Up @@ -40,7 +40,9 @@ export class ClassConverter extends ConverterNodeComponent<ts.ClassDeclaration>
node.members.forEach((member) => {
const modifiers = ts.getCombinedModifierFlags(member);
const privateMember = (modifiers & ts.ModifierFlags.Private) > 0;
const exclude = context.converter.excludePrivate ? privateMember : false;
const protectedMember = (modifiers & ts.ModifierFlags.Protected) > 0;
const exclude = (context.converter.excludePrivate && privateMember)
|| (context.converter.excludeProtected && protectedMember);

if (!exclude) {
this.owner.convertNode(context, member);
Expand Down
5 changes: 5 additions & 0 deletions src/lib/converter/nodes/constructor.ts
Expand Up @@ -73,6 +73,11 @@ export class ConstructorConverter extends ConverterNodeComponent<ts.ConstructorD
return;
}

const protectedParameter = modifiers & ts.ModifierFlags.Protected;
if (protectedParameter && context.converter.excludeProtected) {
return;
}

const property = createDeclaration(context, parameter, ReflectionKind.Property);
if (!property) {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/test/renderer/specs/index.html
Expand Up @@ -118,6 +118,8 @@ <h4 id="source-file-handling">Source file handling</h4>
Prevent externally resolved TypeScript files from being documented.</li>
<li><code>--excludePrivate</code><br>
Prevent private members from being included in the generated documentation.</li>
<li><code>--excludeProtected</code><br>
Prevent protected members from being included in the generated documentation.</li>
</ul>
<h4 id="typescript-compiler">TypeScript compiler</h4>
<ul>
Expand Down

0 comments on commit 32bf528

Please sign in to comment.