@@ -22,6 +22,19 @@ import type { AstModuleExportInfo } from '../analyzer/AstModule';
22
22
import { SourceFileLocationFormatter } from '../analyzer/SourceFileLocationFormatter' ;
23
23
import { ExtractorMessageId } from '../api/ExtractorMessageId' ;
24
24
25
+ /**
26
+ * Options for {@link ApiReportGenerator.generateReviewFileContent}.
27
+ */
28
+ export interface IApiReportOptions {
29
+ /**
30
+ * The release level with which the report is associated.
31
+ * Can also be viewed as the minimal release level of items that should be included in the report.
32
+ *
33
+ * @defaultValue Include everything. I.e. {@link ReleaseTag.Internal}.
34
+ */
35
+ readonly releaseLevel ?: Omit < ReleaseTag , ReleaseTag . None > ;
36
+ }
37
+
25
38
export class ApiReportGenerator {
26
39
private static _trimSpacesRegExp : RegExp = / + $ / gm;
27
40
@@ -42,10 +55,12 @@ export class ApiReportGenerator {
42
55
return normalizedActual === normalizedExpected ;
43
56
}
44
57
45
- public static generateReviewFileContent ( collector : Collector ) : string {
58
+ public static generateReviewFileContent ( collector : Collector , options ?: IApiReportOptions ) : string {
46
59
const writer : IndentedWriter = new IndentedWriter ( ) ;
47
60
writer . trimLeadingSpaces = true ;
48
61
62
+ const releaseLevel : ReleaseTag = ( options ?. releaseLevel as ReleaseTag ) ?? ReleaseTag . Internal ;
63
+
49
64
writer . writeLine (
50
65
[
51
66
`## API Report File for "${ collector . workingPackage . name } "` ,
@@ -128,7 +143,7 @@ export class ApiReportGenerator {
128
143
if ( apiItemMetadata . isPreapproved ) {
129
144
ApiReportGenerator . _modifySpanForPreapproved ( span ) ;
130
145
} else {
131
- ApiReportGenerator . _modifySpan ( collector , span , entity , astDeclaration , false ) ;
146
+ ApiReportGenerator . _modifySpan ( collector , span , entity , astDeclaration , false , releaseLevel ) ;
132
147
}
133
148
134
149
span . writeModifiedText ( writer ) ;
@@ -255,11 +270,12 @@ export class ApiReportGenerator {
255
270
span : Span ,
256
271
entity : CollectorEntity ,
257
272
astDeclaration : AstDeclaration ,
258
- insideTypeLiteral : boolean
273
+ insideTypeLiteral : boolean ,
274
+ releaseLevel : ReleaseTag
259
275
) : void {
260
276
// Should we process this declaration at all?
261
277
// eslint-disable-next-line no-bitwise
262
- if ( ! ApiReportGenerator . _shouldIncludeInReport ( astDeclaration ) ) {
278
+ if ( ! ApiReportGenerator . _shouldIncludeInReport ( collector , astDeclaration , releaseLevel ) ) {
263
279
span . modification . skipAll ( ) ;
264
280
return ;
265
281
}
@@ -385,7 +401,8 @@ export class ApiReportGenerator {
385
401
childSpan ,
386
402
entity ,
387
403
childAstDeclaration ,
388
- insideTypeLiteral
404
+ insideTypeLiteral ,
405
+ releaseLevel
389
406
) ;
390
407
}
391
408
) ;
@@ -402,7 +419,7 @@ export class ApiReportGenerator {
402
419
astDeclaration
403
420
) ;
404
421
405
- if ( ApiReportGenerator . _shouldIncludeInReport ( childAstDeclaration ) ) {
422
+ if ( ApiReportGenerator . _shouldIncludeInReport ( collector , childAstDeclaration , releaseLevel ) ) {
406
423
if ( sortChildren ) {
407
424
span . modification . sortChildren = true ;
408
425
child . modification . sortKey = Collector . getSortKeyIgnoringUnderscore (
@@ -426,15 +443,35 @@ export class ApiReportGenerator {
426
443
}
427
444
}
428
445
429
- ApiReportGenerator . _modifySpan ( collector , child , entity , childAstDeclaration , insideTypeLiteral ) ;
446
+ ApiReportGenerator . _modifySpan (
447
+ collector ,
448
+ child ,
449
+ entity ,
450
+ childAstDeclaration ,
451
+ insideTypeLiteral ,
452
+ releaseLevel
453
+ ) ;
430
454
}
431
455
}
432
456
}
433
457
434
- private static _shouldIncludeInReport ( astDeclaration : AstDeclaration ) : boolean {
458
+ private static _shouldIncludeInReport (
459
+ collector : Collector ,
460
+ astDeclaration : AstDeclaration ,
461
+ releaseLevel : ReleaseTag
462
+ ) : boolean {
435
463
// Private declarations are not included in the API report
436
464
// eslint-disable-next-line no-bitwise
437
- return ( astDeclaration . modifierFlags & ts . ModifierFlags . Private ) === 0 ;
465
+ if ( ( astDeclaration . modifierFlags & ts . ModifierFlags . Private ) !== 0 ) {
466
+ return false ;
467
+ }
468
+
469
+ const apiItemMetadata : ApiItemMetadata = collector . fetchApiItemMetadata ( astDeclaration ) ;
470
+ const releaseTag : ReleaseTag = apiItemMetadata . effectiveReleaseTag ;
471
+
472
+ // If the declaration has a release tag that is not in scope, omit it from the report.
473
+ // No release tag is considered the same as `@public`.
474
+ return releaseTag === ReleaseTag . Public || releaseTag >= releaseLevel ;
438
475
}
439
476
440
477
/**
0 commit comments