Skip to content

Commit

Permalink
Exclude non-public nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVann committed Mar 29, 2019
1 parent 001e749 commit 0273693
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
})
excludeNotExported!: boolean;

@Option({
name: 'excludeNotDocumented',
help: 'Prevent symbols that are not explicitly documented from appearing in the results.',
type: ParameterType.Boolean
})
excludeNotDocumented!: boolean;

@Option({
name: 'excludePrivate',
help: 'Ignores private variables and methods',
Expand Down
9 changes: 8 additions & 1 deletion src/lib/converter/factories/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as ts from 'typescript';
import { ContainerReflection, DeclarationReflection, ReflectionFlag, ReflectionKind } from '../../models/index';
import { Context } from '../context';
import { Converter } from '../converter';
import { getRawComment } from './comment.js';
import { createReferenceType } from './reference';

/**
Expand Down Expand Up @@ -69,7 +70,13 @@ export function createDeclaration(context: Context, node: ts.Declaration, kind:
isExported = isExported || !!(modifiers & ts.ModifierFlags.Export);
}

if (!isExported && context.converter.excludeNotExported) {
const comment = getRawComment(node)
const isPublic = comment && comment.includes('@public')
if (
(!isExported && context.converter.excludeNotExported)
||
(context.converter.excludeNotDocumented && kind !== ReflectionKind.EnumMember && !isPublic)
) {
return;
}

Expand Down
36 changes: 36 additions & 0 deletions src/test/converter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,39 @@ describe('Converter with excludeNotExported=true', function() {
});

});

describe('Converter with excludeNotDocumented=true', function() {
const base = Path.join(__dirname, 'converter');
const fixtureDir = Path.join(base, 'exclude-not-documented');
let app: Application;

before('constructs', function() {
app = new Application({
mode: 'Modules',
logger: 'none',
target: 'ES5',
module: 'CommonJS',
experimentalDecorators: true,
excludeNotDocumented: true,
jsx: 'react'
});
});

let result: ProjectReflection | undefined;

describe('Exclude not documented symbols', () => {
it('converts fixtures', function() {
resetReflectionID();
result = app.convert(app.expandInputFiles([fixtureDir]));
Assert(result instanceof ProjectReflection, 'No reflection returned');
});

it('matches specs', function() {
const specs = JSON.parse(FS.readFileSync(Path.join(fixtureDir, 'specs-without-undocumented.json')).toString());
let data = JSON.stringify(result!.toObject(), null, ' ');
data = data.split(normalizePath(base)).join('%BASE%');

compareReflections(JSON.parse(data), specs);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const x = 5;

export function add(x: number, y: number) {
return x + y;
}

export function times(x: number, y: number) {
return x * y;
}

export class NotDocumented {
some! : string
}

export interface INotDocumented {
some : string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": 0,
"name": "typedoc",
"kind": 0,
"flags": {}
}
278 changes: 278 additions & 0 deletions src/test/converter/exclude-not-documented/specs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
{
"id": 0,
"name": "typedoc",
"kind": 0,
"flags": {},
"children": [
{
"id": 1,
"name": "\"exclude-not-documented\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
"children": [
{
"id": 2,
"name": "NotDocumented",
"kind": 128,
"kindString": "Class",
"flags": {
"isExported": true
},
"children": [
{
"id": 3,
"name": "some",
"kind": 1024,
"kindString": "Property",
"flags": {
"isExported": true
},
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 12,
"character": 8
}
],
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"groups": [
{
"title": "Properties",
"kind": 1024,
"children": [
3
]
}
],
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 11,
"character": 26
}
]
},
{
"id": 4,
"name": "INotDocumented",
"kind": 256,
"flags": {
"isExported": true
},
"children": [
{
"id": 5,
"name": "some",
"kind": 1024,
"flags": {
"isExported": true
},
"sources": [
{
"fileName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
"line": 16,
"character": 8
}
],
"type": {
"type": "intrinsic",
"name": "string"
}
}
],
"sources": [
{
"fileName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
"line": 15,
"character": 31
}
]
},
{
"id": 6,
"name": "x",
"kind": 32,
"kindString": "Variable",
"flags": {
"isExported": true,
"isConst": true
},
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 1,
"character": 14
}
],
"type": {
"type": "unknown",
"name": "5"
},
"defaultValue": "5"
},
{
"id": 7,
"name": "add",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 8,
"name": "add",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 9,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 10,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 3,
"character": 19
}
]
},
{
"id": 11,
"name": "times",
"kind": 64,
"kindString": "Function",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 12,
"name": "times",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 13,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 14,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 7,
"character": 21
}
]
}
],
"groups": [
{
"title": "Classes",
"kind": 128,
"children": [
2
]
},
{
"title": "Interfaces",
"kind": 256,
"children": [
4
]
},
{
"title": "Variables",
"kind": 32,
"children": [
6
]
},
{
"title": "Functions",
"kind": 64,
"children": [
7,
11
]
}
],
"sources": [
{
"fileName": "exclude-not-documented.ts",
"line": 1,
"character": 0
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
1
]
}
]
}

0 comments on commit 0273693

Please sign in to comment.