Skip to content

Commit c00aeb5

Browse files
authored
fix(33286): add outlining for arrow function with one parameter (microsoft#38631)
1 parent 45cf20c commit c00aeb5

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

src/services/outliningElementsCollector.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ namespace ts.OutliningElementsCollector {
276276
}
277277

278278
function functionSpan(node: FunctionLike, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {
279-
const openToken = isNodeArrayMultiLine(node.parameters, sourceFile)
280-
? findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile)
281-
: findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
279+
const openToken = tryGetFunctionOpenToken(node, body, sourceFile);
282280
const closeToken = findChildOfKind(body, SyntaxKind.CloseBraceToken, sourceFile);
283281
return openToken && closeToken && spanBetweenTokens(openToken, closeToken, node, sourceFile, /*autoCollapse*/ node.kind !== SyntaxKind.ArrowFunction);
284282
}
@@ -291,4 +289,14 @@ namespace ts.OutliningElementsCollector {
291289
function createOutliningSpan(textSpan: TextSpan, kind: OutliningSpanKind, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan {
292290
return { textSpan, kind, hintSpan, bannerText, autoCollapse };
293291
}
292+
293+
function tryGetFunctionOpenToken(node: FunctionLike, body: Block, sourceFile: SourceFile): Node | undefined {
294+
if (isNodeArrayMultiLine(node.parameters, sourceFile)) {
295+
const openParenToken = findChildOfKind(node, SyntaxKind.OpenParenToken, sourceFile);
296+
if (openParenToken) {
297+
return openParenToken;
298+
}
299+
}
300+
return findChildOfKind(body, SyntaxKind.OpenBraceToken, sourceFile);
301+
}
294302
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,84 @@
11
/// <reference path="fourslash.ts"/>
22

3-
////function f(x: number, y: number)[| {
4-
//// return x + y;
3+
////[|(
4+
//// a: number,
5+
//// b: number
6+
////) => {
7+
//// return a + b;
8+
////}|]
9+
/////
10+
////(a: number, b: number) => [|{
11+
//// return a + b;
12+
////}|]
13+
////
14+
////const f1 = function[| (
15+
//// a: number
16+
//// b: number
17+
////) {
18+
//// return a + b;
19+
////}|]
20+
////
21+
////const f2 = function (a: number, b: number)[| {
22+
//// return a + b;
523
////}|]
624
////
7-
////function g[|(
8-
//// x: number,
9-
//// y: number,
10-
////): number {
11-
//// return x + y;
25+
////function f3[| (
26+
//// a: number
27+
//// b: number
28+
////) {
29+
//// return a + b;
1230
////}|]
31+
////
32+
////function f4(a: number, b: number)[| {
33+
//// return a + b;
34+
////}|]
35+
////
36+
////class Foo[| {
37+
//// constructor[|(
38+
//// a: number,
39+
//// b: number
40+
//// ) {
41+
//// this.a = a;
42+
//// this.b = b;
43+
//// }|]
44+
////
45+
//// m1[|(
46+
//// a: number,
47+
//// b: number
48+
//// ) {
49+
//// return a + b;
50+
//// }|]
51+
////
52+
//// m1(a: number, b: number)[| {
53+
//// return a + b;
54+
//// }|]
55+
////}|]
56+
////
57+
////declare function foo(props: any): void;
58+
////foo(
59+
//// a =>[| {
60+
////
61+
//// }|]
62+
////)
63+
////
64+
////foo(
65+
//// (a) =>[| {
66+
////
67+
//// }|]
68+
////)
69+
////
70+
////foo(
71+
//// (a, b, c) =>[| {
72+
////
73+
//// }|]
74+
////)
75+
////
76+
////foo([|
77+
//// (a,
78+
//// b,
79+
//// c) => {
80+
////
81+
//// }|]
82+
////)
1383

1484
verify.outliningSpansInCurrentFile(test.ranges());

0 commit comments

Comments
 (0)