@@ -11,11 +11,13 @@ import {ExternalReference} from '@angular/compiler/src/compiler';
11
11
import * as ts from 'typescript' ;
12
12
13
13
import { LogicalFileSystem , LogicalProjectPath } from '../../path' ;
14
+ import { ReflectionHost } from '../../reflection' ;
14
15
import { getSourceFile , isDeclaration , nodeNameForError , resolveModuleName } from '../../util/src/typescript' ;
15
16
16
17
import { findExportedNameOfNode } from './find_export' ;
17
18
import { ImportMode , Reference } from './references' ;
18
19
20
+
19
21
/**
20
22
* A host which supports an operation to convert a file name into a module name.
21
23
*
@@ -115,8 +117,9 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
115
117
private moduleExportsCache = new Map < string , Map < ts . Declaration , string > | null > ( ) ;
116
118
117
119
constructor (
118
- private program : ts . Program , private checker : ts . TypeChecker ,
119
- private options : ts . CompilerOptions , private host : ts . CompilerHost ) { }
120
+ protected program : ts . Program , protected checker : ts . TypeChecker ,
121
+ protected options : ts . CompilerOptions , protected host : ts . CompilerHost ,
122
+ private reflectionHost : ReflectionHost ) { }
120
123
121
124
emit ( ref : Reference < ts . Node > , context : ts . SourceFile , importMode : ImportMode ) : Expression | null {
122
125
if ( ref . bestGuessOwningModule === null ) {
@@ -159,7 +162,7 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
159
162
return this . moduleExportsCache . get ( moduleName ) ! ;
160
163
}
161
164
162
- private enumerateExportsOfModule ( specifier : string , fromFile : string ) :
165
+ protected enumerateExportsOfModule ( specifier : string , fromFile : string ) :
163
166
Map < ts . Declaration , string > | null {
164
167
// First, resolve the module specifier to its entry point, and get the ts.Symbol for it.
165
168
const resolvedModule = resolveModuleName ( specifier , fromFile , this . options , this . host ) ;
@@ -172,34 +175,12 @@ export class AbsoluteModuleStrategy implements ReferenceEmitStrategy {
172
175
return null ;
173
176
}
174
177
175
- const entryPointSymbol = this . checker . getSymbolAtLocation ( entryPointFile ) ;
176
- if ( entryPointSymbol === undefined ) {
178
+ const exports = this . reflectionHost . getExportsOfModule ( entryPointFile ) ;
179
+ if ( exports === null ) {
177
180
return null ;
178
181
}
179
-
180
- // Next, build a Map of all the ts.Declarations exported via the specifier and their exported
181
- // names.
182
182
const exportMap = new Map < ts . Declaration , string > ( ) ;
183
-
184
- const exports = this . checker . getExportsOfModule ( entryPointSymbol ) ;
185
- for ( const expSymbol of exports ) {
186
- // Resolve export symbols to their actual declarations.
187
- const declSymbol = expSymbol . flags & ts . SymbolFlags . Alias ?
188
- this . checker . getAliasedSymbol ( expSymbol ) :
189
- expSymbol ;
190
-
191
- // At this point the valueDeclaration of the symbol should be defined.
192
- const decl = declSymbol . valueDeclaration ;
193
- if ( decl === undefined ) {
194
- continue ;
195
- }
196
-
197
- // Prefer importing the symbol via its declared name, but take any export of it otherwise.
198
- if ( declSymbol . name === expSymbol . name || ! exportMap . has ( decl ) ) {
199
- exportMap . set ( decl , expSymbol . name ) ;
200
- }
201
- }
202
-
183
+ exports . forEach ( ( declaration , name ) => { exportMap . set ( declaration . node , name ) ; } ) ;
203
184
return exportMap ;
204
185
}
205
186
}
0 commit comments