From e3a720f863fc353b6ec8c77aee5470cd1011a3d8 Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 19 Sep 2017 16:25:06 -0700 Subject: [PATCH] explain changes and remove spurious assignment --- src/services/formatting/smartIndenter.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index fac61be45d5..7701cff182c 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -202,7 +202,14 @@ namespace ts.formatting { indentationDelta += options.indentSize; } - // Update `current` and `parent`. + // In our AST, a call argument's `parent` is the call-expression, not the argument list. + // We would like to increase indentation based on the relationship between an argument and its argument-list, + // so we spoof the starting position of the (parent) call-expression to match the (non-parent) argument-list. + // But, the spoofed start-value could then cause a problem when comparing the start position of the call-expression + // to *its* parent (in the case of an iife, an expression statement), adding an extra level of indentation. + // + // Instead, when at an argument, we unspoof the starting position of the enclosing call expression + // *after* applying indentation for the argument. const useTrueStart = isArgumentAndStartLineOverlapsExpressionBeingCalled(parent, current, currentStart.line, sourceFile); @@ -210,7 +217,6 @@ namespace ts.formatting { current = parent; parent = current.parent; currentStart = useTrueStart ? sourceFile.getLineAndCharacterOfPosition(current.getStart()) : containingListOrParentStart; - containingListOrParentStart = undefined; } return indentationDelta + getBaseIndentation(options);