From c9b588b3497c03baa978b1aadd19a99b8885ec8a Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sun, 28 Apr 2019 20:48:34 +0100 Subject: [PATCH] feat(ivy): ngtsc - support namespaced `forwardRef` calls (#25445) In some cases the `forwardRef` helper has been imported via a namespace, e.g. `core.forwardRef(...)`. This commit adds support for unwrapping such namespaced imports when ngtsc is statically evaluating code. PR Close #25445 --- .../compiler-cli/src/ngtsc/annotations/src/util.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/util.ts b/packages/compiler-cli/src/ngtsc/annotations/src/util.ts index b8f9bff340..a9866b33e8 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/util.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/util.ts @@ -230,15 +230,21 @@ function expandForwardRef(arg: ts.Expression): ts.Expression|null { */ export function unwrapForwardRef(node: ts.Expression, reflector: ReflectionHost): ts.Expression { node = unwrapExpression(node); - if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || - node.arguments.length !== 1) { + if (!ts.isCallExpression(node) || node.arguments.length !== 1) { return node; } + + const fn = + ts.isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression; + if (!ts.isIdentifier(fn)) { + return node; + } + const expr = expandForwardRef(node.arguments[0]); if (expr === null) { return node; } - const imp = reflector.getImportOfIdentifier(node.expression); + const imp = reflector.getImportOfIdentifier(fn); if (imp === null || imp.from !== '@angular/core' || imp.name !== 'forwardRef') { return node; } else {