diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 299403d8974..a87d0a9e1da 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -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) { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 23011643811..b8af97350f7 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -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: diff --git a/tests/cases/fourslash/formattingArrowFunctionParenthesizedExpression.ts b/tests/cases/fourslash/formattingArrowFunctionParenthesizedExpression.ts new file mode 100644 index 00000000000..de1021bf1c6 --- /dev/null +++ b/tests/cases/fourslash/formattingArrowFunctionParenthesizedExpression.ts @@ -0,0 +1,47 @@ +/// + +// @Filename: Bar.tsx +//// export const Bar = ({ +//// foo, +//// bar, +//// }: any) => ( +////
Hello world
+//// ) +//// +//// export const Bar2 = ({ +//// foo, +//// bar, +//// }) => (
Hello world
) +//// +//// export const Bar2 = ({ +//// foo, +//// bar, +//// }) =>
Hello world
+//// +//// export const Bar3 = ({ +//// foo, +//// bar, +//// }) => +//// (
Hello world
) +//// +//// export const Bar4 = ({ +//// foo, +//// bar, +//// }) => +////
Hello world
+//// +//// export const Bar5 = () => ( +////
Hello world
+//// ) +//// +//// export const Bar6 = () => (
Hello world
) +//// +//// export const Bar7 = () =>
Hello world
+//// +//// export const Bar8 = () => +//// (
Hello world
) +//// +//// export const Bar9 = () => +////
Hello world
+ +verify.formatDocumentChangesNothing();