Skip to content

Commit fa5e980

Browse files
authored
fix(40010): add outlining for comments before variables statements (#40016)
1 parent 27eb862 commit fa5e980

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ namespace ts.OutliningElementsCollector {
3434
if (depthRemaining === 0) return;
3535
cancellationToken.throwIfCancellationRequested();
3636

37-
if (isDeclaration(n) || n.kind === SyntaxKind.EndOfFileToken) {
37+
if (isDeclaration(n) || isVariableStatement(n) || n.kind === SyntaxKind.EndOfFileToken) {
3838
addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out);
3939
}
4040

41-
if (isFunctionExpressionAssignedToVariable(n)) {
42-
addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out);
43-
}
44-
4541
if (isFunctionLike(n) && isBinaryExpression(n.parent) && isPropertyAccessExpression(n.parent.left)) {
4642
addOutliningForLeadingCommentsForNode(n.parent.left, sourceFile, cancellationToken, out);
4743
}
@@ -70,14 +66,6 @@ namespace ts.OutliningElementsCollector {
7066
}
7167
depthRemaining++;
7268
}
73-
74-
function isFunctionExpressionAssignedToVariable(n: Node) {
75-
if (!isFunctionExpression(n) && !isArrowFunction(n)) {
76-
return false;
77-
}
78-
const ancestor = findAncestor(n, isVariableStatement);
79-
return !!ancestor && getSingleInitializerOfVariableStatementOrPropertyDeclaration(ancestor) === n;
80-
}
8169
}
8270

8371
function addRegionOutliningSpans(sourceFile: SourceFile, out: Push<OutliningSpan>): void {

tests/cases/fourslash/getOutliningForBlockComments.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
//// return y + z;
112112
//// }|];
113113
////
114+
////// Over a variable
115+
////[|/**
116+
//// * foo
117+
//// */|]
118+
////const foo = null;
119+
////
114120
////function Foo()[| {
115121
//// [|/**
116122
//// * Description

0 commit comments

Comments
 (0)