Skip to content

Commit 34b303a

Browse files
committed
directly expose nodeWillIndentChild
1 parent 83eb6ac commit 34b303a

2 files changed

Lines changed: 9 additions & 20 deletions

File tree

src/services/formatting/formatting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ namespace ts.formatting {
496496
}
497497

498498
function getEffectiveDelta(delta: number, child: TextRangeWithKind) {
499-
return SmartIndenter.shouldInheritParentIndentation(node, child) ? 0 : delta;
499+
// Delta value should be zero when the node explicitly prevents indentation of the child node
500+
return SmartIndenter.nodeWillIndentChild(node, child, true) ? delta : 0;
500501
}
501502
}
502503

src/services/formatting/smartIndenter.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,8 @@ namespace ts.formatting {
465465
}
466466
return false;
467467
}
468-
469-
/**
470-
* Function returns true when a node with conditional indentation rule will indent certain child node
471-
*/
472-
function nodeWillIndentChild(parent: TextRangeWithKind, child: TextRangeWithKind, indentByDefault: boolean) {
468+
469+
export function nodeWillIndentChild(parent: TextRangeWithKind, child: TextRangeWithKind, indentByDefault: boolean) {
473470
let childKind = child ? child.kind : SyntaxKind.Unknown;
474471
switch (parent.kind) {
475472
case SyntaxKind.DoStatement:
@@ -487,24 +484,15 @@ namespace ts.formatting {
487484
case SyntaxKind.SetAccessor:
488485
return childKind !== SyntaxKind.Block;
489486
}
490-
// No explicit rule for selected nodes, so result will follow the default value argument
487+
// No explicit rule for given nodes so the result will follow the default value argument
491488
return indentByDefault;
492489
}
493490

491+
/*
492+
Function returns true when the parent node should indent the given child by an explicit rule
493+
*/
494494
export function shouldIndentChildNode(parent: TextRangeWithKind, child?: TextRangeWithKind): boolean {
495-
if (nodeContentIsAlwaysIndented(parent.kind)) {
496-
return true;
497-
}
498-
return nodeWillIndentChild(parent, child, false);
499-
}
500-
501-
/**
502-
* Function returns true if existing node content indentation should be suppressed for a specific child
503-
*/
504-
export function shouldInheritParentIndentation(parent: TextRangeWithKind, child: TextRangeWithKind): boolean {
505-
// Consider parents without indentation rules can indent their children
506-
// so that they can apply inherited delta value to them
507-
return !nodeWillIndentChild(parent, child, true);
495+
return nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(parent, child, false);
508496
}
509497
}
510498
}

0 commit comments

Comments
 (0)