mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
partially move getIndentationToken into new function
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user