@@ -62,11 +62,46 @@ export class ReviewFileGenerator {
6262 // Emit the regular declarations
6363 for ( const entity of collector . entities ) {
6464 if ( entity . exported ) {
65+
66+ // First, collect the list of export names for this symbol. When reporting messages with
67+ // ExtractorMessage.properties.exportName, this will enable us to emit the warning comments alongside
68+ // the associated export statement.
69+ interface IExportToEmit {
70+ readonly exportName : string ;
71+ readonly associatedMessages : ExtractorMessage [ ] ;
72+ }
73+ const exportsToEmit : Map < string , IExportToEmit > = new Map < string , IExportToEmit > ( ) ;
74+
75+ for ( const exportName of entity . exportNames ) {
76+ if ( ! entity . shouldInlineExport ) {
77+ exportsToEmit . set ( exportName , { exportName, associatedMessages : [ ] } ) ;
78+ }
79+ }
80+
6581 if ( entity . astEntity instanceof AstSymbol ) {
66- // Emit all the declarations for this entry
82+ // Emit all the declarations for this entity
6783 for ( const astDeclaration of entity . astEntity . astDeclarations || [ ] ) {
6884
69- stringWriter . write ( ReviewFileGenerator . _getAedocSynopsis ( collector , astDeclaration ) ) ;
85+ // Get the messages associated with this declaration
86+ const fetchedMessages : ExtractorMessage [ ] = collector . messageRouter
87+ . fetchAssociatedMessagesForReviewFile ( astDeclaration ) ;
88+
89+ // Peel off the messages associated with an export statement and store them
90+ // in IExportToEmit.associatedMessages (to be processed later). The remaining messages will
91+ // added to messagesToReport, to be emitted next to the declaration instead of the export statement.
92+ const messagesToReport : ExtractorMessage [ ] = [ ] ;
93+ for ( const message of fetchedMessages ) {
94+ if ( message . properties . exportName ) {
95+ const exportToEmit : IExportToEmit | undefined = exportsToEmit . get ( message . properties . exportName ) ;
96+ if ( exportToEmit ) {
97+ exportToEmit . associatedMessages . push ( message ) ;
98+ continue ;
99+ }
100+ }
101+ messagesToReport . push ( message ) ;
102+ }
103+
104+ stringWriter . write ( ReviewFileGenerator . _getAedocSynopsis ( collector , astDeclaration , messagesToReport ) ) ;
70105
71106 const span : Span = new Span ( astDeclaration . declaration ) ;
72107 ReviewFileGenerator . _modifySpan ( collector , span , entity , astDeclaration , false ) ;
@@ -75,11 +110,16 @@ export class ReviewFileGenerator {
75110 }
76111 }
77112
78- for ( const exportName of entity . exportNames ) {
79- if ( ! entity . shouldInlineExport ) {
80- DtsEmitHelpers . emitNamedExport ( stringWriter , exportName , entity ) ;
81- stringWriter . writeLine ( ) ;
113+ // Now emit the export statements for this entity.
114+ for ( const exportToEmit of exportsToEmit . values ( ) ) {
115+ // Write any associated messages
116+ for ( const message of exportToEmit . associatedMessages ) {
117+ ReviewFileGenerator . _writeLineAsComments ( stringWriter ,
118+ 'Warning: ' + message . formatMessageWithoutLocation ( ) ) ;
82119 }
120+
121+ DtsEmitHelpers . emitNamedExport ( stringWriter , exportToEmit . exportName , entity ) ;
122+ stringWriter . writeLine ( ) ;
83123 }
84124 }
85125 }
@@ -245,7 +285,10 @@ export class ReviewFileGenerator {
245285 }
246286
247287 if ( ! insideTypeLiteral ) {
248- const aedocSynopsis : string = ReviewFileGenerator . _getAedocSynopsis ( collector , childAstDeclaration ) ;
288+ const messagesToReport : ExtractorMessage [ ] = collector . messageRouter
289+ . fetchAssociatedMessagesForReviewFile ( childAstDeclaration ) ;
290+ const aedocSynopsis : string = ReviewFileGenerator . _getAedocSynopsis ( collector , childAstDeclaration ,
291+ messagesToReport ) ;
249292 const indentedAedocSynopsis : string = ReviewFileGenerator . _addIndentAfterNewlines ( aedocSynopsis ,
250293 child . getIndent ( ) ) ;
251294
@@ -263,14 +306,12 @@ export class ReviewFileGenerator {
263306 * whether the item has been documented, and any warnings that were detected
264307 * by the analysis.
265308 */
266- private static _getAedocSynopsis ( collector : Collector , astDeclaration : AstDeclaration ) : string {
267- const output : StringWriter = new StringWriter ( ) ;
268-
269- const messagesToReport : ExtractorMessage [ ] = collector . messageRouter
270- . fetchAssociatedMessagesForReviewFile ( astDeclaration ) ;
309+ private static _getAedocSynopsis ( collector : Collector , astDeclaration : AstDeclaration ,
310+ messagesToReport : ExtractorMessage [ ] ) : string {
311+ const stringWriter : StringWriter = new StringWriter ( ) ;
271312
272313 for ( const message of messagesToReport ) {
273- ReviewFileGenerator . _writeLineAsComments ( output , 'Warning: ' + message . formatMessageWithoutLocation ( ) ) ;
314+ ReviewFileGenerator . _writeLineAsComments ( stringWriter , 'Warning: ' + message . formatMessageWithoutLocation ( ) ) ;
274315 }
275316
276317 const declarationMetadata : DeclarationMetadata = collector . fetchMetadata ( astDeclaration ) ;
@@ -312,13 +353,13 @@ export class ReviewFileGenerator {
312353
313354 if ( footerParts . length > 0 ) {
314355 if ( messagesToReport . length > 0 ) {
315- ReviewFileGenerator . _writeLineAsComments ( output , '' ) ; // skip a line after the warnings
356+ ReviewFileGenerator . _writeLineAsComments ( stringWriter , '' ) ; // skip a line after the warnings
316357 }
317358
318- ReviewFileGenerator . _writeLineAsComments ( output , footerParts . join ( ' ' ) ) ;
359+ ReviewFileGenerator . _writeLineAsComments ( stringWriter , footerParts . join ( ' ' ) ) ;
319360 }
320361
321- return output . toString ( ) ;
362+ return stringWriter . toString ( ) ;
322363 }
323364
324365 private static _writeLineAsComments ( stringWriter : StringWriter , line : string ) : void {
0 commit comments