@@ -56,9 +56,9 @@ namespace ts.formatting {
56
56
// for block indentation, we should look for a line which contains something that's not
57
57
// whitespace.
58
58
const currentToken = getTokenAtPosition ( sourceFile , position ) ;
59
- // for object literal , we want to the indentation work like block
60
- // if { starts in any position (can be in the middle of line)
61
- // the following indentation should treat { as starting of that line (including leading whitespace)
59
+ // For object literals , we want indentation to work just like with blocks.
60
+ // If the `{` starts in any position (even in the middle of a line), then
61
+ // the following indentation should treat `{` as the start of that line (including leading whitespace).
62
62
// ```
63
63
// const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
64
64
// ->
@@ -76,7 +76,8 @@ namespace ts.formatting {
76
76
// y: undefined,
77
77
// }
78
78
// ```
79
- if ( options . indentStyle === IndentStyle . Block || currentToken . kind === SyntaxKind . OpenBraceToken ) {
79
+ const isObjectLiteral = currentToken . kind === SyntaxKind . OpenBraceToken && currentToken . parent . kind === SyntaxKind . ObjectLiteralExpression ;
80
+ if ( options . indentStyle === IndentStyle . Block || isObjectLiteral ) {
80
81
return getBlockIndent ( sourceFile , position , options ) ;
81
82
}
82
83
@@ -91,7 +92,9 @@ namespace ts.formatting {
91
92
const containerList = getListByPosition ( position , precedingToken . parent , sourceFile ) ;
92
93
// use list position if the preceding token is before any list items
93
94
if ( containerList && ! rangeContainsRange ( containerList , precedingToken ) ) {
94
- return getActualIndentationForListStartLine ( containerList , sourceFile , options ) + options . indentSize ! ; // TODO: GH#18217
95
+ const useTheSameBaseIndentation = [ SyntaxKind . FunctionExpression , SyntaxKind . ArrowFunction ] . indexOf ( currentToken . parent . kind ) !== - 1 ;
96
+ const indentSize = useTheSameBaseIndentation ? 0 : options . indentSize ! ;
97
+ return getActualIndentationForListStartLine ( containerList , sourceFile , options ) + indentSize ; // TODO: GH#18217
95
98
}
96
99
97
100
return getSmartIndent ( sourceFile , position , precedingToken , lineAtPosition , assumeNewLineBeforeCloseBrace , options ) ;
0 commit comments