Merge pull request #30743 from andrewbranch/bug/30675

Make anonymous function formatting apply to anonymous generators too
This commit is contained in:
Andrew Branch 2019-04-23 09:35:35 -07:00 committed by GitHub
commit cd56398a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View File

@ -98,7 +98,7 @@ namespace ts.formatting {
rule("SpaceAfterConditionalClosingParen", SyntaxKind.CloseParenToken, SyntaxKind.OpenBracketToken, [isControlDeclContext], RuleAction.Space),
rule("NoSpaceBetweenFunctionKeywordAndStar", SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken, [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Delete),
rule("SpaceAfterStarInGeneratorDeclaration", SyntaxKind.AsteriskToken, [SyntaxKind.Identifier, SyntaxKind.OpenParenToken], [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Space),
rule("SpaceAfterStarInGeneratorDeclaration", SyntaxKind.AsteriskToken, SyntaxKind.Identifier, [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Space),
rule("SpaceAfterFunctionInFuncDecl", SyntaxKind.FunctionKeyword, anyToken, [isFunctionDeclContext], RuleAction.Space),
// Insert new line after { and before } in multi-line contexts.
@ -241,8 +241,8 @@ namespace ts.formatting {
rule("NoSpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext], RuleAction.Delete),
// Insert space after function keyword for anonymous functions
rule("SpaceAfterAnonymousFunctionKeyword", SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Space),
rule("NoSpaceAfterAnonymousFunctionKeyword", SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Delete),
rule("SpaceAfterAnonymousFunctionKeyword", [SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken], SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Space),
rule("NoSpaceAfterAnonymousFunctionKeyword", [SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken], SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Delete),
// Insert space after keywords in control flow statements
rule("SpaceAfterKeywordInControl", keywords, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterKeywordsInControlFlowStatements"), isControlDeclContext], RuleAction.Space),

View File

@ -5,9 +5,11 @@
/////*3*/var bar = function foo() { };
/////*4*/var foo = { bar() { } };
/////*5*/function tmpl <T> () { }
/////*6*/var f = function*() { };
/////*7*/function* g () { }
format.setOption("InsertSpaceBeforeFunctionParenthesis", true);
format.setOption("insertSpaceBeforeFunctionParenthesis", true);
format.setOption("insertSpaceAfterFunctionKeywordForAnonymousFunctions", false);
format.document();
goTo.marker('1');
@ -20,3 +22,7 @@ goTo.marker('4');
verify.currentLineContentIs('var foo = { bar () { } };');
goTo.marker('5');
verify.currentLineContentIs('function tmpl<T> () { }');
goTo.marker('6');
verify.currentLineContentIs('var f = function*() { };');
goTo.marker('7');
verify.currentLineContentIs('function* g () { }');

View File

@ -7,4 +7,4 @@ format.document();
goTo.marker('1');
verify.currentLineContentIs("function* g() { }");
goTo.marker('2');
verify.currentLineContentIs("var v = function* () { };");
verify.currentLineContentIs("var v = function*() { };");