diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index adaaed40d79..3773412bace 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -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 ? - (node).namedBindings : node; - - let children = (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)) { diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 57d527d943f..ebcbfbb1394 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -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(node); + case SyntaxKind.ImportClause: + return hasBraceShell((node).namedBindings); + } + return false; + } } } \ No newline at end of file