From fa5e9807e87e0b4bf0dce23bbb3c43e74fd05089 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Fri, 28 Aug 2020 02:29:05 +0300 Subject: [PATCH] fix(40010): add outlining for comments before variables statements (#40016) --- src/services/outliningElementsCollector.ts | 14 +------------- .../fourslash/getOutliningForBlockComments.ts | 6 ++++++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/services/outliningElementsCollector.ts b/src/services/outliningElementsCollector.ts index a001d9c68f2..0baacad43bf 100644 --- a/src/services/outliningElementsCollector.ts +++ b/src/services/outliningElementsCollector.ts @@ -34,14 +34,10 @@ namespace ts.OutliningElementsCollector { if (depthRemaining === 0) return; cancellationToken.throwIfCancellationRequested(); - if (isDeclaration(n) || n.kind === SyntaxKind.EndOfFileToken) { + if (isDeclaration(n) || isVariableStatement(n) || n.kind === SyntaxKind.EndOfFileToken) { addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out); } - if (isFunctionExpressionAssignedToVariable(n)) { - addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out); - } - if (isFunctionLike(n) && isBinaryExpression(n.parent) && isPropertyAccessExpression(n.parent.left)) { addOutliningForLeadingCommentsForNode(n.parent.left, sourceFile, cancellationToken, out); } @@ -70,14 +66,6 @@ namespace ts.OutliningElementsCollector { } depthRemaining++; } - - function isFunctionExpressionAssignedToVariable(n: Node) { - if (!isFunctionExpression(n) && !isArrowFunction(n)) { - return false; - } - const ancestor = findAncestor(n, isVariableStatement); - return !!ancestor && getSingleInitializerOfVariableStatementOrPropertyDeclaration(ancestor) === n; - } } function addRegionOutliningSpans(sourceFile: SourceFile, out: Push): void { diff --git a/tests/cases/fourslash/getOutliningForBlockComments.ts b/tests/cases/fourslash/getOutliningForBlockComments.ts index 567806877ba..82f4648bcbb 100644 --- a/tests/cases/fourslash/getOutliningForBlockComments.ts +++ b/tests/cases/fourslash/getOutliningForBlockComments.ts @@ -111,6 +111,12 @@ //// return y + z; //// }|]; //// +////// Over a variable +////[|/** +//// * foo +//// */|] +////const foo = null; +//// ////function Foo()[| { //// [|/** //// * Description