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
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:48:34 +01:00 committed by Jason Aden
parent 37f69eddc7
commit c9b588b349
1 changed files with 9 additions and 3 deletions

View File

@ -230,15 +230,21 @@ function expandForwardRef(arg: ts.Expression): ts.Expression|null {
*/ */
export function unwrapForwardRef(node: ts.Expression, reflector: ReflectionHost): ts.Expression { export function unwrapForwardRef(node: ts.Expression, reflector: ReflectionHost): ts.Expression {
node = unwrapExpression(node); node = unwrapExpression(node);
if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || if (!ts.isCallExpression(node) || node.arguments.length !== 1) {
node.arguments.length !== 1) {
return node; 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]); const expr = expandForwardRef(node.arguments[0]);
if (expr === null) { if (expr === null) {
return node; return node;
} }
const imp = reflector.getImportOfIdentifier(node.expression); const imp = reflector.getImportOfIdentifier(fn);
if (imp === null || imp.from !== '@angular/core' || imp.name !== 'forwardRef') { if (imp === null || imp.from !== '@angular/core' || imp.name !== 'forwardRef') {
return node; return node;
} else { } else {