Merge pull request #19317 from igelbox/fix-insert-space-after-function-generic

Fixed incorrect insertSpaceBeforeFunctionParenthesis behavior on funtions with type-arguments
This commit is contained in:
Mohamed Hegazy 2018-04-03 16:11:30 -07:00 committed by GitHub
commit db74229a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -198,7 +198,7 @@ namespace ts.formatting {
rule("NoSpaceAfterCloseAngularBracket",
SyntaxKind.GreaterThanToken,
[SyntaxKind.OpenParenToken, SyntaxKind.OpenBracketToken, SyntaxKind.GreaterThanToken, SyntaxKind.CommaToken],
[isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext],
[isNonJsxSameLineTokenContext, isTypeArgumentOrParameterOrAssertionContext, isNotFunctionDeclContext /*To prevent an interference with the SpaceBeforeOpenParenInFuncDecl rule*/],
RuleAction.Delete),
// decorators
@ -542,6 +542,10 @@ namespace ts.formatting {
return false;
}
function isNotFunctionDeclContext(context: FormattingContext): boolean {
return !isFunctionDeclContext(context);
}
function isFunctionDeclarationOrFunctionExpressionContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.FunctionDeclaration || context.contextNode.kind === SyntaxKind.FunctionExpression;
}

View File

@ -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> () { }');

View File

@ -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> {");