@@ -17,21 +17,30 @@ export interface DocEntry {
1717interface EntryContext {
1818 program : ts . Program ;
1919 checker : ts . TypeChecker ;
20- options : GenerateOptions ;
20+ transform ?: Transformer ;
2121 type : ts . Type ;
2222 symbol : ts . Symbol ;
2323}
2424
25+ type Transformer = (
26+ this : EntryContext ,
27+ entry : DocEntry ,
28+ propertyType : ts . Type ,
29+ propertySymbol : ts . Symbol ,
30+ ) => void ;
31+
2532export interface GenerateOptions {
33+ /**
34+ * Allow fields with `@internal` tag
35+ *
36+ * @defaultValue false
37+ */
38+ allowInternal ?: boolean ;
39+
2640 /**
2741 * Modify output property entry
2842 */
29- transform ?: (
30- this : EntryContext ,
31- entry : DocEntry ,
32- propertyType : ts . Type ,
33- propertySymbol : ts . Symbol ,
34- ) => void ;
43+ transform ?: Transformer ;
3544}
3645
3746export interface GenerateDocumentationOptions extends GenerateOptions {
@@ -66,13 +75,13 @@ export function generateDocumentation(
6675export function generate (
6776 program : ts . Program ,
6877 symbol : ts . Symbol ,
69- options : GenerateOptions ,
78+ { allowInternal = false , transform } : GenerateOptions ,
7079) : GeneratedDoc {
7180 const checker = program . getTypeChecker ( ) ;
7281 const type = checker . getDeclaredTypeOfSymbol ( symbol ) ;
7382 const entryContext : EntryContext = {
7483 checker,
75- options ,
84+ transform ,
7685 program,
7786 type,
7887 symbol,
@@ -85,12 +94,13 @@ export function generate(
8594 ) ,
8695 entries : type
8796 . getProperties ( )
88- . map ( ( prop ) => getDocEntry ( prop , entryContext ) ) ,
97+ . map ( ( prop ) => getDocEntry ( prop , entryContext ) )
98+ . filter ( ( entry ) => allowInternal || ! ( 'internal' in entry . tags ) ) ,
8999 } ;
90100}
91101
92102function getDocEntry ( prop : ts . Symbol , context : EntryContext ) : DocEntry {
93- const { checker, options } = context ;
103+ const { checker, transform } = context ;
94104 const subType = checker . getTypeOfSymbol ( prop ) ;
95105 const tags = Object . fromEntries (
96106 prop
@@ -119,7 +129,7 @@ function getDocEntry(prop: ts.Symbol, context: EntryContext): DocEntry {
119129 type : typeName ,
120130 } ;
121131
122- options . transform ?. call ( context , entry , subType , prop ) ;
132+ transform ?. call ( context , entry , subType , prop ) ;
123133
124134 return entry ;
125135}
0 commit comments