fix(compiler-cli): attach the correct viaModule to namespace imports (#33495)

Previously declarations that were imported via a namespace import
were given the same `bestGuessOwningModule` as the context
where they were imported to. This causes problems with resolving
`ModuleWithProviders` that have a type that has been imported in
this way, causing errors like:

```
ERROR in Symbol UIRouterModule declared in
.../@uirouter/angular/uiRouterNgModule.d.ts
is not exported from
.../@uirouter/angular/uirouter-angular.d.ts
(import into .../src/app/child.module.ts)
```

This commit modifies the `TypescriptReflectionHost.getDirectImportOfIdentifier()`
method so that it also understands how to attach the correct `viaModule` to
the identifier of the namespace import.

Resolves #32166

PR Close #33495
This commit is contained in:
Pete Bacon Darwin
2019-10-30 19:02:30 +00:00
committed by atscott
parent d5ae854b5b
commit 1d141a8ab1
4 changed files with 62 additions and 14 deletions

View File

@ -1558,7 +1558,7 @@ runInEachFileSystem(() => {
const actualDeclaration = host.getDeclarationOfIdentifier(identifier);
expect(actualDeclaration).not.toBe(null);
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
expect(actualDeclaration !.viaModule).toBe(null);
expect(actualDeclaration !.viaModule).toBe('@angular/core');
});
it('should return the original declaration of an aliased class', () => {

View File

@ -1788,7 +1788,7 @@ runInEachFileSystem(() => {
const actualDeclaration = host.getDeclarationOfIdentifier(identifier);
expect(actualDeclaration).not.toBe(null);
expect(actualDeclaration !.node).toBe(expectedDeclarationNode);
expect(actualDeclaration !.viaModule).toBe(null);
expect(actualDeclaration !.viaModule).toBe('@angular/core');
});
it('should return the correct declaration for an inner function identifier inside an ES5 IIFE',