Skip to content

Commit ad02f47

Browse files
authored
Merge pull request microsoft#33148 from minestarks/formatting-object-literals
Fixes microsoft#32923
2 parents 029f7a3 + 9781b95 commit ad02f47

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/services/formatting/smartIndenter.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ namespace ts.formatting {
539539
return true;
540540
case SyntaxKind.VariableDeclaration:
541541
case SyntaxKind.PropertyAssignment:
542+
case SyntaxKind.BinaryExpression:
542543
if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217
543544
return rangeIsOnOneLine(sourceFile, child!);
544545
}
545-
return true;
546+
if (parent.kind !== SyntaxKind.BinaryExpression) {
547+
return true;
548+
}
549+
break;
546550
case SyntaxKind.DoStatement:
547551
case SyntaxKind.WhileStatement:
548552
case SyntaxKind.ForInStatement:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////
4+
//// var obj = {};
5+
//// obj =
6+
//// {
7+
//// prop: 3
8+
//// };
9+
////
10+
//// var obj2 = obj ||
11+
//// {
12+
//// prop: 0
13+
//// }
14+
////
15+
16+
format.document();
17+
verify.currentFileContentIs(
18+
`
19+
var obj = {};
20+
obj =
21+
{
22+
prop: 3
23+
};
24+
25+
var obj2 = obj ||
26+
{
27+
prop: 0
28+
}
29+
`
30+
);
31+
32+
format.setOption("indentMultiLineObjectLiteralBeginningOnBlankLine", true);
33+
format.document();
34+
verify.currentFileContentIs(
35+
`
36+
var obj = {};
37+
obj =
38+
{
39+
prop: 3
40+
};
41+
42+
var obj2 = obj ||
43+
{
44+
prop: 0
45+
}
46+
`
47+
);

0 commit comments

Comments
 (0)