fix(compiler): Missing metadata files should result in undefined (#9704)
RelectorHost threw an exception when metadata was requested for a .d.ts file that didn't have a .metadata.json file. Changed it to return undefined. Fixes #9678
This commit is contained in:
parent
9a04fcd061
commit
30bec78da3
|
@ -184,14 +184,13 @@ export class ReflectorHost implements StaticReflectorHost, ImportGenerator {
|
||||||
if (this.context.exists(metadataPath)) {
|
if (this.context.exists(metadataPath)) {
|
||||||
return this.readMetadata(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) {
|
readMetadata(filePath: string) {
|
||||||
|
|
|
@ -92,6 +92,10 @@ describe('reflector_host', () => {
|
||||||
() => {
|
() => {
|
||||||
expect(reflectorHost.getMetadataFor('node_modules/@angular/core.d.ts'))
|
expect(reflectorHost.getMetadataFor('node_modules/@angular/core.d.ts'))
|
||||||
.toEqual({__symbolic: 'module', version: 1, metadata: {foo: {__symbolic: 'class'}}})});
|
.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[];'
|
const dummyModule = 'export let foo: any[];'
|
||||||
|
@ -115,8 +119,8 @@ const FILES: Entry = {
|
||||||
'core.d.ts': dummyModule,
|
'core.d.ts': dummyModule,
|
||||||
'core.metadata.json':
|
'core.metadata.json':
|
||||||
`{"__symbolic":"module", "version": 1, "metadata": {"foo": {"__symbolic": "class"}}}`,
|
`{"__symbolic":"module", "version": 1, "metadata": {"foo": {"__symbolic": "class"}}}`,
|
||||||
'router-deprecated':
|
'router-deprecated': {'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}},
|
||||||
{'index.d.ts': dummyModule, 'src': {'providers.d.ts': dummyModule}}
|
'unused.d.ts': dummyModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue