Merge pull request #29218 from uniqueiniquity/jsdocSpanForVarStatement

Jsdoc span for var statement
This commit is contained in:
Benjamin Lichtman
2018-12-31 16:27:34 -08:00
committed by GitHub
3 changed files with 24 additions and 1 deletions

View File

@@ -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);

View File

@@ -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 {