Skip to content

Commit dd4acdd

Browse files
committed
fix(33286): add outlining for arrow function with one parameter
1 parent 7fc456f commit dd4acdd

4 files changed

+41
-3
lines changed

src/services/outliningElementsCollector.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ namespace ts.OutliningElementsCollector {
272272
}
273273

274274
function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {
275-
const openToken = isNodeArrayMultiLine(node.parameters, sourceFile)
276-
? findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile)
277-
: findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
275+
const openToken = tryGetFunctionOpenToken(node, body, sourceFile);
278276
const closeToken = findChildOfKind(body, SyntaxKind.CloseBraceToken, sourceFile);
279277
return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== SyntaxKind.ArrowFunction);
280278
}
@@ -287,4 +285,14 @@ namespace ts.OutliningElementsCollector {
287285
function createOutliningSpan(textSpan: TextSpan, kind: OutliningSpanKind, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan {
288286
return { textSpan, kind, hintSpan, bannerText, autoCollapse };
289287
}
288+
289+
function tryGetFunctionOpenToken(node: FunctionLike, body: Block, sourceFile: SourceFile): Node | undefined {
290+
if (isNodeArrayMultiLine(node.parameters, sourceFile)) {
291+
const openParenToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
292+
if (openParenToken) {
293+
return openParenToken;
294+
}
295+
}
296+
return findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
297+
}
290298
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////declare function foo(props: any);
4+
////foo(
5+
//// a =>[| {
6+
////
7+
//// }|]
8+
////)
9+
10+
verify.outliningSpansInCurrentFile(test.ranges(), "code");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////declare function foo(props: any);
4+
////foo(
5+
//// (a) =>[| {
6+
////
7+
//// }|]
8+
////)
9+
10+
verify.outliningSpansInCurrentFile(test.ranges(), "code");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////declare function foo(props: any);
4+
////foo(
5+
//// (a, b, c) =>[| {
6+
////
7+
//// }|]
8+
////)
9+
10+
verify.outliningSpansInCurrentFile(test.ranges(), "code");

0 commit comments

Comments
 (0)