From 0701ed5d4b7680827fe4e5a40115d8abcc49ce1d Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 1 Mar 2018 13:12:53 -0800 Subject: [PATCH] isControlFlowEndingStatement: don't try to enumerate all possible parent kinds (#22131) --- src/services/formatting/smartIndenter.ts | 26 +++++++----------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index f124c444f6d..b8574ba89c1 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -565,26 +565,14 @@ namespace ts.formatting { function isControlFlowEndingStatement(kind: SyntaxKind, parent: TextRangeWithKind): boolean { switch (kind) { case SyntaxKind.ReturnStatement: - case SyntaxKind.ThrowStatement: - switch (parent.kind) { - case SyntaxKind.Block: - const grandParent = (parent as Node).parent; - switch (grandParent && grandParent.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - // We may want to write inner functions after this. - return false; - default: - return true; - } - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleBlock: - return true; - default: - throw Debug.fail(); + case SyntaxKind.ThrowStatement: { + if (parent.kind !== SyntaxKind.Block) { + return true; } + const grandParent = (parent as Node).parent; + // In a function, we may want to write inner functions after this. + return !(grandParent && grandParent.kind === SyntaxKind.FunctionExpression || grandParent.kind === SyntaxKind.FunctionDeclaration); + } case SyntaxKind.ContinueStatement: case SyntaxKind.BreakStatement: return true;