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: