From 36a30c42b5d53aa1ee1911515e29aa6645e6b003 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 24 Jun 2015 11:53:53 -0700 Subject: [PATCH] Rename functions and variables, also a small refactoring. --- src/services/formatting/smartIndenter.ts | 44 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index b9636a8ddb8..db748f7f494 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -298,35 +298,49 @@ namespace ts.formatting { function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorOptions): number { // actual indentation should not be used when: // - node is close parenthesis - this is the end of the expression - // - node is property access expression - if (node.kind !== SyntaxKind.CloseParenToken && - node.kind !== SyntaxKind.PropertyAccessExpression && - node.parent && ( + if (node.kind === SyntaxKind.CloseParenToken) { + return Value.Unknown; + } + + if (node.parent && ( node.parent.kind === SyntaxKind.CallExpression || - node.parent.kind === SyntaxKind.NewExpression)) { + node.parent.kind === SyntaxKind.NewExpression) && + (node.parent).expression !== node) { - let parentExpression = (node.parent).expression; - let startingExpression = getStartingExpression(parentExpression); + let fullCallOrNewExpression = (node.parent).expression; + let startingExpression = getStartingExpression(fullCallOrNewExpression); - if (parentExpression === startingExpression) { + if (fullCallOrNewExpression === startingExpression) { return Value.Unknown; } - let parentExpressionEnd = sourceFile.getLineAndCharacterOfPosition(parentExpression.end); + let fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end); let startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end); - if (parentExpressionEnd.line === startingExpressionEnd.line) { + if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) { return Value.Unknown; } - return findColumnForFirstNonWhitespaceCharacterInLine(parentExpressionEnd, sourceFile, options); + return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options); } + return Value.Unknown; - function getStartingExpression(expression: PropertyAccessExpression | CallExpression | ElementAccessExpression) { - while (expression.expression) - expression = expression.expression; - return expression; + function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) { + while (true) { + switch (node.kind) { + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ElementAccessExpression: + + node = node.expression; + break; + default: + return node; + } + } + return node; } }