fix(ngcc): support UMD global factory in comma lists (#32709)

Previously we were looking for a global factory call that looks like:

```ts
(factory((global.ng = global.ng || {}, global.ng.common = {}), global.ng.core))"
```

but in some cases it looks like:

```ts
(global = global || self, factory((global.ng = global.ng || {}, global.ng.common = {}), global.ng.core))"
```

Note the `global = global || self` at the start of the statement.

This commit makes the test when finding the global factory
function call resilient to being in a comma list.

PR Close #32709
This commit is contained in:
Pete Bacon Darwin
2019-09-17 03:57:31 +01:00
committed by Andrew Kushnir
parent 894c4b5390
commit e5a3de575f
2 changed files with 36 additions and 3 deletions

View File

@ -204,15 +204,21 @@ function isAmdConditional(value: ts.Node): value is AmdConditional {
*/
function isGlobalFactoryCall(value: ts.Node): value is ts.CallExpression {
if (ts.isCallExpression(value) && !!value.parent) {
// Be resilient to the value being part of a comma list
value = isCommaExpression(value.parent) ? value.parent : value;
// Be resilient to the value being inside parentheses
const expression = ts.isParenthesizedExpression(value.parent) ? value.parent : value;
return !!expression.parent && ts.isConditionalExpression(expression.parent) &&
expression.parent.whenFalse === expression;
value = ts.isParenthesizedExpression(value.parent) ? value.parent : value;
return !!value.parent && ts.isConditionalExpression(value.parent) &&
value.parent.whenFalse === value;
} else {
return false;
}
}
function isCommaExpression(value: ts.Node): value is ts.BinaryExpression {
return ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.CommaToken;
}
function getGlobalIdentifier(i: Import) {
return i.specifier.replace('@angular/', 'ng.').replace(/^\//, '');
}