Skip to content

Commit ba7c1a1

Browse files
committed
do not insert space after function expressions
1 parent a4ec7d6 commit ba7c1a1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/services/formatting/rules.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,18 @@ namespace ts.formatting {
705705
case SyntaxKind.ClassDeclaration:
706706
case SyntaxKind.ModuleDeclaration:
707707
case SyntaxKind.EnumDeclaration:
708-
case SyntaxKind.Block:
709708
case SyntaxKind.CatchClause:
710709
case SyntaxKind.ModuleBlock:
711710
case SyntaxKind.SwitchStatement:
712711
return true;
712+
case SyntaxKind.Block: {
713+
const blockParent = context.currentTokenParent.parent;
714+
if (blockParent.kind !== SyntaxKind.ArrowFunction &&
715+
blockParent.kind !== SyntaxKind.FunctionExpression)
716+
{
717+
return true;
718+
}
719+
}
713720
}
714721
return false;
715722
}

tests/cases/fourslash/formatVariableDeclarationList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ verify.currentLineContentIs(" x = 'Foo';");
3737
goTo.marker("11");
3838
verify.currentLineContentIs(" return fun;");
3939
goTo.marker("12");
40-
verify.currentLineContentIs(" } (fun1));");
40+
verify.currentLineContentIs(" }(fun1));");

tests/cases/fourslash/formattingJsxElements.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
////<span>) </span>;/*closingParenInJsxElement2*/
7373
////<Router routes = { 3 } / >;/*jsxExpressionSpaces*/
7474
////<Router routes={ (3) } />;/*jsxExpressionSpaces2*/
75+
////<Router routes={() => {}}/*jsxExpressionSpaces3*/
76+
/////>;/*jsxDanglingSelfClosingToken*/
7577

7678
format.document();
7779
goTo.marker("autoformat");
@@ -120,8 +122,7 @@ goTo.marker("expressionIndent");
120122
verify.indentationIs(12);
121123

122124
goTo.marker("danglingBracketAutoformat")
123-
// TODO: verify.currentLineContentIs(" >");
124-
verify.currentLineContentIs(" >");
125+
verify.currentLineContentIs(" >");
125126
goTo.marker("closingTagAutoformat");
126127
verify.currentLineContentIs(" </div>");
127128

@@ -145,4 +146,8 @@ verify.currentLineContentIs("<span>) </span>;");
145146
goTo.marker("jsxExpressionSpaces");
146147
verify.currentLineContentIs("<Router routes={3} />;");
147148
goTo.marker("jsxExpressionSpaces2");
148-
verify.currentLineContentIs("<Router routes={(3)} />;");
149+
verify.currentLineContentIs("<Router routes={(3)} />;");
150+
goTo.marker("jsxExpressionSpaces3");
151+
verify.currentLineContentIs("<Router routes={() => { }}");
152+
goTo.marker("jsxDanglingSelfClosingToken");
153+
verify.currentLineContentIs("/>;");

0 commit comments

Comments
 (0)