Merge pull request #13092 from SaschaNaz/jsxdangling

Format JSX expression and closing token
This commit is contained in:
Mohamed Hegazy
2016-12-21 16:43:35 -08:00
committed by GitHub
4 changed files with 35 additions and 11 deletions

View File

@@ -494,14 +494,26 @@ namespace ts.formatting {
case SyntaxKind.WhileKeyword:
case SyntaxKind.AtToken:
return indentation;
case SyntaxKind.SlashToken:
case SyntaxKind.GreaterThanToken: {
if (container.kind === SyntaxKind.JsxOpeningElement ||
container.kind === SyntaxKind.JsxClosingElement ||
container.kind === SyntaxKind.JsxSelfClosingElement
) {
return indentation;
}
break;
}
case SyntaxKind.OpenBracketToken:
case SyntaxKind.CloseBracketToken:
return (container.kind === SyntaxKind.MappedType) ?
indentation + getEffectiveDelta(delta, container) : 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 + getEffectiveDelta(delta, container) : indentation;
case SyntaxKind.CloseBracketToken: {
if (container.kind !== SyntaxKind.MappedType) {
return indentation;
}
break;
}
}
// 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 + getEffectiveDelta(delta, container) : indentation;
},
getIndentation: () => indentation,
getDelta: child => getEffectiveDelta(delta, child),

View File

@@ -710,11 +710,18 @@ namespace ts.formatting {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.Block:
case SyntaxKind.CatchClause:
case SyntaxKind.ModuleBlock:
case SyntaxKind.SwitchStatement:
return true;
case SyntaxKind.Block: {
const blockParent = context.currentTokenParent.parent;
if (blockParent.kind !== SyntaxKind.ArrowFunction &&
blockParent.kind !== SyntaxKind.FunctionExpression
) {
return true;
}
}
}
return false;
}