@@ -323,19 +323,22 @@ const symbolNameCache = new Map<string, Symbol>();
323323
324324export function assignSymbolName ( symbol : Symbol ) : string {
325325
326- const decls = symbol . getDeclarations ( )
327- if ( decls . length === 0 ) {
328- return symbol . getName ( )
326+ const decls = symbol . getDeclarations ( ) ;
327+ if ( decls . length === 0 ) {
328+ return symbol . getName ( ) ;
329329 }
330330
331- const declFile = decls [ 0 ] . getSourceFile ( )
332- const declFilePath = declFile . getFilePath ( )
331+ const declFile = decls [ 0 ] . getSourceFile ( ) ;
332+ const declFilePath = declFile . getFilePath ( ) ;
333+ const declDirPath = path . dirname ( declFilePath ) ;
333334
334- if ( declFile . getDefaultExportSymbol ( ) === symbol ) {
335- return declFile . getBaseName ( ) + '_default_export_symbol'
336- }
335+ let rawName = symbol . getName ( ) ; // Initialize rawName here
336+
337+ const id = declDirPath + "#" + rawName ;
337338
338- let rawName = symbol . getName ( )
339+ if ( declFile . getDefaultExportSymbol ( ) === symbol ) {
340+ return declFile . getBaseName ( ) + '_default_export_symbol' ;
341+ }
339342
340343 // Handle methods, properties, constructors, and functions with proper naming
341344 const firstDecl = decls [ 0 ] ;
@@ -381,17 +384,12 @@ export function assignSymbolName(symbol: Symbol): string {
381384 }
382385 }
383386
384- const id = declFilePath + "#" + rawName
385387 if ( ! symbolNameCache . has ( id ) ) {
386388 symbolNameCache . set ( id , symbol )
387389 return rawName
388390 }
389391
390- const symbolExists = symbolNameCache . get ( id )
391- // make ts happy
392- if ( ! symbolExists ) {
393- return rawName
394- }
392+ const symbolExists = symbolNameCache . get ( id ) !
395393
396394 const getDeclsPos = ( symbol : Symbol ) => {
397395 const declsPos = [ ]
@@ -404,10 +402,16 @@ export function assignSymbolName(symbol: Symbol): string {
404402
405403 const arr1 = getDeclsPos ( symbol )
406404 const arr2 = getDeclsPos ( symbolExists )
407- if ( arr1 . join ( ',' ) === arr2 . join ( ',' ) ) {
405+
406+ const symbolExistsDecls = symbolExists . getDeclarations ( )
407+ if ( symbolExistsDecls . length === 0 ) {
408+ return rawName
409+ }
410+ const symbolExistsDeclFile = symbolExistsDecls [ 0 ] . getSourceFile ( )
411+ if ( arr1 . join ( ',' ) === arr2 . join ( ',' ) && symbolExistsDeclFile . getFilePath ( ) === declFilePath ) {
408412 return rawName
409413 }
410414
411415 // mangled name
412- return rawName + "_" + getDeclsPos ( symbol ) . join ( "." )
416+ return rawName + "_" + path . basename ( declFilePath ) + "_" + getDeclsPos ( symbol ) . join ( "." )
413417}
0 commit comments