fix(compiler): always check summaries first before falling back to metadata from .d.ts files (#18788)
PR Close #18788
This commit is contained in:
parent
0262e37301
commit
f83b819bea
|
@ -78,20 +78,22 @@ export class StaticSymbolResolver {
|
|||
if (staticSymbol.members.length > 0) {
|
||||
return this._resolveSymbolMembers(staticSymbol) !;
|
||||
}
|
||||
let result = this.resolvedSymbols.get(staticSymbol);
|
||||
if (result) {
|
||||
return result;
|
||||
// Note: always ask for a summary first,
|
||||
// as we might have read shallow metadata via a .d.ts file
|
||||
// for the symbol.
|
||||
const resultFromSummary = this._resolveSymbolFromSummary(staticSymbol) !;
|
||||
if (resultFromSummary) {
|
||||
return resultFromSummary;
|
||||
}
|
||||
result = this._resolveSymbolFromSummary(staticSymbol) !;
|
||||
if (result) {
|
||||
return result;
|
||||
const resultFromCache = this.resolvedSymbols.get(staticSymbol);
|
||||
if (resultFromCache) {
|
||||
return resultFromCache;
|
||||
}
|
||||
// Note: Some users use libraries that were not compiled with ngc, i.e. they don't
|
||||
// have summaries, only .d.ts files. So we always need to check both, the summary
|
||||
// and metadata.
|
||||
this._createSymbolsOf(staticSymbol.filePath);
|
||||
result = this.resolvedSymbols.get(staticSymbol) !;
|
||||
return result;
|
||||
return this.resolvedSymbols.get(staticSymbol) !;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -104,9 +104,18 @@ describe('StaticSymbolResolver', () => {
|
|||
});
|
||||
|
||||
it('should use summaries in resolveSymbol and prefer them over regular metadata', () => {
|
||||
const someSymbol = symbolCache.get('/test.ts', 'a');
|
||||
init({'/test.ts': 'export var a = 2'}, [{symbol: someSymbol, metadata: 1}]);
|
||||
expect(symbolResolver.resolveSymbol(someSymbol).metadata).toBe(1);
|
||||
const symbolA = symbolCache.get('/test.ts', 'a');
|
||||
const symbolB = symbolCache.get('/test.ts', 'b');
|
||||
const symbolC = symbolCache.get('/test.ts', 'c');
|
||||
init({'/test.ts': 'export var a = 2; export var b = 2; export var c = 2;'}, [
|
||||
{symbol: symbolA, metadata: 1},
|
||||
{symbol: symbolB, metadata: 1},
|
||||
]);
|
||||
// reading the metadata of a symbol without a summary first,
|
||||
// to test whether summaries are still preferred after this.
|
||||
expect(symbolResolver.resolveSymbol(symbolC).metadata).toBe(2);
|
||||
expect(symbolResolver.resolveSymbol(symbolA).metadata).toBe(1);
|
||||
expect(symbolResolver.resolveSymbol(symbolB).metadata).toBe(1);
|
||||
});
|
||||
|
||||
it('should be able to get all exported symbols of a file', () => {
|
||||
|
|
Loading…
Reference in New Issue