Skip to content

Commit aa920c0

Browse files
authored
fix(47296): add outlining spans for parenthesized expressions (#47307)
1 parent 2d85e1e commit aa920c0

7 files changed

+53
-12
lines changed

src/services/outliningElementsCollector.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ namespace ts.OutliningElementsCollector {
240240
return spanForArrowFunction(n as ArrowFunction);
241241
case SyntaxKind.CallExpression:
242242
return spanForCallExpression(n as CallExpression);
243+
case SyntaxKind.ParenthesizedExpression:
244+
return spanForParenthesizedExpression(n as ParenthesizedExpression);
243245
}
244246

245247
function spanForCallExpression(node: CallExpression): OutliningSpan | undefined {
@@ -256,7 +258,7 @@ namespace ts.OutliningElementsCollector {
256258
}
257259

258260
function spanForArrowFunction(node: ArrowFunction): OutliningSpan | undefined {
259-
if (isBlock(node.body) || positionsAreOnSameLine(node.body.getFullStart(), node.body.getEnd(), sourceFile)) {
261+
if (isBlock(node.body) || isParenthesizedExpression(node.body) || positionsAreOnSameLine(node.body.getFullStart(), node.body.getEnd(), sourceFile)) {
260262
return undefined;
261263
}
262264
const textSpan = createTextSpanFromBounds(node.body.getFullStart(), node.body.getEnd());
@@ -307,6 +309,12 @@ namespace ts.OutliningElementsCollector {
307309
function spanForNodeArray(nodeArray: NodeArray<Node>): OutliningSpan | undefined {
308310
return nodeArray.length ? createOutliningSpan(createTextSpanFromRange(nodeArray), OutliningSpanKind.Code) : undefined;
309311
}
312+
313+
function spanForParenthesizedExpression(node: ParenthesizedExpression): OutliningSpan | undefined {
314+
if (positionsAreOnSameLine(node.getStart(), node.getEnd(), sourceFile)) return undefined;
315+
const textSpan = createTextSpanFromBounds(node.getStart(), node.getEnd());
316+
return createOutliningSpan(textSpan, OutliningSpanKind.Code, createTextSpanFromNode(node));
317+
}
310318
}
311319

312320
function functionSpan(node: SignatureDeclaration, body: Block, sourceFile: SourceFile): OutliningSpan | undefined {

tests/cases/fourslash/getJSXOutliningSpans.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
////
33
////export class Home extends Component[| {
44
//// render()[| {
5-
//// return (
5+
//// return [|(
66
//// [|<div>
77
//// [|<h1>Hello, world!</h1>|]
88
//// [|<ul>
@@ -29,7 +29,7 @@
2929
//// text
3030
//// </>|]
3131
//// </div>|]
32-
//// );
32+
//// )|];
3333
//// }|]
3434
////}|]
3535

tests/cases/fourslash/getOutliningSpans.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
//// }|]
2727
////}|]
2828
////// class expressions
29-
//// (new class[| {
29+
//// [|(new class[| {
3030
//// bla()[| {
3131
////
3232
//// }|]
33-
//// }|])
33+
//// }|])|]
3434
////switch(1)[| {
3535
//// case 1:[| break;|]
3636
////}|]
@@ -64,9 +64,9 @@
6464
////}|]
6565
////
6666
////// function expressions
67-
////(function f()[| {
67+
////[|(function f()[| {
6868
////
69-
////}|])
69+
////}|])|]
7070
////
7171
////// trivia handeling
7272
////class ClassFooWithTrivia[| /* some comments */

tests/cases/fourslash/outliningSpansForArrowFunctionBody.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//// () =>[| {
66
//// 42
77
//// }|];
8-
//// () =>[| (
8+
//// () => [|(
99
//// 42
1010
//// )|];
1111
//// () =>[| "foo" +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////const a = [|(
4+
//// true
5+
//// ? true
6+
//// : false
7+
//// ? true
8+
//// : false
9+
////)|];
10+
////
11+
////const b = ( 1 );
12+
////
13+
////const c = [|(
14+
//// 1
15+
////)|];
16+
////
17+
////( 1 );
18+
////
19+
////[|(
20+
//// [|(
21+
//// [|(
22+
//// 1
23+
//// )|]
24+
//// )|]
25+
////)|];
26+
////
27+
////[|(
28+
//// [|(
29+
//// ( 1 )
30+
//// )|]
31+
////)|];
32+
33+
verify.outliningSpansInCurrentFile(test.ranges());

tests/cases/fourslash/shims-pp/getOutliningSpans.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
////}|]
5959
////
6060
////// function expressions
61-
////(function f()[| {
61+
////[|(function f()[| {
6262
////
63-
////}|])
63+
////}|])|]
6464
////
6565
////// trivia handeling
6666
////class ClassFooWithTrivia[| /* some comments */

tests/cases/fourslash/shims/getOutliningSpans.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
////}|]
5959
////
6060
////// function expressions
61-
////(function f()[| {
61+
////[|(function f()[| {
6262
////
63-
////}|])
63+
////}|])|]
6464
////
6565
////// trivia handeling
6666
////class ClassFooWithTrivia[| /* some comments */

0 commit comments

Comments
 (0)