fix(ivy): support finding the import of namespace-imported identifiers (#27675)

Currently there is no support in ngtsc for imports of the form:

```
import * as core from `@angular/core`

export function forRoot(): core.ModuleWithProviders;
```

This commit modifies the `ReflectionHost.getImportOfIdentifier(id)`
method, so that it supports this kind of return type.

PR Close #27675
This commit is contained in:
Pete Bacon Darwin
2018-12-11 13:55:45 +00:00
committed by Jason Aden
parent 8bfaaf164a
commit 63013f1aeb
3 changed files with 148 additions and 39 deletions

View File

@ -286,12 +286,19 @@ export class NgModuleDecoratorHandler implements DecoratorHandler<NgModuleAnalys
*/
private _reflectModuleFromTypeParam(type: ts.TypeNode): ts.Expression|null {
// Examine the type of the function to see if it's a ModuleWithProviders reference.
if (!ts.isTypeReferenceNode(type) || !ts.isIdentifier(type.typeName)) {
if (!ts.isTypeReferenceNode(type)) {
return null;
}
const typeName = type && (ts.isIdentifier(type.typeName) && type.typeName ||
ts.isQualifiedName(type.typeName) && type.typeName.right) ||
null;
if (typeName === null) {
return null;
}
// Look at the type itself to see where it comes from.
const id = this.reflector.getImportOfIdentifier(type.typeName);
const id = this.reflector.getImportOfIdentifier(typeName);
// If it's not named ModuleWithProviders, bail.
if (id === null || id.name !== 'ModuleWithProviders') {