Skip to content

Commit 1009206

Browse files
committed
Implement excludePrivateClassFields
resolves #3017
1 parent a85a65b commit 1009206

File tree

14 files changed

+68
-6
lines changed

14 files changed

+68
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ title: Changelog
99
- Introduced the `preservedTypeAnnotationTags` option to specify tags whose type annotations should
1010
be copied to the output documentation, #3020.
1111
API: Introduced `typeAnnotation` on `CommentTag`
12+
- Added `excludePrivateClassFields` option to hide `#private` members while allowing `private` members, #3017.
1213

1314
## Bug Fixes
1415

site/options/input.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,16 @@ Removes symbols annotated with the `@internal` doc tag. Defaults to true if the
215215
typedoc --excludePrivate
216216
```
217217

218-
Removes private class members from the generated documentation. Defaults to true.
218+
Removes members marked with `private` and `#private` class fields from the generated documentation. Defaults to true.
219+
To include `#private` class fields both this option and [excludePrivateClassFields](#excludeprivateclassfields) must be set to `false`.
220+
221+
## excludePrivateClassFields
222+
223+
```bash
224+
typedoc --excludePrivateClassFields
225+
```
226+
227+
Removes `#private` class fields from the generated documentation. Defaults to true.
219228

220229
## excludeProtected
221230

site/options/package-options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ at the root level. The following tables indicate where an option should be set.
4141
| [`excludeNotDocumentedKinds`](input.md#excludenotdocumentedkinds) | Package | |
4242
| [`excludeInternal`](input.md#excludeinternal) | Package | |
4343
| [`excludePrivate`](input.md#excludeprivate) | Package | |
44+
| [`excludePrivateClassFields`](input.md#excludeprivateclassfields) | Package | |
4445
| [`excludeProtected`](input.md#excludeprotected) | Package | |
4546
| [`excludeReferences`](input.md#excludereferences) | Package | |
4647
| [`excludeCategories`](input.md#excludecategories) | Package | |

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export class CommentPlugin extends ConverterComponent {
134134
@Option("excludePrivate")
135135
accessor excludePrivate!: boolean;
136136

137+
@Option("excludePrivateClassFields")
138+
accessor excludePrivateClassFields!: boolean;
139+
137140
@Option("excludeProtected")
138141
accessor excludeProtected!: boolean;
139142

@@ -567,6 +570,19 @@ export class CommentPlugin extends ConverterComponent {
567570
return true;
568571
}
569572

573+
// #3017 this isn't quite right as it may incorrectly detect
574+
// private members named with a hash which aren't actually private
575+
// class fields (e.g. class Foo { "#hash" = 1 })
576+
// We can't fix this without storing more information about the name,
577+
// which I'm going to put off until #3015 is done.
578+
if (
579+
reflection.flags.hasFlag(ReflectionFlag.Private) &&
580+
reflection.name.startsWith("#") &&
581+
this.excludePrivateClassFields
582+
) {
583+
return true;
584+
}
585+
570586
if (
571587
reflection.flags.hasFlag(ReflectionFlag.Protected) &&
572588
this.excludeProtected

src/lib/internationalization/locales/de.cts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ export = localeUtils.buildIncompleteTranslation({
284284
help_excludeNotDocumentedKinds: "Arten von Reflections, die von excludeNotDocumented entfernt werden können",
285285
help_excludeInternal: "Verhindert, dass Symbole in der Dokumentation erscheinen, die mit @internal markiert sind",
286286
help_excludeCategories: "Schließt Symbole aus dieser Kategorie von der Dokumentation aus",
287-
help_excludePrivate: "Ignoriert private Variablen und Methoden, Standardwert ist true.",
288287
help_excludeProtected: "Ignoriert geschützte Variablen und Methoden",
289288
help_excludeReferences: "Wird ein Symbol mehrfach exportiert, ignoriere alle außer dem ersten Export",
290289
help_externalSymbolLinkMappings:

src/lib/internationalization/locales/en.cts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export = {
276276
help_excludeNotDocumentedKinds: "Specify the type of reflections that can be removed by excludeNotDocumented",
277277
help_excludeInternal: "Prevent symbols that are marked with @internal from being documented",
278278
help_excludeCategories: "Exclude symbols within this category from the documentation",
279-
help_excludePrivate: "Ignore private variables and methods, defaults to true.",
279+
help_excludePrivate: "Ignore members marked with the private keyword and #private class fields, defaults to true.",
280+
help_excludePrivateClassFields: "Ignore #private class fields, defaults to true.",
280281
help_excludeProtected: "Ignore protected variables and methods",
281282
help_excludeReferences: "If a symbol is exported multiple times, ignore all but the first export",
282283
help_externalSymbolLinkMappings: "Define custom links for symbols not included in the documentation",

src/lib/internationalization/locales/ja.cts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ export = localeUtils.buildIncompleteTranslation({
194194
help_excludeNotDocumentedKinds: "excludeNotDocumented によって削除できる反射の種類を指定します",
195195
help_excludeInternal: "@internal でマークされたシンボルがドキュメント化されないようにする",
196196
help_excludeCategories: "このカテゴリ内のシンボルをドキュメントから除外する",
197-
help_excludePrivate: "プライベート変数とメソッドを無視します。デフォルトは true です。",
198197
help_excludeProtected: "保護された変数とメソッドを無視する",
199198
help_excludeReferences: "シンボルが複数回エクスポートされた場合、最初のエクスポート以外はすべて無視されます。",
200199
help_externalSymbolLinkMappings: "ドキュメントに含まれていないシンボルのカスタムリンクを定義する",

src/lib/internationalization/locales/ko.cts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export = localeUtils.buildIncompleteTranslation({
6262
help_excludeNotDocumentedKinds: "excludeNotDocumented로 제거될 리플렉션 유형을 지정합니다",
6363
help_excludeInternal: "@internal로 표시된 심볼이 문서화되지 않도록 방지합니다",
6464
help_excludeCategories: "문서에서 제외할 카테고리 내의 심볼을 제외합니다",
65-
help_excludePrivate: "비공개 변수와 메서드를 무시합니다. 기본값은 true입니다.",
6665
help_excludeProtected: "보호된 변수와 메서드를 무시합니다",
6766
help_excludeReferences: "심볼이 여러 번 내보내진 경우 첫 번째 내보내기를 제외하고 모두 무시합니다",
6867
help_externalSymbolLinkMappings: "문서에 포함되지 않은 심볼에 대한 사용자 정의 링크를 정의합니다",

src/lib/internationalization/locales/zh.cts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ export = localeUtils.buildIncompleteTranslation({
233233
help_excludeNotDocumentedKinds: "指定可以通过 excludeNotDocumented 删除的反射类型",
234234
help_excludeInternal: "防止标有 @internal 的符号被记录",
235235
help_excludeCategories: "从文档中排除此类别中的符号",
236-
help_excludePrivate: "忽略私有变量和方法,默认为 true。",
237236
help_excludeProtected: "忽略受保护的变量和方法",
238237
help_excludeReferences: "如果一个符号被导出多次,则忽略除第一次导出之外的所有导出",
239238
help_externalSymbolLinkMappings: "为文档中未包含的符号定义自定义链接",

src/lib/utils/options/declaration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export interface TypeDocOptionMap {
207207
excludeNotDocumented: boolean;
208208
excludeNotDocumentedKinds: ReflectionKind.KindString[];
209209
excludeInternal: boolean;
210+
excludePrivateClassFields: boolean;
210211
excludePrivate: boolean;
211212
excludeProtected: boolean;
212213
excludeReferences: boolean;

0 commit comments

Comments
 (0)