fix(language-service): Lazily instantiate MetadataResolver (#32631)

The instantiation of the resolver also requires instantiation of the
StaticReflector, and the latter requires resolution of core Angular symbols.
Module resolution should not be done during instantiation to avoid potential
cyclic dependency between the plugin and the containing Project, so the
Singleton pattern is used to create the resolver.

PR Close #32631
This commit is contained in:
Keen Yee Liau
2019-09-11 23:12:58 -07:00
committed by Kara Erickson
parent 7a569a7c52
commit 1771d6ff25
2 changed files with 29 additions and 14 deletions

View File

@ -51,13 +51,11 @@ describe('reflector_host_spec', () => {
const tsLS = ts.createLanguageService(mockHost);
// First count is due to the instantiation of StaticReflector, which
// performs resolutions of core Angular symbols, like `NgModule`.
// TODO: Reduce this count to zero doing lazy instantiation.
// First count is zero due to lazy instantiation of the StaticReflector
// and MetadataResolver.
const ngLSHost = new TypeScriptServiceHost(mockHost, tsLS);
const firstCount = spy.calls.count();
expect(firstCount).toBeGreaterThan(20);
expect(firstCount).toBeLessThan(50);
expect(firstCount).toBe(0);
spy.calls.reset();
// Second count is due to resolution of the Tour of Heroes (toh) project.