Skip to content

Commit ee5c3fa

Browse files
authored
fix(39047): handle extra spaces after the catch statement (microsoft#39306)
1 parent 58ed610 commit ee5c3fa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/services/formatting/rules.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ namespace ts.formatting {
348348
anyToken,
349349
[isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNotForContext],
350350
RuleAction.InsertSpace),
351-
// This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
352-
rule("SpaceAfterTryFinally", [SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
351+
// This low-pri rule takes care of "try {", "catch {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
352+
rule("SpaceAfterTryCatchFinally", [SyntaxKind.TryKeyword, SyntaxKind.CatchKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
353353
];
354354

355355
return [

tests/cases/fourslash/formatCatch.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////try {
4+
////} /*0*/catch {
5+
////}
6+
////
7+
////try {
8+
////} /*1*/catch{
9+
////}
10+
11+
format.document();
12+
13+
for (const marker of test.markers()) {
14+
goTo.marker(marker);
15+
verify.currentLineContentIs("} catch {");
16+
}

0 commit comments

Comments
 (0)