Fix indentation of arrow functions returning parenthesized expressions (#40677)

* Fix indentation of arrow functions returning parenthesized expressions

* Add more test cases
This commit is contained in:
Andrew Branch
2020-09-22 17:16:09 -07:00
committed by GitHub
parent aa30121dd1
commit 9eb6424b8f
3 changed files with 53 additions and 3 deletions

View File

@@ -2461,8 +2461,7 @@ namespace FourSlash {
const { fileName } = this.activeFile;
const before = this.getFileContent(fileName);
this.formatDocument();
const after = this.getFileContent(fileName);
this.assertObjectsEqual(after, before);
this.verifyFileContent(fileName, before);
}
public verifyTextAtCaretIs(text: string) {

View File

@@ -558,11 +558,15 @@ namespace ts.formatting {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.ArrowFunction:
case SyntaxKind.Constructor:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return childKind !== SyntaxKind.Block;
case SyntaxKind.ArrowFunction:
if (sourceFile && childKind === SyntaxKind.ParenthesizedExpression) {
return rangeIsOnOneLine(sourceFile, child!);
}
return childKind !== SyntaxKind.Block;
case SyntaxKind.ExportDeclaration:
return childKind !== SyntaxKind.NamedExports;
case SyntaxKind.ImportDeclaration:

View File

@@ -0,0 +1,47 @@
/// <reference path="fourslash.ts" />
// @Filename: Bar.tsx
//// export const Bar = ({
//// foo,
//// bar,
//// }: any) => (
//// <div>Hello world</div>
//// )
////
//// export const Bar2 = ({
//// foo,
//// bar,
//// }) => (<div>Hello world</div>)
////
//// export const Bar2 = ({
//// foo,
//// bar,
//// }) => <div>Hello world</div>
////
//// export const Bar3 = ({
//// foo,
//// bar,
//// }) =>
//// (<div>Hello world</div>)
////
//// export const Bar4 = ({
//// foo,
//// bar,
//// }) =>
//// <div>Hello world</div>
////
//// export const Bar5 = () => (
//// <div>Hello world</div>
//// )
////
//// export const Bar6 = () => (<div>Hello world</div>)
////
//// export const Bar7 = () => <div>Hello world</div>
////
//// export const Bar8 = () =>
//// (<div>Hello world</div>)
////
//// export const Bar9 = () =>
//// <div>Hello world</div>
verify.formatDocumentChangesNothing();