no space after new on constructor signatures

This commit is contained in:
Kagami Sascha Rosylight 2017-05-01 23:11:59 +09:00
parent 05b3170f33
commit 61f494ec5d
2 changed files with 17 additions and 1 deletions

View file

@ -84,6 +84,7 @@ namespace ts.formatting {
public NoSpaceBeforeComma: Rule;
public SpaceAfterCertainKeywords: Rule;
public NoSpaceAfterNewKeywordOnConstructorSignature: Rule;
public SpaceAfterLetConstInVariableDeclaration: Rule;
public NoSpaceBeforeOpenParenInFuncCall: Rule;
public SpaceAfterFunctionInFuncDecl: Rule;
@ -334,6 +335,7 @@ namespace ts.formatting {
this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
this.NoSpaceAfterNewKeywordOnConstructorSignature = new Rule(RuleDescriptor.create1(SyntaxKind.NewKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsConstructorSignatureContext), RuleAction.Delete));
this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space));
this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete));
this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
@ -530,7 +532,8 @@ namespace ts.formatting {
this.SpaceBeforeAt,
this.NoSpaceAfterAt,
this.SpaceAfterDecorator,
this.NoSpaceBeforeNonNullAssertionOperator
this.NoSpaceBeforeNonNullAssertionOperator,
this.NoSpaceAfterNewKeywordOnConstructorSignature
];
// These rules are applied after high priority rules.
@ -881,6 +884,10 @@ namespace ts.formatting {
return context.contextNode.kind === SyntaxKind.TypeLiteral; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
}
static IsConstructorSignatureContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.ConstructSignature;
}
static IsTypeArgumentOrParameterOrAssertion(token: TextRangeWithKind, parent: Node): boolean {
if (token.kind !== SyntaxKind.LessThanToken && token.kind !== SyntaxKind.GreaterThanToken) {
return false;

View file

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
/////*1*/interface Gourai { new () {} }
/////*2*/type Stylet = { new () {} }
format.document();
goTo.marker("1");
verify.currentLineContentIs("interface Gourai { new() {} }");
goTo.marker("2");
verify.currentLineContentIs("type Stylet = { new() {} }");