Skip to content

Commit 36a30c4

Browse files
committed
Rename functions and variables, also a small refactoring.
1 parent f5f4af2 commit 36a30c4

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,35 +298,49 @@ namespace ts.formatting {
298298
function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
299299
// actual indentation should not be used when:
300300
// - node is close parenthesis - this is the end of the expression
301-
// - node is property access expression
302-
if (node.kind !== SyntaxKind.CloseParenToken &&
303-
node.kind !== SyntaxKind.PropertyAccessExpression &&
304-
node.parent && (
301+
if (node.kind === SyntaxKind.CloseParenToken) {
302+
return Value.Unknown;
303+
}
304+
305+
if (node.parent && (
305306
node.parent.kind === SyntaxKind.CallExpression ||
306-
node.parent.kind === SyntaxKind.NewExpression)) {
307+
node.parent.kind === SyntaxKind.NewExpression) &&
308+
(<CallExpression>node.parent).expression !== node) {
307309

308-
let parentExpression = (<CallExpression | NewExpression>node.parent).expression;
309-
let startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>parentExpression);
310+
let fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
311+
let startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>fullCallOrNewExpression);
310312

311-
if (parentExpression === startingExpression) {
313+
if (fullCallOrNewExpression === startingExpression) {
312314
return Value.Unknown;
313315
}
314316

315-
let parentExpressionEnd = sourceFile.getLineAndCharacterOfPosition(parentExpression.end);
317+
let fullCallOrNewExpressionEnd = sourceFile.getLineAndCharacterOfPosition(fullCallOrNewExpression.end);
316318
let startingExpressionEnd = sourceFile.getLineAndCharacterOfPosition(startingExpression.end);
317319

318-
if (parentExpressionEnd.line === startingExpressionEnd.line) {
320+
if (fullCallOrNewExpressionEnd.line === startingExpressionEnd.line) {
319321
return Value.Unknown;
320322
}
321323

322-
return findColumnForFirstNonWhitespaceCharacterInLine(parentExpressionEnd, sourceFile, options);
324+
return findColumnForFirstNonWhitespaceCharacterInLine(fullCallOrNewExpressionEnd, sourceFile, options);
323325
}
326+
324327
return Value.Unknown;
325328

326-
function getStartingExpression(expression: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
327-
while (expression.expression)
328-
expression = <PropertyAccessExpression | CallExpression | ElementAccessExpression>expression.expression;
329-
return expression;
329+
function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
330+
while (true) {
331+
switch (node.kind) {
332+
case SyntaxKind.CallExpression:
333+
case SyntaxKind.NewExpression:
334+
case SyntaxKind.PropertyAccessExpression:
335+
case SyntaxKind.ElementAccessExpression:
336+
337+
node = <PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression>node.expression;
338+
break;
339+
default:
340+
return node;
341+
}
342+
}
343+
return node;
330344
}
331345
}
332346

0 commit comments

Comments
 (0)