fix(33286): add outlining for arrow function with one parameter (#38631)

This commit is contained in:
Alexander T
2020-05-21 18:07:47 +03:00
committed by GitHub
parent 45cf20ca70
commit c00aeb5486
2 changed files with 88 additions and 10 deletions

View File

@@ -276,9 +276,7 @@ namespace ts.OutliningElementsCollector {
}
function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {
const openToken = isNodeArrayMultiLine(node.parameters, sourceFile)
? findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile)
: findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
const openToken = tryGetFunctionOpenToken(node, body, sourceFile);
const closeToken = findChildOfKind(body, SyntaxKind.CloseBraceToken, sourceFile);
return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== SyntaxKind.ArrowFunction);
}
@@ -291,4 +289,14 @@ namespace ts.OutliningElementsCollector {
function createOutliningSpan(textSpan: TextSpan, kind: OutliningSpanKind, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan {
return { textSpan, kind, hintSpan, bannerText, autoCollapse };
}
function tryGetFunctionOpenToken(node: FunctionLike, body: Block, sourceFile: SourceFile): Node | undefined {
if (isNodeArrayMultiLine(node.parameters, sourceFile)) {
const openParenToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
if (openParenToken) {
return openParenToken;
}
}
return findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
}
}