Skip to content

Commit 19ce735

Browse files
committed
refactor(@angular-devkit/build-optimizer): remove casts from tslib helper check
1 parent 0c528f1 commit 19ce735

File tree

1 file changed

+14
-22
lines changed
  • packages/angular_devkit/build_optimizer/src/transforms

1 file changed

+14
-22
lines changed

packages/angular_devkit/build_optimizer/src/transforms/scrub-file.ts

+14-22
Original file line numberDiff line numberDiff line change
@@ -593,35 +593,27 @@ function isTslibHelper(
593593
tslibImports: ts.NamespaceImport[],
594594
checker: ts.TypeChecker,
595595
) {
596+
let name;
596597

597-
let callExprIdent = callExpr.expression as ts.Identifier;
598+
if (ts.isIdentifier(callExpr.expression)) {
599+
name = callExpr.expression.text;
600+
} else if (ts.isPropertyAccessExpression(callExpr.expression)) {
601+
const left = callExpr.expression.expression;
598602

599-
if (callExpr.expression.kind !== ts.SyntaxKind.Identifier) {
600-
if (callExpr.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
601-
const propAccess = callExpr.expression as ts.PropertyAccessExpression;
602-
const left = propAccess.expression;
603-
callExprIdent = propAccess.name;
604-
605-
if (left.kind !== ts.SyntaxKind.Identifier) {
606-
return false;
607-
}
608-
609-
const id = left as ts.Identifier;
610-
611-
if (!identifierIsTslib(id, tslibImports, checker)) {
612-
return false;
613-
}
603+
if (!ts.isIdentifier(left)) {
604+
return false;
605+
}
614606

615-
} else {
607+
if (!identifierIsTslib(left, tslibImports, checker)) {
616608
return false;
617609
}
618-
}
619610

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

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

0 commit comments

Comments
 (0)