diff --git a/modules/@angular/compiler-cli/src/reflector_host.ts b/modules/@angular/compiler-cli/src/reflector_host.ts index 44318e7835..29daaf9cdd 100644 --- a/modules/@angular/compiler-cli/src/reflector_host.ts +++ b/modules/@angular/compiler-cli/src/reflector_host.ts @@ -184,14 +184,13 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator { if (this.context.exists(metadataPath)) { return this.readMetadata(metadataPath); } + } else { + const sf = this.program.getSourceFile(filePath); + if (!sf) { + throw new Error(`Source file ${filePath} not present in program.`); + } + return this.metadataCollector.getMetadata(sf); } - - let sf = this.program.getSourceFile(filePath); - if (!sf) { - throw new Error(`Source file ${filePath} not present in program.`); - } - const metadata = this.metadataCollector.getMetadata(sf); - return metadata; } readMetadata(filePath: string) { diff --git a/modules/@angular/compiler-cli/test/reflector_host_spec.ts b/modules/@angular/compiler-cli/test/reflector_host_spec.ts index 4805fe10ba..b7a778423b 100644 --- a/modules/@angular/compiler-cli/test/reflector_host_spec.ts +++ b/modules/@angular/compiler-cli/test/reflector_host_spec.ts @@ -92,6 +92,10 @@ describe('reflector_host', () => { () => { expect(reflectorHost.getMetadataFor('node_modules/@angular/core.d.ts')) .toEqual({__symbolic: 'module', version: 1, metadata: {foo: {__symbolic: 'class'}}})}); + + it('should be able to read metadata from an otherwise unused .d.ts file ', () => { + expect(reflectorHost.getMetadataFor('node_modules/@angular/unused.d.ts')).toBeUndefined(); + }); }); const dummyModule = 'export let foo: any[];' @@ -115,8 +119,8 @@ const FILES: Entry = { 'core.d.ts': dummyModule, 'core.metadata.json': `{"__symbolic":"module", "version": 1, "metadata": {"foo": {"__symbolic": "class"}}}`, - 'router-deprecated': - {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}} + 'router-deprecated': {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}}, + 'unused.d.ts': dummyModule } } }