mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
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:
@@ -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) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user