@@ -33,7 +33,7 @@ namespace ts {
3333 let needsScopeFixMarker = false ;
3434 let resultHasScopeMarker = false ;
3535 let enclosingDeclaration : Node ;
36- let necessaryTypeRefernces : Map < true > | undefined ;
36+ let necessaryTypeReferences : Map < true > | undefined ;
3737 let lateMarkedStatements : LateVisibilityPaintedStatement [ ] | undefined ;
3838 let lateStatementReplacementMap : Map < VisitResult < LateVisibilityPaintedStatement > > ;
3939 let suppressNewDiagnosticContexts : boolean ;
@@ -53,6 +53,7 @@ namespace ts {
5353
5454 let currentSourceFile : SourceFile ;
5555 let refs : Map < SourceFile > ;
56+ let libs : Map < boolean > ;
5657 const resolver = context . getEmitResolver ( ) ;
5758 const options = context . getCompilerOptions ( ) ;
5859 const newLine = getNewLineCharacter ( options ) ;
@@ -63,9 +64,9 @@ namespace ts {
6364 if ( ! typeReferenceDirectives ) {
6465 return ;
6566 }
66- necessaryTypeRefernces = necessaryTypeRefernces || createMap < true > ( ) ;
67+ necessaryTypeReferences = necessaryTypeReferences || createMap < true > ( ) ;
6768 for ( const ref of typeReferenceDirectives ) {
68- necessaryTypeRefernces . set ( ref , true ) ;
69+ necessaryTypeReferences . set ( ref , true ) ;
6970 }
7071 }
7172
@@ -163,6 +164,7 @@ namespace ts {
163164 if ( node . kind === SyntaxKind . Bundle ) {
164165 isBundledEmit = true ;
165166 refs = createMap < SourceFile > ( ) ;
167+ libs = createMap < boolean > ( ) ;
166168 let hasNoDefaultLib = false ;
167169 const bundle = createBundle ( map ( node . sourceFiles ,
168170 sourceFile => {
@@ -177,6 +179,7 @@ namespace ts {
177179 needsScopeFixMarker = false ;
178180 resultHasScopeMarker = false ;
179181 collectReferences ( sourceFile , refs ) ;
182+ collectLibs ( sourceFile , libs ) ;
180183 if ( isExternalModule ( sourceFile ) ) {
181184 resultHasExternalModuleIndicator = false ; // unused in external module bundle emit (all external modules are within module blocks, therefore are known to be modules)
182185 needsDeclare = false ;
@@ -200,6 +203,7 @@ namespace ts {
200203 } ) ) ;
201204 bundle . syntheticFileReferences = [ ] ;
202205 bundle . syntheticTypeReferences = getFileReferencesForUsedTypeReferences ( ) ;
206+ bundle . syntheticLibReferences = getLibReferences ( ) ;
203207 bundle . hasNoDefaultLib = hasNoDefaultLib ;
204208 const outputFilePath = getDirectoryPath ( normalizeSlashes ( getOutputPathsFor ( node , host , /*forceDtsPaths*/ true ) . declarationFilePath ! ) ) ;
205209 const referenceVisitor = mapReferencesIntoArray ( bundle . syntheticFileReferences as FileReference [ ] , outputFilePath ) ;
@@ -219,8 +223,9 @@ namespace ts {
219223 suppressNewDiagnosticContexts = false ;
220224 lateMarkedStatements = undefined ;
221225 lateStatementReplacementMap = createMap ( ) ;
222- necessaryTypeRefernces = undefined ;
226+ necessaryTypeReferences = undefined ;
223227 refs = collectReferences ( currentSourceFile , createMap ( ) ) ;
228+ libs = collectLibs ( currentSourceFile , createMap ( ) ) ;
224229 const references : FileReference [ ] = [ ] ;
225230 const outputFilePath = getDirectoryPath ( normalizeSlashes ( getOutputPathsFor ( node , host , /*forceDtsPaths*/ true ) . declarationFilePath ! ) ) ;
226231 const referenceVisitor = mapReferencesIntoArray ( references , outputFilePath ) ;
@@ -231,12 +236,16 @@ namespace ts {
231236 if ( isExternalModule ( node ) && ( ! resultHasExternalModuleIndicator || ( needsScopeFixMarker && ! resultHasScopeMarker ) ) ) {
232237 combinedStatements = setTextRange ( createNodeArray ( [ ...combinedStatements , createExportDeclaration ( /*decorators*/ undefined , /*modifiers*/ undefined , createNamedExports ( [ ] ) , /*moduleSpecifier*/ undefined ) ] ) , combinedStatements ) ;
233238 }
234- const updated = updateSourceFileNode ( node , combinedStatements , /*isDeclarationFile*/ true , references , getFileReferencesForUsedTypeReferences ( ) , node . hasNoDefaultLib ) ;
239+ const updated = updateSourceFileNode ( node , combinedStatements , /*isDeclarationFile*/ true , references , getFileReferencesForUsedTypeReferences ( ) , node . hasNoDefaultLib , getLibReferences ( ) ) ;
235240 updated . exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit ;
236241 return updated ;
237242
243+ function getLibReferences ( ) {
244+ return map ( arrayFrom ( libs . keys ( ) ) , lib => ( { fileName : lib , pos : - 1 , end : - 1 } ) ) ;
245+ }
246+
238247 function getFileReferencesForUsedTypeReferences ( ) {
239- return necessaryTypeRefernces ? mapDefined ( arrayFrom ( necessaryTypeRefernces . keys ( ) ) , getFileReferenceForTypeName ) : [ ] ;
248+ return necessaryTypeReferences ? mapDefined ( arrayFrom ( necessaryTypeReferences . keys ( ) ) , getFileReferenceForTypeName ) : [ ] ;
240249 }
241250
242251 function getFileReferenceForTypeName ( typeName : string ) : FileReference | undefined {
@@ -297,6 +306,16 @@ namespace ts {
297306 return ret ;
298307 }
299308
309+ function collectLibs ( sourceFile : SourceFile , ret : Map < boolean > ) {
310+ forEach ( sourceFile . libReferenceDirectives , ref => {
311+ const lib = host . getLibFileFromReference ( ref ) ;
312+ if ( lib ) {
313+ ret . set ( ref . fileName . toLocaleLowerCase ( ) , true ) ;
314+ }
315+ } ) ;
316+ return ret ;
317+ }
318+
300319 function filterBindingPatternInitializers ( name : BindingName ) {
301320 if ( name . kind === SyntaxKind . Identifier ) {
302321 return name ;
0 commit comments