Skip to content

Commit

Permalink
refactor(@angular-devkit/build-optimizer): remove casts from tslib he…
Browse files Browse the repository at this point in the history
…lper check
  • Loading branch information
clydin authored and mgechev committed Apr 6, 2020
1 parent 2885a93 commit 4f3eab9
Showing 1 changed file with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,35 +593,27 @@ function isTslibHelper(
tslibImports: ts.NamespaceImport[],
checker: ts.TypeChecker,
) {
let name;

let callExprIdent = callExpr.expression as ts.Identifier;
if (ts.isIdentifier(callExpr.expression)) {
name = callExpr.expression.text;
} else if (ts.isPropertyAccessExpression(callExpr.expression)) {
const left = callExpr.expression.expression;

if (callExpr.expression.kind !== ts.SyntaxKind.Identifier) {
if (callExpr.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
const propAccess = callExpr.expression as ts.PropertyAccessExpression;
const left = propAccess.expression;
callExprIdent = propAccess.name;

if (left.kind !== ts.SyntaxKind.Identifier) {
return false;
}

const id = left as ts.Identifier;

if (!identifierIsTslib(id, tslibImports, checker)) {
return false;
}
if (!ts.isIdentifier(left)) {
return false;
}

} else {
if (!identifierIsTslib(left, tslibImports, checker)) {
return false;
}
}

// node.text on a name that starts with two underscores will return three instead.
// Unless it's an expression like tslib.__decorate, in which case it's only 2.
if (callExprIdent.text !== `_${helper}` && callExprIdent.text !== helper) {
name = callExpr.expression.name.text;
} else {
return false;
}

return true;
// node.text on a name that starts with two underscores will return three instead.
// Unless it's an expression like tslib.__decorate, in which case it's only 2.
return name === `_${helper}` || name === helper;
}

0 comments on commit 4f3eab9

Please sign in to comment.