fix(compiler): use either summary or metadata information when reading .d.ts files (#18912)

This fix applies for getting all symbols in file.

PR Close #18912
This commit is contained in:
Tobias Bosch
2017-08-28 15:51:27 -07:00
committed by Jason Aden
parent 83e5deb988
commit f1e526f046
4 changed files with 47 additions and 39 deletions

View File

@ -136,15 +136,14 @@ describe('StaticSymbolResolver', () => {
]);
});
it('should merge the exported symbols of a file with the exported symbols of its summary', () => {
const someSymbol = symbolCache.get('/test.ts', 'a');
init(
{'/test.ts': 'export var b = 2'},
[{symbol: symbolCache.get('/test.ts', 'a'), metadata: 1}]);
expect(symbolResolver.getSymbolsOf('/test.ts')).toEqual([
symbolCache.get('/test.ts', 'a'), symbolCache.get('/test.ts', 'b')
]);
});
it('should read the exported symbols of a file from the summary and ignore exports in the source',
() => {
const someSymbol = symbolCache.get('/test.ts', 'a');
init(
{'/test.ts': 'export var b = 2'},
[{symbol: symbolCache.get('/test.ts', 'a'), metadata: 1}]);
expect(symbolResolver.getSymbolsOf('/test.ts')).toEqual([symbolCache.get('/test.ts', 'a')]);
});
describe('importAs', () => {
@ -385,9 +384,10 @@ export class MockSummaryResolver implements SummaryResolver<StaticSymbol> {
resolveSummary(reference: StaticSymbol): Summary<StaticSymbol> {
return this.summaries.find(summary => summary.symbol === reference);
};
getSymbolsOf(filePath: string): StaticSymbol[] {
return this.summaries.filter(summary => summary.symbol.filePath === filePath)
.map(summary => summary.symbol);
getSymbolsOf(filePath: string): StaticSymbol[]|null {
const symbols = this.summaries.filter(summary => summary.symbol.filePath === filePath)
.map(summary => summary.symbol);
return symbols.length ? symbols : null;
}
getImportAs(symbol: StaticSymbol): StaticSymbol {
const entry = this.importAs.find(entry => entry.symbol === symbol);