@@ -37,20 +37,23 @@ namespace ts {
37
37
let lateStatementReplacementMap : Map < VisitResult < LateVisibilityPaintedStatement > > ;
38
38
let suppressNewDiagnosticContexts : boolean ;
39
39
40
+ const host = context . getEmitHost ( ) ;
40
41
const symbolTracker : SymbolTracker = {
41
42
trackSymbol,
42
43
reportInaccessibleThisError,
43
44
reportInaccessibleUniqueSymbolError,
44
- reportPrivateInBaseOfClassExpression
45
+ reportPrivateInBaseOfClassExpression,
46
+ moduleResolverHost : host ,
47
+ trackReferencedAmbientModule,
45
48
} ;
46
49
let errorNameNode : DeclarationName | undefined ;
47
50
48
51
let currentSourceFile : SourceFile ;
52
+ let refs : Map < SourceFile > ;
49
53
const resolver = context . getEmitResolver ( ) ;
50
54
const options = context . getCompilerOptions ( ) ;
51
55
const newLine = getNewLineCharacter ( options ) ;
52
56
const { noResolve, stripInternal } = options ;
53
- const host = context . getEmitHost ( ) ;
54
57
return transformRoot ;
55
58
56
59
function recordTypeReferenceDirectivesIfNecessary ( typeReferenceDirectives : string [ ] ) : void {
@@ -63,6 +66,11 @@ namespace ts {
63
66
}
64
67
}
65
68
69
+ function trackReferencedAmbientModule ( node : ModuleDeclaration ) {
70
+ const container = getSourceFileOfNode ( node ) ;
71
+ refs . set ( "" + getOriginalNodeId ( container ) , container ) ;
72
+ }
73
+
66
74
function handleSymbolAccessibilityError ( symbolAccessibilityResult : SymbolAccessibilityResult ) {
67
75
if ( symbolAccessibilityResult . accessibility === SymbolAccessibility . Accessible ) {
68
76
// Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info
@@ -197,13 +205,13 @@ namespace ts {
197
205
lateMarkedStatements = undefined ;
198
206
lateStatementReplacementMap = createMap ( ) ;
199
207
necessaryTypeRefernces = undefined ;
200
- const refs = collectReferences ( currentSourceFile , createMap ( ) ) ;
208
+ refs = collectReferences ( currentSourceFile , createMap ( ) ) ;
201
209
const references : FileReference [ ] = [ ] ;
202
210
const outputFilePath = getDirectoryPath ( normalizeSlashes ( getOutputPathsFor ( node , host , /*forceDtsPaths*/ true ) . declarationFilePath ) ) ;
203
211
const referenceVisitor = mapReferencesIntoArray ( references , outputFilePath ) ;
204
- refs . forEach ( referenceVisitor ) ;
205
212
const statements = visitNodes ( node . statements , visitDeclarationStatements ) ;
206
213
let combinedStatements = setTextRange ( createNodeArray ( transformAndReplaceLatePaintedStatements ( statements ) ) , node . statements ) ;
214
+ refs . forEach ( referenceVisitor ) ;
207
215
const emittedImports = filter ( combinedStatements , isAnyImportSyntax ) ;
208
216
if ( isExternalModule ( node ) && ( ! resultHasExternalModuleIndicator || ( needsScopeFixMarker && ! resultHasScopeMarker ) ) ) {
209
217
combinedStatements = setTextRange ( createNodeArray ( [ ...combinedStatements , createExportDeclaration ( /*decorators*/ undefined , /*modifiers*/ undefined , createNamedExports ( [ ] ) , /*moduleSpecifier*/ undefined ) ] ) , combinedStatements ) ;
0 commit comments