Skip to content

Commit 0701ed5

Browse files
author
Andy
authored
isControlFlowEndingStatement: don't try to enumerate all possible parent kinds (#22131)
1 parent 928ffaa commit 0701ed5

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -565,26 +565,14 @@ namespace ts.formatting {
565565
function isControlFlowEndingStatement(kind: SyntaxKind, parent: TextRangeWithKind): boolean {
566566
switch (kind) {
567567
case SyntaxKind.ReturnStatement:
568-
case SyntaxKind.ThrowStatement:
569-
switch (parent.kind) {
570-
case SyntaxKind.Block:
571-
const grandParent = (parent as Node).parent;
572-
switch (grandParent && grandParent.kind) {
573-
case SyntaxKind.FunctionDeclaration:
574-
case SyntaxKind.FunctionExpression:
575-
// We may want to write inner functions after this.
576-
return false;
577-
default:
578-
return true;
579-
}
580-
case SyntaxKind.CaseClause:
581-
case SyntaxKind.DefaultClause:
582-
case SyntaxKind.SourceFile:
583-
case SyntaxKind.ModuleBlock:
584-
return true;
585-
default:
586-
throw Debug.fail();
568+
case SyntaxKind.ThrowStatement: {
569+
if (parent.kind !== SyntaxKind.Block) {
570+
return true;
587571
}
572+
const grandParent = (parent as Node).parent;
573+
// In a function, we may want to write inner functions after this.
574+
return !(grandParent && grandParent.kind === SyntaxKind.FunctionExpression || grandParent.kind === SyntaxKind.FunctionDeclaration);
575+
}
588576
case SyntaxKind.ContinueStatement:
589577
case SyntaxKind.BreakStatement:
590578
return true;

0 commit comments

Comments
 (0)