Skip to content

Commit 11585d2

Browse files
Merge pull request #29218 from uniqueiniquity/jsdocSpanForVarStatement
Jsdoc span for var statement
2 parents aebcb6d + 048d046 commit 11585d2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ namespace ts {
21212121
: undefined;
21222122
}
21232123

2124-
function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined {
2124+
export function getSingleInitializerOfVariableStatementOrPropertyDeclaration(node: Node): Expression | undefined {
21252125
switch (node.kind) {
21262126
case SyntaxKind.VariableStatement:
21272127
const v = getSingleVariableOfVariableStatement(node);

src/services/outliningElementsCollector.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ namespace ts.OutliningElementsCollector {
3737
addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out);
3838
}
3939

40+
if (isFunctionExpressionAssignedToVariable(n)) {
41+
addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out);
42+
}
43+
4044
const span = getOutliningSpanForNode(n, sourceFile);
4145
if (span) out.push(span);
4246

@@ -54,6 +58,14 @@ namespace ts.OutliningElementsCollector {
5458
}
5559
depthRemaining++;
5660
}
61+
62+
function isFunctionExpressionAssignedToVariable(n: Node) {
63+
if (!isFunctionExpression(n) && !isArrowFunction(n)) {
64+
return false;
65+
}
66+
const ancestor = findAncestor(n, isVariableStatement);
67+
return !!ancestor && getSingleInitializerOfVariableStatementOrPropertyDeclaration(ancestor) === n;
68+
}
5769
}
5870

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

tests/cases/fourslash/getOutliningForBlockComments.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@
9999
//// return 1;
100100
//// }|]
101101
////}|]
102+
////
103+
////// Over a function expression assigned to a variable
104+
//// [|/**
105+
//// * Return a sum
106+
//// * @param {Number} y
107+
//// * @param {Number} z
108+
//// * @returns {Number} the sum of y and z
109+
//// */|]
110+
//// const sum2 = (y, z) =>[| {
111+
//// return y + z;
112+
//// }|];
102113

103114
verify.outliningSpansInCurrentFile(test.ranges());
104115

0 commit comments

Comments
 (0)