From 9f20dd937aa1a1a8fe3a3eace4238f9783db6395 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Fri, 29 Jun 2018 14:03:46 -0700 Subject: [PATCH] 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 --- .../compiler-cli/src/ngtsc/annotations/src/ng_module.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts index dd5c304194..5a7df1c339 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -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}`); } });