From 2c3be449ff2e883d67135cbe889db982f66a224c Mon Sep 17 00:00:00 2001 From: "Oleksandr T." Date: Mon, 24 Feb 2025 21:51:28 +0200 Subject: [PATCH] fix(60887): Incorrect Formatting on if (a) try {} finally {} (#60898) --- src/services/formatting/smartIndenter.ts | 5 +++++ tests/cases/fourslash/formatTryFinally.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/cases/fourslash/formatTryFinally.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index c6ed975a1a5..7f41a2701b8 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -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; diff --git a/tests/cases/fourslash/formatTryFinally.ts b/tests/cases/fourslash/formatTryFinally.ts new file mode 100644 index 00000000000..d81cd45e793 --- /dev/null +++ b/tests/cases/fourslash/formatTryFinally.ts @@ -0,0 +1,15 @@ +/// + +////if (true) try { +//// // ... +////} finally { +//// // ... +////} + +format.document(); +verify.currentFileContentIs( +`if (true) try { + // ... +} finally { + // ... +}`);