Skip to content

Commit

Permalink
fix(compiler): always check summaries first before falling back to me…
Browse files Browse the repository at this point in the history
…tadata from .d.ts files (#18788)

PR Close #18788
  • Loading branch information
tbosch authored and mhevery committed Aug 28, 2017
1 parent 0262e37 commit f83b819
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 10 additions & 8 deletions packages/compiler/src/aot/static_symbol_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) !;
}

/**
Expand Down
15 changes: 12 additions & 3 deletions packages/compiler/test/aot/static_symbol_resolver_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f83b819

Please sign in to comment.