use existing util functions

This commit is contained in:
Benjamin Lichtman 2018-12-31 15:56:54 -08:00
parent bb2f300191
commit 048d04684b
2 changed files with 6 additions and 4 deletions

View File

@ -2121,7 +2121,7 @@ namespace ts {
: undefined;
}
function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined {
export function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined {
switch (node.kind) {
case SyntaxKind.VariableStatement:
const v = getSingleVariableOfVariableStatement(node);

View File

@ -60,9 +60,11 @@ namespace ts.OutliningElementsCollector {
}
function isFunctionExpressionAssignedToVariable(n: Node) {
return (isFunctionExpression(n) || isArrowFunction(n)) &&
n.parent && n.parent.parent && n.parent.parent.parent &&
isVariableStatement(n.parent.parent.parent);
if (!isFunctionExpression(n) && !isArrowFunction(n)) {
return false;
}
const ancestor = findAncestor(n, isVariableStatement);
return !!ancestor && getSingleInitializerOfVariableStatementOrPropertyDeclaration(ancestor) === n;
}
}