Skip to content

Commit

Permalink
fix(60887): Incorrect Formatting on if (a) try {} finally {} (#60898)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk authored Feb 24, 2025
1 parent 8ae98d0 commit 2c3be44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/services/formatting/smartIndenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@ export namespace SmartIndenter {
return false;
}
break;
case SyntaxKind.TryStatement:
if (childKind === SyntaxKind.Block) {
return false;
}
break;
}
// No explicit rule for given nodes so the result will follow the default value argument
return indentByDefault;
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/fourslash/formatTryFinally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts"/>

////if (true) try {
//// // ...
////} finally {
//// // ...
////}

format.document();
verify.currentFileContentIs(
`if (true) try {
// ...
} finally {
// ...
}`);

0 comments on commit 2c3be44

Please sign in to comment.