diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index c508d8696ad..0b1d08e8b05 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -389,7 +389,7 @@ namespace ts.formatting { let indentation = inheritedIndentation; if (indentation === Constants.Unknown) { - if (isIndentPreventedChildNode(parent.kind, node.kind)) { + if (isIndentPreventedCoreComponent(node.kind)) { indentation = parentDynamicIndentation.getIndentation(); } else if (isSomeBlock(node.kind)) { @@ -479,21 +479,12 @@ namespace ts.formatting { return indentation; } } - switch (kind) { - // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent - case SyntaxKind.OpenBraceToken: - case SyntaxKind.CloseBraceToken: - case SyntaxKind.OpenBracketToken: - case SyntaxKind.CloseBracketToken: - case SyntaxKind.OpenParenToken: - case SyntaxKind.CloseParenToken: - case SyntaxKind.ElseKeyword: - case SyntaxKind.WhileKeyword: - case SyntaxKind.AtToken: - return indentation; - default: - // if token line equals to the line of containing node (this is a first token in the node) - use node indentation - return nodeStartLine !== line ? indentation + delta : indentation; + if (isIndentPreventedCoreComponent(kind)) { + return indentation; + } + else { + // if token line equals to the line of containing node (this is a first token in the node) - use node indentation + return nodeStartLine !== line ? indentation + delta : indentation; } }, getIndentation: () => indentation, @@ -1021,11 +1012,20 @@ namespace ts.formatting { return false; } - function isIndentPreventedChildNode(parent: SyntaxKind, child: SyntaxKind) { - switch (parent) { - case SyntaxKind.JsxElement: { - return child === SyntaxKind.JsxClosingElement; - } + function isIndentPreventedCoreComponent(child: SyntaxKind) { + switch (child) { + // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent + case SyntaxKind.OpenBraceToken: + case SyntaxKind.CloseBraceToken: + case SyntaxKind.OpenBracketToken: + case SyntaxKind.CloseBracketToken: + case SyntaxKind.OpenParenToken: + case SyntaxKind.CloseParenToken: + case SyntaxKind.ElseKeyword: + case SyntaxKind.WhileKeyword: + case SyntaxKind.AtToken: + case SyntaxKind.JsxClosingElement: + return true; } }