Skip to content

Commit ec7a667

Browse files
author
Benjamin Lichtman
committed
Update rules to match JSXElement
1 parent b15ecfc commit ec7a667

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/services/formatting/rules.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ namespace ts.formatting {
231231
rule("SpaceAfterConstructor", SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], RuleAction.Space),
232232
rule("NoSpaceAfterConstructor", SyntaxKind.ConstructorKeyword, SyntaxKind.OpenParenToken, [isOptionDisabledOrUndefined("insertSpaceAfterConstructor"), isNonJsxSameLineTokenContext], RuleAction.Delete),
233233

234-
rule("SpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionEnabled("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementContext, isNextTokenNotCloseBracket], RuleAction.Space),
235-
rule("NoSpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementContext], RuleAction.Delete),
234+
rule("SpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionEnabled("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNextTokenNotCloseBracket], RuleAction.Space),
235+
rule("NoSpaceAfterComma", SyntaxKind.CommaToken, anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterCommaDelimiter"), isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext], RuleAction.Delete),
236236

237237
// Insert space after function keyword for anonymous functions
238238
rule("SpaceAfterAnonymousFunctionKeyword", SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken, [isOptionEnabled("insertSpaceAfterFunctionKeywordForAnonymousFunctions"), isFunctionDeclContext], RuleAction.Space),
@@ -319,7 +319,7 @@ namespace ts.formatting {
319319
"SpaceBetweenStatements",
320320
[SyntaxKind.CloseParenToken, SyntaxKind.DoKeyword, SyntaxKind.ElseKeyword, SyntaxKind.CaseKeyword],
321321
anyToken,
322-
[isNonJsxSameLineTokenContext, isNonJsxElementContext, isNotForContext],
322+
[isNonJsxSameLineTokenContext, isNonJsxElementOrFragmentContext, isNotForContext],
323323
RuleAction.Space),
324324
// This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
325325
rule("SpaceAfterTryFinally", [SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
@@ -614,8 +614,8 @@ namespace ts.formatting {
614614
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
615615
}
616616

617-
function isNonJsxElementContext(context: FormattingContext): boolean {
618-
return context.contextNode.kind !== SyntaxKind.JsxElement;
617+
function isNonJsxElementOrFragmentContext(context: FormattingContext): boolean {
618+
return context.contextNode.kind !== SyntaxKind.JsxElement && context.contextNode.kind !== SyntaxKind.JsxFragment;
619619
}
620620

621621
function isJsxExpressionContext(context: FormattingContext): boolean {

src/services/formatting/smartIndenter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ namespace ts.formatting {
508508
case SyntaxKind.ArrayBindingPattern:
509509
case SyntaxKind.ObjectBindingPattern:
510510
case SyntaxKind.JsxOpeningElement:
511+
case SyntaxKind.JsxOpeningFragment:
511512
case SyntaxKind.JsxSelfClosingElement:
512513
case SyntaxKind.JsxExpression:
513514
case SyntaxKind.MethodSignature:
@@ -554,6 +555,8 @@ namespace ts.formatting {
554555
(!!(<ImportClause>child).namedBindings && (<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports);
555556
case SyntaxKind.JsxElement:
556557
return childKind !== SyntaxKind.JsxClosingElement;
558+
case SyntaxKind.JsxFragment:
559+
return childKind !== SyntaxKind.JsxClosingFragment;
557560
}
558561
// No explicit rule for given nodes so the result will follow the default value argument
559562
return indentByDefault;

0 commit comments

Comments
 (0)