From 9781b95bdc64c43644a401755d79c7412886cfea Mon Sep 17 00:00:00 2001 From: Mine Starks Date: Thu, 15 Aug 2019 15:30:09 -0700 Subject: [PATCH] Fixes #32923 --- src/services/formatting/smartIndenter.ts | 6 ++- ...ObjectLiteralOpenCurlyNewlineAssignment.ts | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewlineAssignment.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 7a8bfb5f5d509..05862e419b1e4 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -539,10 +539,14 @@ namespace ts.formatting { return true; case SyntaxKind.VariableDeclaration: case SyntaxKind.PropertyAssignment: + case SyntaxKind.BinaryExpression: if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217 return rangeIsOnOneLine(sourceFile, child!); } - return true; + if (parent.kind !== SyntaxKind.BinaryExpression) { + return true; + } + break; case SyntaxKind.DoStatement: case SyntaxKind.WhileStatement: case SyntaxKind.ForInStatement: diff --git a/tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewlineAssignment.ts b/tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewlineAssignment.ts new file mode 100644 index 0000000000000..3693b49075e15 --- /dev/null +++ b/tests/cases/fourslash/formattingObjectLiteralOpenCurlyNewlineAssignment.ts @@ -0,0 +1,47 @@ +/// + +//// +//// var obj = {}; +//// obj = +//// { +//// prop: 3 +//// }; +//// +//// var obj2 = obj || +//// { +//// prop: 0 +//// } +//// + +format.document(); +verify.currentFileContentIs( +` +var obj = {}; +obj = +{ + prop: 3 +}; + +var obj2 = obj || +{ + prop: 0 +} +` +); + +format.setOption("indentMultiLineObjectLiteralBeginningOnBlankLine", true); +format.document(); +verify.currentFileContentIs( +` +var obj = {}; +obj = + { + prop: 3 + }; + +var obj2 = obj || + { + prop: 0 + } +` +); \ No newline at end of file