fix(55998): Ability to Place Open Brace On New Line For Try Catch Blocks (#56021)

This commit is contained in:
Oleksandr T 2023-11-03 15:02:20 +02:00 committed by GitHub
parent e6d0f722e0
commit 65f33a2e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -91,7 +91,7 @@ export function getAllRules(): RuleSpec[] {
const typeScriptOpenBraceLeftTokenRange = tokenRangeFrom([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.ClassKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ImportKeyword]);
// Place a space before open brace in a control flow construct
const controlOpenBraceLeftTokenRange = tokenRangeFrom([SyntaxKind.CloseParenToken, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.DoKeyword, SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword, SyntaxKind.ElseKeyword]);
const controlOpenBraceLeftTokenRange = tokenRangeFrom([SyntaxKind.CloseParenToken, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.DoKeyword, SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CatchKeyword]);
// These rules are higher in priority than user-configurable
const highPriorityCommonRules = [

View File

@ -0,0 +1,28 @@
/// <reference path="fourslash.ts"/>
////try {
////}
////catch {
////}
////
////try {
////}
////catch (e) {
////}
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
format.document();
verify.currentFileContentIs(
`try
{
}
catch
{
}
try
{
}
catch (e)
{
}`);