fix(metadata): treat empty array of metadata like absent file (#10610)

This commit is contained in:
Alex Eagle 2016-08-10 11:52:56 -07:00 committed by vikerman
parent aff1bc9f2d
commit 9a11ec2624
2 changed files with 10 additions and 2 deletions

View File

@ -238,7 +238,8 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
if (DTS.test(filePath)) { if (DTS.test(filePath)) {
const metadataPath = filePath.replace(DTS, '.metadata.json'); const metadataPath = filePath.replace(DTS, '.metadata.json');
if (this.context.fileExists(metadataPath)) { if (this.context.fileExists(metadataPath)) {
return this.readMetadata(metadataPath); const metadata = this.readMetadata(metadataPath);
return (Array.isArray(metadata) && metadata.length == 0) ? undefined : metadata;
} }
} else { } else {
const sf = this.program.getSourceFile(filePath); const sf = this.program.getSourceFile(filePath);

View File

@ -203,6 +203,11 @@ describe('reflector_host', () => {
.toBeUndefined(); .toBeUndefined();
}); });
it('should be able to read empty metadata ', () => {
expect(reflectorNestedGenDir.getMetadataFor('node_modules/@angular/empty.d.ts'))
.toBeUndefined();
});
it('should return undefined for missing modules', () => { it('should return undefined for missing modules', () => {
expect(reflectorNestedGenDir.getMetadataFor('node_modules/@angular/missing.d.ts')) expect(reflectorNestedGenDir.getMetadataFor('node_modules/@angular/missing.d.ts'))
.toBeUndefined(); .toBeUndefined();
@ -328,7 +333,9 @@ const FILES: Entry = {
'core.metadata.json': 'core.metadata.json':
`{"__symbolic":"module", "version": 1, "metadata": {"foo": {"__symbolic": "class"}}}`, `{"__symbolic":"module", "version": 1, "metadata": {"foo": {"__symbolic": "class"}}}`,
'router': {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}}, 'router': {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}},
'unused.d.ts': dummyModule 'unused.d.ts': dummyModule,
'empty.d.ts': 'export declare var a: string;',
'empty.metadata.json': '[]',
} }
} }
}, },