@@ -62,6 +62,21 @@ function getSymbolsFromScope(s, untilScope) {
6262 return allUsedNames ;
6363}
6464
65+ function getAllReferences ( variable ) {
66+ let set = variable . references ;
67+ // Look for inner scope variables too (like in class Foo { t() { Foo } })
68+ const identifiers = new Set ( variable . identifiers ) ;
69+ for ( const scope of variable . scope . childScopes ) {
70+ for ( const innerVar of scope . variables ) {
71+ if ( innerVar . identifiers . some ( id => identifiers . has ( id ) ) ) {
72+ set = set . concat ( innerVar . references ) ;
73+ break ;
74+ }
75+ }
76+ }
77+ return set ;
78+ }
79+
6580function reduceSet ( a , b ) {
6681 for ( const item of b )
6782 a . add ( item ) ;
@@ -242,7 +257,7 @@ class ConcatenatedModule extends Module {
242257 } ) ;
243258 const globalScope = scopeManager . acquire ( ast ) ;
244259 const moduleScope = globalScope . childScopes [ 0 ] ;
245- const resultSource = new ReplaceSource ( m . source ( innerDependencyTemplates , outputOptions , requestShortener ) ) ;
260+ const resultSource = new ReplaceSource ( source ) ;
246261 info . source = resultSource ;
247262 info . globalScope = globalScope ;
248263 info . moduleScope = moduleScope ;
@@ -272,12 +287,13 @@ class ConcatenatedModule extends Module {
272287 info . moduleScope . variables . forEach ( variable => {
273288 const name = variable . name ;
274289 if ( allUsedNames . has ( name ) ) {
275- const symbolsInReferences = variable . references . map ( ref => getSymbolsFromScope ( ref . from , info . moduleScope ) ) . reduce ( reduceSet , new Set ( ) ) ;
290+ const references = getAllReferences ( variable ) ;
291+ const symbolsInReferences = references . map ( ref => getSymbolsFromScope ( ref . from , info . moduleScope ) ) . reduce ( reduceSet , new Set ( ) ) ;
276292 const newName = this . findNewName ( name , allUsedNames , symbolsInReferences , info . module . readableIdentifier ( requestShortener ) ) ;
277293 allUsedNames . add ( newName ) ;
278294 info . internalNames . set ( name , newName ) ;
279295 const source = info . source ;
280- const allIdentifiers = new Set ( variable . references . map ( r => r . identifier ) . concat ( variable . identifiers ) ) ;
296+ const allIdentifiers = new Set ( references . map ( r => r . identifier ) . concat ( variable . identifiers ) ) ;
281297 for ( const identifier of allIdentifiers ) {
282298 const r = identifier . range ;
283299 source . replace ( r [ 0 ] , r [ 1 ] - 1 , newName ) ;
0 commit comments