@@ -10,14 +10,15 @@ import { Text } from '@microsoft/node-core-library';
1010import { ExtractorContext } from '../../ExtractorContext' ;
1111import { IndentedWriter } from '../../utils/IndentedWriter' ;
1212import { TypeScriptHelpers } from '../../utils/TypeScriptHelpers' ;
13- import { Span } from '../../utils/Span' ;
13+ import { Span , SpanModification } from '../../utils/Span' ;
1414import { ReleaseTag } from '../../aedoc/ReleaseTag' ;
1515import { AstSymbolTable } from './AstSymbolTable' ;
1616import { AstEntryPoint } from './AstEntryPoint' ;
1717import { AstSymbol } from './AstSymbol' ;
1818import { AstImport } from './AstImport' ;
1919import { DtsEntry } from './DtsEntry' ;
2020import { AstDeclaration } from './AstDeclaration' ;
21+ import { SymbolAnalyzer } from './SymbolAnalyzer' ;
2122
2223/**
2324 * Used with PackageTypingsGenerator.writeTypingsFile()
@@ -255,12 +256,12 @@ export class PackageTypingsGenerator {
255256 indentedWriter . writeLine ( ) ;
256257
257258 const span : Span = new Span ( astDeclaration . declaration ) ;
258- this . _modifySpan ( span , dtsEntry ) ;
259+ this . _modifySpan ( span , dtsEntry , astDeclaration , dtsKind ) ;
259260 indentedWriter . writeLine ( span . getModifiedText ( ) ) ;
260261 }
261262 } else {
262263 indentedWriter . writeLine ( ) ;
263- indentedWriter . writeLine ( `// Removed for this release type: ${ dtsEntry . nameForEmit } ` ) ;
264+ indentedWriter . writeLine ( `/* Excluded from this release type: ${ dtsEntry . nameForEmit } */ ` ) ;
264265 }
265266 }
266267 }
@@ -269,11 +270,12 @@ export class PackageTypingsGenerator {
269270 /**
270271 * Before writing out a declaration, _modifySpan() applies various fixups to make it nice.
271272 */
272- private _modifySpan ( span : Span , dtsEntry : DtsEntry ) : void {
273+ private _modifySpan ( span : Span , dtsEntry : DtsEntry , astDeclaration : AstDeclaration ,
274+ dtsKind : PackageTypingsDtsKind ) : void {
275+
273276 const previousSpan : Span | undefined = span . previousSibling ;
274277
275278 let recurseChildren : boolean = true ;
276-
277279 switch ( span . kind ) {
278280 case ts . SyntaxKind . JSDocComment :
279281 // For now, we don't transform JSDoc comment nodes at all
@@ -364,7 +366,37 @@ export class PackageTypingsGenerator {
364366
365367 if ( recurseChildren ) {
366368 for ( const child of span . children ) {
367- this . _modifySpan ( child , dtsEntry ) ;
369+ let childAstDeclaration : AstDeclaration = astDeclaration ;
370+
371+ // Should we trim this node?
372+ let trimmed : boolean = false ;
373+ if ( SymbolAnalyzer . isAstDeclaration ( child . kind ) ) {
374+ childAstDeclaration = this . _astSymbolTable . getChildAstDeclarationByNode ( child . node , astDeclaration ) ;
375+
376+ const releaseTag : ReleaseTag = this . _getReleaseTagForAstSymbol ( childAstDeclaration . astSymbol ) ;
377+ if ( ! this . _shouldIncludeReleaseTag ( releaseTag , dtsKind ) ) {
378+ const modification : SpanModification = child . modification ;
379+
380+ // Yes, trim it and stop here
381+ const name : string = childAstDeclaration . astSymbol . localName ;
382+ modification . omitChildren = true ;
383+
384+ modification . prefix = `/* Excluded from this release type: ${ name } */` ;
385+ modification . suffix = '' ;
386+
387+ if ( child . children . length > 0 ) {
388+ // If there are grandchildren, then keep the last grandchild's separator,
389+ // since it often has useful whitespace
390+ modification . suffix = child . children [ child . children . length - 1 ] . separator ;
391+ }
392+
393+ trimmed = true ;
394+ }
395+ }
396+
397+ if ( ! trimmed ) {
398+ this . _modifySpan ( child , dtsEntry , childAstDeclaration , dtsKind ) ;
399+ }
368400 }
369401 }
370402 }
@@ -397,7 +429,10 @@ export class PackageTypingsGenerator {
397429 const declarationReleaseTag : ReleaseTag = this . _getReleaseTagForDeclaration ( astDeclaration . declaration ) ;
398430 if ( releaseTag !== ReleaseTag . None && declarationReleaseTag !== releaseTag ) {
399431 // this._analyzeWarnings.push('WARNING: Conflicting release tags found for ' + symbol.name);
432+ break ;
400433 }
434+
435+ releaseTag = declarationReleaseTag ;
401436 }
402437
403438 if ( releaseTag !== ReleaseTag . None ) {
0 commit comments