Skip to content

Commit 0273693

Browse files
committed
Exclude non-public nodes.
1 parent 001e749 commit 0273693

File tree

6 files changed

+352
-1
lines changed

6 files changed

+352
-1
lines changed

src/lib/converter/converter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
6868
})
6969
excludeNotExported!: boolean;
7070

71+
@Option({
72+
name: 'excludeNotDocumented',
73+
help: 'Prevent symbols that are not explicitly documented from appearing in the results.',
74+
type: ParameterType.Boolean
75+
})
76+
excludeNotDocumented!: boolean;
77+
7178
@Option({
7279
name: 'excludePrivate',
7380
help: 'Ignores private variables and methods',

src/lib/converter/factories/declaration.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as ts from 'typescript';
33
import { ContainerReflection, DeclarationReflection, ReflectionFlag, ReflectionKind } from '../../models/index';
44
import { Context } from '../context';
55
import { Converter } from '../converter';
6+
import { getRawComment } from './comment.js';
67
import { createReferenceType } from './reference';
78

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

72-
if (!isExported && context.converter.excludeNotExported) {
73+
const comment = getRawComment(node)
74+
const isPublic = comment && comment.includes('@public')
75+
if (
76+
(!isExported && context.converter.excludeNotExported)
77+
||
78+
(context.converter.excludeNotDocumented && kind !== ReflectionKind.EnumMember && !isPublic)
79+
) {
7380
return;
7481
}
7582

src/test/converter.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,39 @@ describe('Converter with excludeNotExported=true', function() {
151151
});
152152

153153
});
154+
155+
describe('Converter with excludeNotDocumented=true', function() {
156+
const base = Path.join(__dirname, 'converter');
157+
const fixtureDir = Path.join(base, 'exclude-not-documented');
158+
let app: Application;
159+
160+
before('constructs', function() {
161+
app = new Application({
162+
mode: 'Modules',
163+
logger: 'none',
164+
target: 'ES5',
165+
module: 'CommonJS',
166+
experimentalDecorators: true,
167+
excludeNotDocumented: true,
168+
jsx: 'react'
169+
});
170+
});
171+
172+
let result: ProjectReflection | undefined;
173+
174+
describe('Exclude not documented symbols', () => {
175+
it('converts fixtures', function() {
176+
resetReflectionID();
177+
result = app.convert(app.expandInputFiles([fixtureDir]));
178+
Assert(result instanceof ProjectReflection, 'No reflection returned');
179+
});
180+
181+
it('matches specs', function() {
182+
const specs = JSON.parse(FS.readFileSync(Path.join(fixtureDir, 'specs-without-undocumented.json')).toString());
183+
let data = JSON.stringify(result!.toObject(), null, ' ');
184+
data = data.split(normalizePath(base)).join('%BASE%');
185+
186+
compareReflections(JSON.parse(data), specs);
187+
});
188+
});
189+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const x = 5;
2+
3+
export function add(x: number, y: number) {
4+
return x + y;
5+
}
6+
7+
export function times(x: number, y: number) {
8+
return x * y;
9+
}
10+
11+
export class NotDocumented {
12+
some! : string
13+
}
14+
15+
export interface INotDocumented {
16+
some : string
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": 0,
3+
"name": "typedoc",
4+
"kind": 0,
5+
"flags": {}
6+
}
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
{
2+
"id": 0,
3+
"name": "typedoc",
4+
"kind": 0,
5+
"flags": {},
6+
"children": [
7+
{
8+
"id": 1,
9+
"name": "\"exclude-not-documented\"",
10+
"kind": 1,
11+
"kindString": "External module",
12+
"flags": {
13+
"isExported": true
14+
},
15+
"originalName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
16+
"children": [
17+
{
18+
"id": 2,
19+
"name": "NotDocumented",
20+
"kind": 128,
21+
"kindString": "Class",
22+
"flags": {
23+
"isExported": true
24+
},
25+
"children": [
26+
{
27+
"id": 3,
28+
"name": "some",
29+
"kind": 1024,
30+
"kindString": "Property",
31+
"flags": {
32+
"isExported": true
33+
},
34+
"sources": [
35+
{
36+
"fileName": "exclude-not-documented.ts",
37+
"line": 12,
38+
"character": 8
39+
}
40+
],
41+
"type": {
42+
"type": "intrinsic",
43+
"name": "string"
44+
}
45+
}
46+
],
47+
"groups": [
48+
{
49+
"title": "Properties",
50+
"kind": 1024,
51+
"children": [
52+
3
53+
]
54+
}
55+
],
56+
"sources": [
57+
{
58+
"fileName": "exclude-not-documented.ts",
59+
"line": 11,
60+
"character": 26
61+
}
62+
]
63+
},
64+
{
65+
"id": 4,
66+
"name": "INotDocumented",
67+
"kind": 256,
68+
"flags": {
69+
"isExported": true
70+
},
71+
"children": [
72+
{
73+
"id": 5,
74+
"name": "some",
75+
"kind": 1024,
76+
"flags": {
77+
"isExported": true
78+
},
79+
"sources": [
80+
{
81+
"fileName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
82+
"line": 16,
83+
"character": 8
84+
}
85+
],
86+
"type": {
87+
"type": "intrinsic",
88+
"name": "string"
89+
}
90+
}
91+
],
92+
"sources": [
93+
{
94+
"fileName": "%BASE%/exclude-not-documented/exclude-not-documented.ts",
95+
"line": 15,
96+
"character": 31
97+
}
98+
]
99+
},
100+
{
101+
"id": 6,
102+
"name": "x",
103+
"kind": 32,
104+
"kindString": "Variable",
105+
"flags": {
106+
"isExported": true,
107+
"isConst": true
108+
},
109+
"sources": [
110+
{
111+
"fileName": "exclude-not-documented.ts",
112+
"line": 1,
113+
"character": 14
114+
}
115+
],
116+
"type": {
117+
"type": "unknown",
118+
"name": "5"
119+
},
120+
"defaultValue": "5"
121+
},
122+
{
123+
"id": 7,
124+
"name": "add",
125+
"kind": 64,
126+
"kindString": "Function",
127+
"flags": {
128+
"isExported": true
129+
},
130+
"signatures": [
131+
{
132+
"id": 8,
133+
"name": "add",
134+
"kind": 4096,
135+
"kindString": "Call signature",
136+
"flags": {},
137+
"parameters": [
138+
{
139+
"id": 9,
140+
"name": "x",
141+
"kind": 32768,
142+
"kindString": "Parameter",
143+
"flags": {},
144+
"type": {
145+
"type": "intrinsic",
146+
"name": "number"
147+
}
148+
},
149+
{
150+
"id": 10,
151+
"name": "y",
152+
"kind": 32768,
153+
"kindString": "Parameter",
154+
"flags": {},
155+
"type": {
156+
"type": "intrinsic",
157+
"name": "number"
158+
}
159+
}
160+
],
161+
"type": {
162+
"type": "intrinsic",
163+
"name": "number"
164+
}
165+
}
166+
],
167+
"sources": [
168+
{
169+
"fileName": "exclude-not-documented.ts",
170+
"line": 3,
171+
"character": 19
172+
}
173+
]
174+
},
175+
{
176+
"id": 11,
177+
"name": "times",
178+
"kind": 64,
179+
"kindString": "Function",
180+
"flags": {
181+
"isExported": true
182+
},
183+
"signatures": [
184+
{
185+
"id": 12,
186+
"name": "times",
187+
"kind": 4096,
188+
"kindString": "Call signature",
189+
"flags": {},
190+
"parameters": [
191+
{
192+
"id": 13,
193+
"name": "x",
194+
"kind": 32768,
195+
"kindString": "Parameter",
196+
"flags": {},
197+
"type": {
198+
"type": "intrinsic",
199+
"name": "number"
200+
}
201+
},
202+
{
203+
"id": 14,
204+
"name": "y",
205+
"kind": 32768,
206+
"kindString": "Parameter",
207+
"flags": {},
208+
"type": {
209+
"type": "intrinsic",
210+
"name": "number"
211+
}
212+
}
213+
],
214+
"type": {
215+
"type": "intrinsic",
216+
"name": "number"
217+
}
218+
}
219+
],
220+
"sources": [
221+
{
222+
"fileName": "exclude-not-documented.ts",
223+
"line": 7,
224+
"character": 21
225+
}
226+
]
227+
}
228+
],
229+
"groups": [
230+
{
231+
"title": "Classes",
232+
"kind": 128,
233+
"children": [
234+
2
235+
]
236+
},
237+
{
238+
"title": "Interfaces",
239+
"kind": 256,
240+
"children": [
241+
4
242+
]
243+
},
244+
{
245+
"title": "Variables",
246+
"kind": 32,
247+
"children": [
248+
6
249+
]
250+
},
251+
{
252+
"title": "Functions",
253+
"kind": 64,
254+
"children": [
255+
7,
256+
11
257+
]
258+
}
259+
],
260+
"sources": [
261+
{
262+
"fileName": "exclude-not-documented.ts",
263+
"line": 1,
264+
"character": 0
265+
}
266+
]
267+
}
268+
],
269+
"groups": [
270+
{
271+
"title": "External modules",
272+
"kind": 1,
273+
"children": [
274+
1
275+
]
276+
}
277+
]
278+
}

0 commit comments

Comments
 (0)