fixing autoformat not working with empty JsxText

This commit is contained in:
SaschaNaz
2015-08-22 03:37:48 +09:00
parent b8cbfcb715
commit 2677b3fa26
+15 -2
View File
@@ -360,7 +360,9 @@ namespace ts.formatting {
range: TextRange,
inheritedIndentation: number): number {
if (rangeOverlapsWithStartEnd(range, startPos, endPos)) {
if (rangeOverlapsWithStartEnd(range, startPos, endPos) ||
rangeContainsStartEnd(range, startPos, endPos) /* Not to miss zero-range nodes e.g. JsxText */) {
if (inheritedIndentation !== Constants.Unknown) {
return inheritedIndentation;
}
@@ -387,7 +389,10 @@ namespace ts.formatting {
let indentation = inheritedIndentation;
if (indentation === Constants.Unknown) {
if (isSomeBlock(node.kind)) {
if (isIndentPreventedChildNode(parent.kind, node.kind)) {
indentation = parentDynamicIndentation.getIndentation();
}
else if (isSomeBlock(node.kind)) {
// blocks should be indented in
// - other blocks
// - source file
@@ -1016,6 +1021,14 @@ namespace ts.formatting {
return false;
}
function isIndentPreventedChildNode(parent: SyntaxKind, child: SyntaxKind) {
switch (parent) {
case SyntaxKind.JsxElement: {
return child === SyntaxKind.JsxClosingElement;
}
}
}
function getOpenTokenForList(node: Node, list: Node[]) {
switch (node.kind) {
case SyntaxKind.Constructor: