mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
format class expression indentation
This commit is contained in:
parent
40112c5137
commit
58c732b47d
@ -274,7 +274,7 @@ namespace ts.formatting {
|
||||
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);
|
||||
|
||||
// Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc)
|
||||
this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia]);
|
||||
this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia, SyntaxKind.ClassKeyword]);
|
||||
this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new Rule(RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines);
|
||||
|
||||
// Place a space before open brace in a control flow construct
|
||||
@ -667,6 +667,7 @@ namespace ts.formatting {
|
||||
static NodeIsTypeScriptDeclWithBlockContext(node: Node): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.TypeLiteral:
|
||||
|
||||
@ -406,6 +406,7 @@ namespace ts.formatting {
|
||||
function nodeContentIsAlwaysIndented(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
|
||||
23
tests/cases/fourslash/formatClassExpression.ts
Normal file
23
tests/cases/fourslash/formatClassExpression.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////class Thing extends (
|
||||
//// class/*classOpenBrace*/
|
||||
//// {
|
||||
/////*classIndent*/
|
||||
//// protected doThing() {/*methodAutoformat*/
|
||||
/////*methodIndent*/
|
||||
//// }
|
||||
//// }
|
||||
////) {
|
||||
////}
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("classOpenBrace");
|
||||
verify.currentLineContentIs(" class {");
|
||||
goTo.marker("classIndent");
|
||||
verify.indentationIs(8);
|
||||
goTo.marker("methodAutoformat");
|
||||
verify.currentLineContentIs(" protected doThing() {");
|
||||
goTo.marker("methodIndent");
|
||||
verify.indentationIs(12);
|
||||
Loading…
x
Reference in New Issue
Block a user