mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-13 06:20:23 -06:00
Fixed incorrect insertSpaceBeforeFunctionParenthesis behavior on functions with type-arguments
There was an interference between the SpaceBeforeOpenParenInFuncDecl and the NoSpaceAfterCloseAngularBracket rules. So, the NoSpaceAfterCloseAngularBracket eliminated a space which has been added by the SpaceBeforeOpenParenInFuncDecl rule.
This commit is contained in:
parent
e5f8287e5c
commit
2b6ef79ada
@ -379,7 +379,7 @@ namespace ts.formatting {
|
||||
this.NoSpaceBetweenCloseParenAndAngularBracket = new Rule(RuleDescriptor.create1(SyntaxKind.CloseParenToken, SyntaxKind.LessThanToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterOpenAngularBracket = new Rule(RuleDescriptor.create3(SyntaxKind.LessThanToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseAngularBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.GreaterThanToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterCloseAngularBracket = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.FromTokens([SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterCloseAngularBracket = new Rule(RuleDescriptor.create3(SyntaxKind.GreaterThanToken, Shared.TokenRange.FromTokens([SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsTypeArgumentOrParameterOrAssertionContext, Rules.IsNotFunctionDeclContext /*To prevent an interference with the SpaceBeforeOpenParenInFuncDecl rule*/), RuleAction.Delete));
|
||||
|
||||
// Remove spaces in empty interface literals. e.g.: x: {}
|
||||
this.NoSpaceBetweenEmptyInterfaceBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectTypeContext), RuleAction.Delete));
|
||||
@ -718,6 +718,10 @@ namespace ts.formatting {
|
||||
return false;
|
||||
}
|
||||
|
||||
static IsNotFunctionDeclContext(context: FormattingContext): boolean {
|
||||
return !Rules.IsFunctionDeclContext(context);
|
||||
}
|
||||
|
||||
static IsFunctionDeclarationOrFunctionExpressionContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind === SyntaxKind.FunctionDeclaration || context.contextNode.kind === SyntaxKind.FunctionExpression;
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
/////*2*/function boo () { }
|
||||
/////*3*/var bar = function foo() { };
|
||||
/////*4*/var foo = { bar() { } };
|
||||
/////*5*/function tmpl <T> () { }
|
||||
|
||||
format.setOption("InsertSpaceBeforeFunctionParenthesis", true);
|
||||
|
||||
@ -16,4 +17,6 @@ verify.currentLineContentIs('function boo () { }');
|
||||
goTo.marker('3');
|
||||
verify.currentLineContentIs('var bar = function foo () { };');
|
||||
goTo.marker('4');
|
||||
verify.currentLineContentIs('var foo = { bar () { } };');
|
||||
verify.currentLineContentIs('var foo = { bar () { } };');
|
||||
goTo.marker('5');
|
||||
verify.currentLineContentIs('function tmpl<T> () { }');
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
////foo()<number, string, T >();
|
||||
////(a + b)<number, string, T >();
|
||||
////
|
||||
////function bar<T>() {
|
||||
/////*inFunctionDeclaration*/function bar <T> () {
|
||||
/////*inClassExpression*/ return class < T2 > {
|
||||
//// }
|
||||
////}
|
||||
@ -42,6 +42,9 @@ verify.currentLineContentIs(" new <T>(a: T);");
|
||||
goTo.marker("inOptionalMethodSignature");
|
||||
verify.currentLineContentIs(" op?<T, M>(a: T, b: M);");
|
||||
|
||||
goTo.marker("inFunctionDeclaration");
|
||||
verify.currentLineContentIs("function bar<T>() {");
|
||||
|
||||
goTo.marker("inClassExpression");
|
||||
verify.currentLineContentIs(" return class <T2> {");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user