@@ -766,6 +766,32 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
766
766
} ) ;
767
767
}
768
768
769
+ function isSymbolUsedByGlobalSymbols ( symbol : ts . Symbol , visitedSymbols : Set < ts . Symbol > = new Set ( ) ) : boolean {
770
+ if ( visitedSymbols . has ( symbol ) ) {
771
+ return false ;
772
+ }
773
+
774
+ visitedSymbols . add ( symbol ) ;
775
+
776
+ return Array . from ( typesUsageEvaluator . getSymbolsUsingSymbol ( symbol ) ?? [ ] ) . some ( ( usedInSymbol : ts . Symbol ) => {
777
+ if ( usedInSymbol . escapedName !== ts . InternalSymbolName . Global ) {
778
+ return isSymbolUsedByGlobalSymbols ( usedInSymbol , visitedSymbols ) ;
779
+ }
780
+
781
+ const usedByThisSymbol = getDeclarationsForSymbol ( usedInSymbol ) . some ( ( decl : ts . Declaration ) => {
782
+ const closestModuleLike = getClosestSourceFileLikeNode ( decl ) ;
783
+ const moduleInfo = getModuleLikeModuleInfo ( closestModuleLike , criteria , typeChecker ) ;
784
+ return moduleInfo . type === ModuleType . ShouldBeInlined ;
785
+ } ) ;
786
+
787
+ if ( usedByThisSymbol ) {
788
+ return true ;
789
+ }
790
+
791
+ return isSymbolUsedByGlobalSymbols ( usedInSymbol , visitedSymbols ) ;
792
+ } ) ;
793
+ }
794
+
769
795
function isNodeUsed ( node : ts . Node ) : boolean {
770
796
if ( isNodeNamedDeclaration ( node ) || ts . isSourceFile ( node ) ) {
771
797
const nodeSymbol = getNodeSymbol ( node , typeChecker ) ;
@@ -778,7 +804,7 @@ export function generateDtsBundle(entries: readonly EntryPointConfig[], options:
778
804
return true ;
779
805
}
780
806
781
- return inlineDeclareGlobals && getGlobalSymbolsUsingSymbol ( nodeSymbol ) . length !== 0 ;
807
+ return inlineDeclareGlobals && isSymbolUsedByGlobalSymbols ( nodeSymbol ) ;
782
808
} else if ( ts . isVariableStatement ( node ) ) {
783
809
return node . declarationList . declarations . some ( ( declaration : ts . VariableDeclaration ) => {
784
810
return isNodeUsed ( declaration ) ;
0 commit comments