-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(60887): Incorrect Formatting on if (a) try {} finally {} #60898
base: main
Are you sure you want to change the base?
Conversation
@@ -729,6 +730,12 @@ export namespace SmartIndenter { | |||
return false; | |||
} | |||
break; | |||
case SyntaxKind.TryStatement: | |||
const tryStatement = parent as TryStatement; | |||
if (tryStatement.finallyBlock && tryStatement.finallyBlock === child) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suspicious about this just because all of the other code in this switch case are only checking syntax kind or position info, not node equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakebailey thanks for the feedback. I found that in this case, the finallyBlock
should not be handled as a child of the try block to ensure the correct delta calculation
const delta = SmartIndenter.shouldIndentChildNode(options, node) ? options.indentSize! : 0; |
There are other places where we handle the finallyBlock
in a similar way
TypeScript/src/services/outliningElementsCollector.ts
Lines 259 to 261 in 5170645
else if (tryStatement.finallyBlock === n) { | |
const node = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile); | |
if (node) return spanForNode(node); |
I hope that makes sense., if you have any thoughts or suggestions, I’d be grateful to hear them. thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this bug not affect the try block or the catch block, then? Maybe I'm missing something...
@typescript-bot pack this |
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
Fixes #60887