@@ -104,7 +104,10 @@ namespace ts.formatting {
104
104
export function formatOnOpeningCurly ( position : number , sourceFile : SourceFile , rulesProvider : RulesProvider , options : FormatCodeSettings ) : TextChange [ ] {
105
105
const openingCurly = findImmediatelyPrecedingTokenOfKind ( position , SyntaxKind . OpenBraceToken , sourceFile ) ;
106
106
const curlyBraceRange = openingCurly && openingCurly . parent ;
107
- return formatOutermostNodeWithinListLevel ( curlyBraceRange , sourceFile , options , rulesProvider , FormattingRequestKind . FormatOnOpeningCurlyBrace ) ;
107
+ const nextToken = curlyBraceRange && findNextToken ( openingCurly , curlyBraceRange ) ;
108
+ return nextToken && nextToken . kind === SyntaxKind . CloseBraceToken ?
109
+ formatOutermostNodeWithinListLevel ( curlyBraceRange , sourceFile , options , rulesProvider , FormattingRequestKind . FormatOnOpeningCurlyBrace ) :
110
+ [ ] ;
108
111
}
109
112
110
113
export function formatOnClosingCurly ( position : number , sourceFile : SourceFile , rulesProvider : RulesProvider , options : FormatCodeSettings ) : TextChange [ ] {
@@ -130,8 +133,8 @@ namespace ts.formatting {
130
133
}
131
134
132
135
/**
133
- * Validating `expectedLastToken ` ensures the token was typed in the context we expect (eg: not a comment).
134
- * @param expectedLastToken The last token constituting the desired parent node.
136
+ * Validating `expectedTokenKind ` ensures the token was typed in the context we expect (eg: not a comment).
137
+ * @param expectedTokenKind The kind of the last token constituting the desired parent node.
135
138
*/
136
139
function findImmediatelyPrecedingTokenOfKind ( end : number , expectedTokenKind : SyntaxKind , sourceFile : SourceFile ) : Node | undefined {
137
140
const precedingToken = findPrecedingToken ( end , sourceFile ) ;
@@ -142,8 +145,8 @@ namespace ts.formatting {
142
145
}
143
146
144
147
/**
145
- * Finds and formats the highest node enclosing `position ` whose end does not exceed the given position
146
- * and is at the same list level as the token at `position `.
148
+ * Finds and formats the highest node enclosing `node ` whose end does not exceed the `node.end`
149
+ * and is at the same list level as the token at `node `.
147
150
*
148
151
* Consider typing the following
149
152
* ```
0 commit comments