@@ -37,6 +37,8 @@ namespace ts {
37
37
let lateMarkedStatements : LateVisibilityPaintedStatement [ ] | undefined ;
38
38
let lateStatementReplacementMap : Map < VisitResult < LateVisibilityPaintedStatement > > ;
39
39
let suppressNewDiagnosticContexts : boolean ;
40
+ let exportedModuleSpecifiers : StringLiteralLike [ ] | undefined ;
41
+ let exportedModuleSymbolsUsingImportTypeNodes : Symbol [ ] | undefined ;
40
42
41
43
const host = context . getEmitHost ( ) ;
42
44
const symbolTracker : SymbolTracker = {
@@ -46,6 +48,7 @@ namespace ts {
46
48
reportPrivateInBaseOfClassExpression,
47
49
moduleResolverHost : host ,
48
50
trackReferencedAmbientModule,
51
+ trackExternalModuleSymbolOfImportTypeNode
49
52
} ;
50
53
let errorNameNode : DeclarationName | undefined ;
51
54
@@ -115,6 +118,12 @@ namespace ts {
115
118
}
116
119
}
117
120
121
+ function trackExternalModuleSymbolOfImportTypeNode ( symbol : Symbol ) {
122
+ if ( ! isBundledEmit ) {
123
+ ( exportedModuleSymbolsUsingImportTypeNodes || ( exportedModuleSymbolsUsingImportTypeNodes = [ ] ) ) . push ( symbol ) ;
124
+ }
125
+ }
126
+
118
127
function trackSymbol ( symbol : Symbol , enclosingDeclaration ?: Node , meaning ?: SymbolFlags ) {
119
128
if ( symbol . flags & SymbolFlags . TypeParameter ) return ;
120
129
handleSymbolAccessibilityError ( resolver . isSymbolAccessible ( symbol , enclosingDeclaration , meaning , /*shouldComputeAliasesToMakeVisible*/ true ) ) ;
@@ -224,6 +233,12 @@ namespace ts {
224
233
combinedStatements = setTextRange ( createNodeArray ( [ ...combinedStatements , createExportDeclaration ( /*decorators*/ undefined , /*modifiers*/ undefined , createNamedExports ( [ ] ) , /*moduleSpecifier*/ undefined ) ] ) , combinedStatements ) ;
225
234
}
226
235
const updated = updateSourceFileNode ( node , combinedStatements , /*isDeclarationFile*/ true , references , getFileReferencesForUsedTypeReferences ( ) , node . hasNoDefaultLib ) ;
236
+ if ( exportedModuleSpecifiers || exportedModuleSymbolsUsingImportTypeNodes ) {
237
+ updated . getExportedModulesFromDeclarationEmit = ( ) => ( {
238
+ exportedModuleSpecifiers : exportedModuleSpecifiers || emptyArray ,
239
+ exportedModuleSymbolsUsingImportTypeNodes : exportedModuleSymbolsUsingImportTypeNodes || emptyArray
240
+ } ) ;
241
+ }
227
242
return updated ;
228
243
229
244
function getFileReferencesForUsedTypeReferences ( ) {
@@ -483,10 +498,15 @@ namespace ts {
483
498
function rewriteModuleSpecifier < T extends Node > ( parent : ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode , input : T | undefined ) : T | StringLiteral {
484
499
if ( ! input ) return undefined ! ; // TODO: GH#18217
485
500
resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || ( parent . kind !== SyntaxKind . ModuleDeclaration && parent . kind !== SyntaxKind . ImportType ) ;
486
- if ( input . kind === SyntaxKind . StringLiteral && isBundledEmit ) {
487
- const newName = getExternalModuleNameFromDeclaration ( context . getEmitHost ( ) , resolver , parent ) ;
488
- if ( newName ) {
489
- return createLiteral ( newName ) ;
501
+ if ( isStringLiteralLike ( input ) ) {
502
+ if ( isBundledEmit ) {
503
+ const newName = getExternalModuleNameFromDeclaration ( context . getEmitHost ( ) , resolver , parent ) ;
504
+ if ( newName ) {
505
+ return createLiteral ( newName ) ;
506
+ }
507
+ }
508
+ else {
509
+ ( exportedModuleSpecifiers || ( exportedModuleSpecifiers = [ ] ) ) . push ( input ) ;
490
510
}
491
511
}
492
512
return input ;
0 commit comments