Skip to content

Commit cd56398

Browse files
authored
Merge pull request #30743 from andrewbranch/bug/30675
Make anonymous function formatting apply to anonymous generators too
2 parents c74d25c + 45ed018 commit cd56398

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/services/formatting/rules.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace ts.formatting {
9898
rule("SpaceAfterConditionalClosingParen", SyntaxKind.CloseParenToken, SyntaxKind.OpenBracketToken, [isControlDeclContext], RuleAction.Space),
9999

100100
rule("NoSpaceBetweenFunctionKeywordAndStar", SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken, [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Delete),
101-
rule("SpaceAfterStarInGeneratorDeclaration", SyntaxKind.AsteriskToken, [SyntaxKind.Identifier, SyntaxKind.OpenParenToken], [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Space),
101+
rule("SpaceAfterStarInGeneratorDeclaration", SyntaxKind.AsteriskToken, SyntaxKind.Identifier, [isFunctionDeclarationOrFunctionExpressionContext], RuleAction.Space),
102102

103103
rule("SpaceAfterFunctionInFuncDecl", SyntaxKind.FunctionKeyword, anyToken, [isFunctionDeclContext], RuleAction.Space),
104104
// Insert new line after { and before } in multi-line contexts.
@@ -241,8 +241,8 @@ namespace ts.formatting {
241241
rule("NoSpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext], RuleAction.Delete),
242242

243243
// Insert space after function keyword for anonymous functions
244-
rule("SpaceAfterAnonymousFunctionKeyword", SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Space),
245-
rule("NoSpaceAfterAnonymousFunctionKeyword", SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Delete),
244+
rule("SpaceAfterAnonymousFunctionKeyword", [SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken], SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Space),
245+
rule("NoSpaceAfterAnonymousFunctionKeyword", [SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken], SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Delete),
246246

247247
// Insert space after keywords in control flow statements
248248
rule("SpaceAfterKeywordInControl", keywords, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterKeywordsInControlFlowStatements"), isControlDeclContext], RuleAction.Space),

tests/cases/fourslash/formattingSpaceBeforeFunctionParen.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
/////*3*/var bar = function foo() { };
66
/////*4*/var foo = { bar() { } };
77
/////*5*/function tmpl <T> () { }
8+
/////*6*/var f = function*() { };
9+
/////*7*/function* g () { }
810

9-
format.setOption("InsertSpaceBeforeFunctionParenthesis", true);
10-
11+
format.setOption("insertSpaceBeforeFunctionParenthesis", true);
12+
format.setOption("insertSpaceAfterFunctionKeywordForAnonymousFunctions", false);
1113
format.document();
1214

1315
goTo.marker('1');
@@ -20,3 +22,7 @@ goTo.marker('4');
2022
verify.currentLineContentIs('var foo = { bar () { } };');
2123
goTo.marker('5');
2224
verify.currentLineContentIs('function tmpl<T> () { }');
25+
goTo.marker('6');
26+
verify.currentLineContentIs('var f = function*() { };');
27+
goTo.marker('7');
28+
verify.currentLineContentIs('function* g () { }');

tests/cases/fourslash/generatorDeclarationFormatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ format.document();
77
goTo.marker('1');
88
verify.currentLineContentIs("function* g() { }");
99
goTo.marker('2');
10-
verify.currentLineContentIs("var v = function* () { };");
10+
verify.currentLineContentIs("var v = function*() { };");

0 commit comments

Comments
 (0)