@@ -222,14 +222,21 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
222
222
const ngHost = ng . createCompilerHost ( { options : compilerOpts , tsHost : bazelHost } ) ;
223
223
224
224
ngHost . fileNameToModuleName = ( importedFilePath : string , containingFilePath : string ) => {
225
- try {
226
- const sourceFile = ngHost . getSourceFile ( importedFilePath , ts . ScriptTarget . Latest ) ;
227
- if ( sourceFile && sourceFile . moduleName ) {
228
- return sourceFile . moduleName ;
225
+ // Lookup the module name specified in the TypeScript source file, if present
226
+ // it will look like ///<amd module-name="something"/>
227
+ // For performance, we only do this for .d.ts files, to avoid parsing lots of
228
+ // additional files that were not in the program.
229
+ // (We don't have the ts.Program available in this codepath)
230
+ if ( importedFilePath . endsWith ( '.d.ts' ) ) {
231
+ try {
232
+ const sourceFile = ngHost . getSourceFile ( importedFilePath , ts . ScriptTarget . Latest ) ;
233
+ if ( sourceFile && sourceFile . moduleName ) {
234
+ return sourceFile . moduleName ;
235
+ }
236
+ } catch ( err ) {
237
+ // File does not exist or parse error. Ignore this case and continue onto the
238
+ // other methods of resolving the module below.
229
239
}
230
- } catch ( err ) {
231
- // File does not exist or parse error. Ignore this case and continue onto the
232
- // other methods of resolving the module below.
233
240
}
234
241
if ( ( compilerOpts . module === ts . ModuleKind . UMD || compilerOpts . module === ts . ModuleKind . AMD ) &&
235
242
ngHost . amdModuleName ) {
0 commit comments