mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
disable indentation when in brace shell
This pattern can also be used to format JSX end tag.
This commit is contained in:
1 parent
66924a3718
commit
f0ed672eb1
2 files changed
+23
-14
No files matched your search
@@ -403,19 +403,8 @@ namespace ts.formatting {
|
||||
indentation = parentDynamicIndentation.getIndentation();
|
||||
}
|
||||
}
|
||||
else if (node.kind === SyntaxKind.NamedExports || node.kind === SyntaxKind.ImportClause) {
|
||||
let blockParent = node.kind === SyntaxKind.ImportClause ?
|
||||
(<ImportClause>node).namedBindings : node;
|
||||
|
||||
let children = (<NamedExports | ImportClause>blockParent).getChildren(sourceFile);
|
||||
// Detect named export/import pseudo-block
|
||||
if (children[0] && children[0].kind === SyntaxKind.OpenBraceToken &&
|
||||
children[2] && children[2].kind === SyntaxKind.CloseBraceToken) {
|
||||
indentation = parentDynamicIndentation.getIndentation();
|
||||
}
|
||||
else {
|
||||
indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta();
|
||||
}
|
||||
else if (SmartIndenter.isIndentationPrevented(node)) {
|
||||
indentation = parentDynamicIndentation.getIndentation();
|
||||
}
|
||||
else {
|
||||
if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) {
|
||||
|
||||
@@ -133,7 +133,9 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
// increase indentation if parent node wants its content to be indented and parent and child nodes don't start on the same line
|
||||
if (shouldIndentChildNode(parent.kind, current.kind) && !parentAndChildShareLine) {
|
||||
if (shouldIndentChildNode(parent.kind, current.kind) &&
|
||||
!isIndentationPrevented(current) && !parentAndChildShareLine) {
|
||||
|
||||
indentationDelta += options.IndentSize;
|
||||
}
|
||||
|
||||
@@ -475,5 +477,23 @@ namespace ts.formatting {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function hasBraceShell(node: Node) {
|
||||
let children = node.getChildren();
|
||||
let last = children.length - 1;
|
||||
// Check if node looks like a block
|
||||
return children[0] && children[0].kind === SyntaxKind.OpenBraceToken &&
|
||||
children[last] && children[last].kind === SyntaxKind.CloseBraceToken;
|
||||
}
|
||||
|
||||
export function isIndentationPrevented(node: TextRangeWithKind) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.NamedExports:
|
||||
return hasBraceShell(<NamedExports>node);
|
||||
case SyntaxKind.ImportClause:
|
||||
return hasBraceShell((<ImportClause>node).namedBindings);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user