Skip to content

Commit 4e88e3c

Browse files
author
Armando Aguirre
authored
Merge pull request #24335 from armanio123/FixObjectLiteralExpression
Fix object literal expression
2 parents 3321537 + 0b18bdf commit 4e88e3c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,10 @@ namespace ts.formatting {
482482
return findFirstNonWhitespaceCharacterAndColumn(startPos, endPos, sourceFile, options).column;
483483
}
484484

485-
function nodeContentIsAlwaysIndented(kind: SyntaxKind): boolean {
486-
switch (kind) {
485+
export function nodeWillIndentChild(settings: FormatCodeSettings | undefined, parent: TextRangeWithKind, child: TextRangeWithKind | undefined, sourceFile: SourceFileLike | undefined, indentByDefault: boolean): boolean {
486+
const childKind = child ? child.kind : SyntaxKind.Unknown;
487+
488+
switch (parent.kind) {
487489
case SyntaxKind.ExpressionStatement:
488490
case SyntaxKind.ClassDeclaration:
489491
case SyntaxKind.ClassExpression:
@@ -505,7 +507,6 @@ namespace ts.formatting {
505507
case SyntaxKind.CallExpression:
506508
case SyntaxKind.NewExpression:
507509
case SyntaxKind.VariableStatement:
508-
case SyntaxKind.VariableDeclaration:
509510
case SyntaxKind.ExportAssignment:
510511
case SyntaxKind.ReturnStatement:
511512
case SyntaxKind.ConditionalExpression:
@@ -528,24 +529,14 @@ namespace ts.formatting {
528529
case SyntaxKind.NamedImports:
529530
case SyntaxKind.ExportSpecifier:
530531
case SyntaxKind.ImportSpecifier:
531-
case SyntaxKind.PropertyAssignment:
532532
case SyntaxKind.PropertyDeclaration:
533533
return true;
534-
}
535-
return false;
536-
}
537-
538-
export function nodeWillIndentChild(settings: FormatCodeSettings | undefined, parent: TextRangeWithKind, child: TextRangeWithKind | undefined, sourceFile: SourceFileLike | undefined, indentByDefault: boolean): boolean {
539-
const childKind = child ? child.kind : SyntaxKind.Unknown;
540-
541-
switch (parent.kind) {
542534
case SyntaxKind.VariableDeclaration:
543535
case SyntaxKind.PropertyAssignment:
544-
case SyntaxKind.ObjectLiteralExpression:
545536
if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) {
546537
return rangeIsOnOneLine(sourceFile, child);
547538
}
548-
break;
539+
return true;
549540
case SyntaxKind.DoStatement:
550541
case SyntaxKind.WhileStatement:
551542
case SyntaxKind.ForInStatement:
@@ -604,7 +595,7 @@ namespace ts.formatting {
604595
* @param isNextChild If true, we are judging indent of a hypothetical child *after* this one, not the current child.
605596
*/
606597
export function shouldIndentChildNode(settings: FormatCodeSettings | undefined, parent: TextRangeWithKind, child?: Node, sourceFile?: SourceFileLike, isNextChild = false): boolean {
607-
return (nodeContentIsAlwaysIndented(parent.kind) || nodeWillIndentChild(settings, parent, child, sourceFile, /*indentByDefault*/ false))
598+
return nodeWillIndentChild(settings, parent, child, sourceFile, /*indentByDefault*/ false)
608599
&& !(isNextChild && child && isControlFlowEndingStatement(child.kind, parent));
609600
}
610601

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// var a =
4+
//// {/*1*/}
5+
////
6+
//// var b = {
7+
//// outer:
8+
//// {/*2*/}
9+
//// }
10+
11+
function verifyIndentationAfterNewLine(marker: string, indentation: number): void {
12+
goTo.marker(marker);
13+
edit.insert("\n");
14+
verify.indentationIs(indentation);
15+
}
16+
17+
verifyIndentationAfterNewLine("1", 0);
18+
verifyIndentationAfterNewLine("2", 4);

0 commit comments

Comments
 (0)