mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #29218 from uniqueiniquity/jsdocSpanForVarStatement
Jsdoc span for var statement
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -37,6 +37,10 @@ namespace ts.OutliningElementsCollector {
|
||||
addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
if (isFunctionExpressionAssignedToVariable(n)) {
|
||||
addOutliningForLeadingCommentsForNode(n.parent.parent.parent, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
const span = getOutliningSpanForNode(n, sourceFile);
|
||||
if (span) out.push(span);
|
||||
|
||||
@@ -54,6 +58,14 @@ 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<OutliningSpan>): void {
|
||||
|
||||
@@ -99,6 +99,17 @@
|
||||
//// return 1;
|
||||
//// }|]
|
||||
////}|]
|
||||
////
|
||||
////// Over a function expression assigned to a variable
|
||||
//// [|/**
|
||||
//// * Return a sum
|
||||
//// * @param {Number} y
|
||||
//// * @param {Number} z
|
||||
//// * @returns {Number} the sum of y and z
|
||||
//// */|]
|
||||
//// const sum2 = (y, z) =>[| {
|
||||
//// return y + z;
|
||||
//// }|];
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user