@@ -34,16 +34,20 @@ export function extractImportDeclaration(node: ImportDeclaration, sourceCode: st
3434/**
3535 * Extract export declaration
3636 */
37- export function extractExportDeclaration ( node : ExportDeclaration , sourceCode : string ) : Declaration {
37+ export function extractExportDeclaration ( node : ExportDeclaration , sourceCode : string , sourceFile ?: SourceFile , keepComments : boolean = false ) : Declaration {
3838 const text = getNodeText ( node , sourceCode )
3939 const isTypeOnly = ! ! node . isTypeOnly
4040
41+ // Extract comments if enabled and sourceFile is available
42+ const leadingComments = keepComments && sourceFile ? extractJSDocComments ( node , sourceFile ) : undefined
43+
4144 return {
4245 kind : 'export' ,
4346 name : '' , // Export declarations don't have a single name
4447 text,
4548 isExported : true ,
4649 isTypeOnly,
50+ leadingComments,
4751 source : node . moduleSpecifier ?. getText ( ) . slice ( 1 , - 1 ) , // Remove quotes if present
4852 start : node . getStart ( ) ,
4953 end : node . getEnd ( ) ,
@@ -53,15 +57,19 @@ export function extractExportDeclaration(node: ExportDeclaration, sourceCode: st
5357/**
5458 * Extract export assignment (export default)
5559 */
56- export function extractExportAssignment ( node : ExportAssignment , sourceCode : string ) : Declaration {
60+ export function extractExportAssignment ( node : ExportAssignment , sourceCode : string , sourceFile ?: SourceFile , keepComments : boolean = false ) : Declaration {
5761 const text = getNodeText ( node , sourceCode )
5862
63+ // Extract comments if enabled and sourceFile is available
64+ const leadingComments = keepComments && sourceFile ? extractJSDocComments ( node , sourceFile ) : undefined
65+
5966 return {
6067 kind : 'export' ,
6168 name : 'default' ,
6269 text,
6370 isExported : true ,
6471 isTypeOnly : false ,
72+ leadingComments,
6573 start : node . getStart ( ) ,
6674 end : node . getEnd ( ) ,
6775 }
@@ -170,16 +178,6 @@ function isAsConstAssertion(node: import('typescript').Expression): boolean {
170178 return false
171179}
172180
173- /**
174- * Get the underlying expression from an 'as const' assertion
175- */
176- function _getAsConstValue ( node : import ( 'typescript' ) . Expression ) : import ( 'typescript' ) . Expression | null {
177- if ( isAsExpression ( node ) && isAsConstAssertion ( node ) ) {
178- return node . expression
179- }
180- return null
181- }
182-
183181/**
184182 * Infer a literal type from a value for 'as const' declarations
185183 * This creates readonly types for objects and arrays
@@ -491,7 +489,7 @@ export function findReferencedTypes(declarations: Declaration[], _sourceCode: st
491489/**
492490 * Extract declarations for referenced types by searching the entire source file
493491 */
494- export function extractReferencedTypeDeclarations ( sourceFile : SourceFile , referencedTypes : Set < string > , sourceCode : string ) : Declaration [ ] {
492+ export function extractReferencedTypeDeclarations ( sourceFile : SourceFile , referencedTypes : Set < string > , sourceCode : string , keepComments : boolean = true ) : Declaration [ ] {
495493 const additionalDeclarations : Declaration [ ] = [ ]
496494
497495 if ( referencedTypes . size === 0 ) {
@@ -505,7 +503,7 @@ export function extractReferencedTypeDeclarations(sourceFile: SourceFile, refere
505503 const interfaceNode = node as InterfaceDeclaration
506504 const interfaceName = interfaceNode . name . getText ( )
507505 if ( referencedTypes . has ( interfaceName ) ) {
508- const decl = extractInterfaceDeclaration ( interfaceNode , sourceCode , sourceFile , false ) // Don't extract comments for referenced types
506+ const decl = extractInterfaceDeclaration ( interfaceNode , sourceCode , sourceFile , keepComments )
509507 additionalDeclarations . push ( decl )
510508 referencedTypes . delete ( interfaceName ) // Remove to avoid duplicates
511509 }
@@ -516,7 +514,7 @@ export function extractReferencedTypeDeclarations(sourceFile: SourceFile, refere
516514 const typeNode = node as TypeAliasDeclaration
517515 const typeName = typeNode . name . getText ( )
518516 if ( referencedTypes . has ( typeName ) ) {
519- const decl = extractTypeAliasDeclaration ( typeNode , sourceCode , sourceFile , false ) // Don't extract comments for referenced types
517+ const decl = extractTypeAliasDeclaration ( typeNode , sourceCode , sourceFile , keepComments )
520518 additionalDeclarations . push ( decl )
521519 referencedTypes . delete ( typeName )
522520 }
@@ -528,7 +526,7 @@ export function extractReferencedTypeDeclarations(sourceFile: SourceFile, refere
528526 if ( classNode . name ) {
529527 const className = classNode . name . getText ( )
530528 if ( referencedTypes . has ( className ) ) {
531- const decl = extractClassDeclaration ( classNode , sourceCode , sourceFile , false ) // Don't extract comments for referenced types
529+ const decl = extractClassDeclaration ( classNode , sourceCode , sourceFile , keepComments )
532530 additionalDeclarations . push ( decl )
533531 referencedTypes . delete ( className )
534532 }
@@ -540,7 +538,7 @@ export function extractReferencedTypeDeclarations(sourceFile: SourceFile, refere
540538 const enumNode = node as EnumDeclaration
541539 const enumName = enumNode . name . getText ( )
542540 if ( referencedTypes . has ( enumName ) ) {
543- const decl = extractEnumDeclaration ( enumNode , sourceCode , sourceFile , false ) // Don't extract comments for referenced types
541+ const decl = extractEnumDeclaration ( enumNode , sourceCode , sourceFile , keepComments )
544542 additionalDeclarations . push ( decl )
545543 referencedTypes . delete ( enumName )
546544 }
0 commit comments