From 7a73c89c57dbb3b079f7d740a0f2b2893739775b Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 21 Jun 2018 11:20:03 -0700 Subject: [PATCH] Convert getInsertNodeAfterOptionsWorker to switch statement (#25128) --- src/services/textChanges.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index c37969f19c..a5eed1418a 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -490,22 +490,25 @@ namespace ts.textChanges { }; } private getInsertNodeAfterOptionsWorker(node: Node): InsertNodeOptions { - if (isClassDeclaration(node) || isModuleDeclaration(node)) { - return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ModuleDeclaration: + return { prefix: this.newLineCharacter, suffix: this.newLineCharacter }; + + case SyntaxKind.VariableDeclaration: + case SyntaxKind.StringLiteral: + return { prefix: ", " }; + + case SyntaxKind.PropertyAssignment: + return { suffix: "," + this.newLineCharacter }; + + case SyntaxKind.Parameter: + return {}; + + default: + Debug.assert(isStatement(node) || isClassOrTypeElement(node)); // Else we haven't handled this kind of node yet -- add it + return { suffix: this.newLineCharacter }; } - else if (isStatement(node) || isClassOrTypeElement(node)) { - return { suffix: this.newLineCharacter }; - } - else if (isVariableDeclaration(node) || isStringLiteral(node)) { - return { prefix: ", " }; - } - else if (isPropertyAssignment(node)) { - return { suffix: "," + this.newLineCharacter }; - } - else if (isParameter(node)) { - return {}; - } - return Debug.failBadSyntaxKind(node); // We haven't handled this kind of node yet -- add it } public insertName(sourceFile: SourceFile, node: FunctionExpression | ClassExpression | ArrowFunction, name: string): void {