Simplify rules for isControlFlowEndingStatement (#25693)

This commit is contained in:
Andy 2018-07-16 11:17:46 -07:00 committed by GitHub
parent 8ef146e658
commit afdd47c9ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View file

@ -579,17 +579,10 @@ namespace ts.formatting {
function isControlFlowEndingStatement(kind: SyntaxKind, parent: TextRangeWithKind): boolean {
switch (kind) {
case SyntaxKind.ReturnStatement:
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.ThrowStatement:
case SyntaxKind.ContinueStatement:
case SyntaxKind.BreakStatement:
return true;
return parent.kind !== SyntaxKind.Block;
default:
return false;
}

View file

@ -0,0 +1,13 @@
/// <reference path='fourslash.ts'/>
//// function foo() {
//// if (true) {
//// {| "indentation": 8|}
//// return;
//// {| "indentation": 8|}
//// }
//// }
for (const marker of test.markers()) {
verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indentation);
}