Skip to content

Commit 58c732b

Browse files
saschanazvladima
authored andcommitted
format class expression indentation
1 parent 40112c5 commit 58c732b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/services/formatting/rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace ts.formatting {
274274
this.SpaceBeforeOpenBraceInFunction = new Rule(RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines);
275275

276276
// Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc)
277-
this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia]);
277+
this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.ClassKeyword]);
278278
this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new Rule(RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines);
279279

280280
// Place a space before open brace in a control flow construct
@@ -667,6 +667,7 @@ namespace ts.formatting {
667667
static NodeIsTypeScriptDeclWithBlockContext(node: Node): boolean {
668668
switch (node.kind) {
669669
case SyntaxKind.ClassDeclaration:
670+
case SyntaxKind.ClassExpression:
670671
case SyntaxKind.InterfaceDeclaration:
671672
case SyntaxKind.EnumDeclaration:
672673
case SyntaxKind.TypeLiteral:

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ namespace ts.formatting {
406406
function nodeContentIsAlwaysIndented(kind: SyntaxKind): boolean {
407407
switch (kind) {
408408
case SyntaxKind.ClassDeclaration:
409+
case SyntaxKind.ClassExpression:
409410
case SyntaxKind.InterfaceDeclaration:
410411
case SyntaxKind.EnumDeclaration:
411412
case SyntaxKind.TypeAliasDeclaration:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////class Thing extends (
4+
//// class/*classOpenBrace*/
5+
//// {
6+
/////*classIndent*/
7+
//// protected doThing() {/*methodAutoformat*/
8+
/////*methodIndent*/
9+
//// }
10+
//// }
11+
////) {
12+
////}
13+
14+
format.document();
15+
16+
goTo.marker("classOpenBrace");
17+
verify.currentLineContentIs(" class {");
18+
goTo.marker("classIndent");
19+
verify.indentationIs(8);
20+
goTo.marker("methodAutoformat");
21+
verify.currentLineContentIs(" protected doThing() {");
22+
goTo.marker("methodIndent");
23+
verify.indentationIs(12);

0 commit comments

Comments
 (0)