getLineIndentation for others

This commit is contained in:
SaschaNaz
2015-05-24 14:38:17 +09:00
parent e20be95812
commit 50a02237d1

View File

@@ -66,6 +66,10 @@ module ts.formatting {
if (actualIndentation !== Value.Unknown) {
return actualIndentation;
}
actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options);
if (actualIndentation !== Value.Unknown) {
return actualIndentation + options.IndentSize;
}
previous = current;
current = current.parent;
@@ -122,6 +126,10 @@ module ts.formatting {
if (actualIndentation !== Value.Unknown) {
return actualIndentation + indentationDelta;
}
actualIndentation = getLineIndentationWhenExpressionIsInMultiLine(current, sourceFile, options);
if (actualIndentation !== Value.Unknown) {
return actualIndentation + indentationDelta;
}
}
// increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line
@@ -279,14 +287,7 @@ module ts.formatting {
function getActualIndentationForListItem(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
let containingList = getContainingList(node, sourceFile);
if (containingList) {
let lineIndentation = getLineIndentationWhenExpressionIsInMultiLine(node, sourceFile, options);
if (lineIndentation !== Value.Unknown)
return lineIndentation;
return getActualIndentationFromList(containingList);
}
return Value.Unknown;
return containingList ? getActualIndentationFromList(containingList) : Value.Unknown;
function getActualIndentationFromList(list: Node[]): number {
let index = indexOf(list, node);
@@ -295,8 +296,9 @@ module ts.formatting {
}
function getLineIndentationWhenExpressionIsInMultiLine(node: Node, sourceFile: SourceFile, options: EditorOptions): number {
if (node.parent.kind === SyntaxKind.CallExpression ||
node.parent.kind === SyntaxKind.NewExpression) {
if (node.parent && (
node.parent.kind === SyntaxKind.CallExpression ||
node.parent.kind === SyntaxKind.NewExpression)) {
let parentExpression = (<CallExpression | NewExpression>node.parent).expression;
let startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>parentExpression);