Skip to content

Commit 8d1d0d8

Browse files
committed
format class expression indentation
1 parent 9e0949b commit 8d1d0d8

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/services/formatting/rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace ts.formatting {
272272
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);
273273

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

278278
// Place a space before open brace in a control flow construct
@@ -663,6 +663,7 @@ namespace ts.formatting {
663663
static NodeIsTypeScriptDeclWithBlockContext(node: Node): boolean {
664664
switch (node.kind) {
665665
case SyntaxKind.ClassDeclaration:
666+
case SyntaxKind.ClassExpression:
666667
case SyntaxKind.InterfaceDeclaration:
667668
case SyntaxKind.EnumDeclaration:
668669
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)