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 {
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 {