Skip to content

Commit 9eb6424

Browse files
authored
Fix indentation of arrow functions returning parenthesized expressions (#40677)
* Fix indentation of arrow functions returning parenthesized expressions * Add more test cases
1 parent aa30121 commit 9eb6424

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/harness/fourslashImpl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,8 +2461,7 @@ namespace FourSlash {
24612461
const { fileName } = this.activeFile;
24622462
const before = this.getFileContent(fileName);
24632463
this.formatDocument();
2464-
const after = this.getFileContent(fileName);
2465-
this.assertObjectsEqual(after, before);
2464+
this.verifyFileContent(fileName, before);
24662465
}
24672466

24682467
public verifyTextAtCaretIs(text: string) {

src/services/formatting/smartIndenter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,15 @@ namespace ts.formatting {
558558
case SyntaxKind.FunctionDeclaration:
559559
case SyntaxKind.FunctionExpression:
560560
case SyntaxKind.MethodDeclaration:
561-
case SyntaxKind.ArrowFunction:
562561
case SyntaxKind.Constructor:
563562
case SyntaxKind.GetAccessor:
564563
case SyntaxKind.SetAccessor:
565564
return childKind !== SyntaxKind.Block;
565+
case SyntaxKind.ArrowFunction:
566+
if (sourceFile && childKind === SyntaxKind.ParenthesizedExpression) {
567+
return rangeIsOnOneLine(sourceFile, child!);
568+
}
569+
return childKind !== SyntaxKind.Block;
566570
case SyntaxKind.ExportDeclaration:
567571
return childKind !== SyntaxKind.NamedExports;
568572
case SyntaxKind.ImportDeclaration:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: Bar.tsx
4+
//// export const Bar = ({
5+
//// foo,
6+
//// bar,
7+
//// }: any) => (
8+
//// <div>Hello world</div>
9+
//// )
10+
////
11+
//// export const Bar2 = ({
12+
//// foo,
13+
//// bar,
14+
//// }) => (<div>Hello world</div>)
15+
////
16+
//// export const Bar2 = ({
17+
//// foo,
18+
//// bar,
19+
//// }) => <div>Hello world</div>
20+
////
21+
//// export const Bar3 = ({
22+
//// foo,
23+
//// bar,
24+
//// }) =>
25+
//// (<div>Hello world</div>)
26+
////
27+
//// export const Bar4 = ({
28+
//// foo,
29+
//// bar,
30+
//// }) =>
31+
//// <div>Hello world</div>
32+
////
33+
//// export const Bar5 = () => (
34+
//// <div>Hello world</div>
35+
//// )
36+
////
37+
//// export const Bar6 = () => (<div>Hello world</div>)
38+
////
39+
//// export const Bar7 = () => <div>Hello world</div>
40+
////
41+
//// export const Bar8 = () =>
42+
//// (<div>Hello world</div>)
43+
////
44+
//// export const Bar9 = () =>
45+
//// <div>Hello world</div>
46+
47+
verify.formatDocumentChangesNothing();

0 commit comments

Comments
 (0)