feat(ivy): give ngtsc a basic understanding of ModuleWithProviders (#24738)

This commit changes the @NgModule provider to understand that sometimes
an import will resolve to an object instead of a type, and that object
could be of the ModuleWithProviders type. In that case, the 'ngModule'
property is read, and its value used instead.

This still will not handle ModuleWithProviders references across
compilation units; that work is coming in a future PR.

PR Close #24738
This commit is contained in:
Alex Rickabaugh 2018-06-29 14:03:46 -07:00 committed by Matias Niemelä
parent a1b630ee8f
commit 9f20dd937a
1 changed files with 7 additions and 1 deletions

View File

@ -132,6 +132,12 @@ function resolveTypeList(resolvedList: ResolvedValue, name: string): Reference[]
}
resolvedList.forEach((entry, idx) => {
// Unwrap ModuleWithProviders for modules that are locally declared (and thus static resolution
// was able to descend into the function and return an object literal, a Map).
if (entry instanceof Map && entry.has('ngModule')) {
entry = entry.get('ngModule') !;
}
if (Array.isArray(entry)) {
// Recurse into nested arrays.
refList.push(...resolveTypeList(entry, name));
@ -144,7 +150,7 @@ function resolveTypeList(resolvedList: ResolvedValue, name: string): Reference[]
refList.push(entry);
} else {
// TODO(alxhub): expand ModuleWithProviders.
throw new Error(`Value at position ${idx} in ${name} array is not a reference`);
throw new Error(`Value at position ${idx} in ${name} array is not a reference: ${entry}`);
}
});