From 048d04684bd79722c83c42ccf2530e491cde54a9 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Mon, 31 Dec 2018 15:56:54 -0800 Subject: [PATCH] use existing util functions --- src/compiler/utilities.ts | 2 +- src/services/outliningElementsCollector.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 23c92216c56..9c6b27de13c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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); diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index 3f4d345be8c..c6080277fc7 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -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; } }