Skip to content

Commit 5bd477e

Browse files
Merge pull request microsoft#20924 from uniqueiniquity/jsxSpreadAttributeFormatting
Jsx spread attribute formatting
2 parents f6dc0ad + 624f68a commit 5bd477e

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/services/formatting/rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ namespace ts.formatting {
619619
}
620620

621621
function isJsxExpressionContext(context: FormattingContext): boolean {
622-
return context.contextNode.kind === SyntaxKind.JsxExpression;
622+
return context.contextNode.kind === SyntaxKind.JsxExpression || context.contextNode.kind === SyntaxKind.JsxSpreadAttribute;
623623
}
624624

625625
function isNextTokenParentJsxAttribute(context: FormattingContext): boolean {
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
///<reference path="fourslash.ts"/>
22

33
//@Filename: file.tsx
4-
/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces*/<Madoka homu={ true } saya={ (true) } />;
4+
/////*1*/<Madoka homu={ true } saya={ (true) } />;
5+
////
6+
////<PrimaryButton
7+
//// /*2*/{ ...this._getButtonProps() }
8+
/////>
59

6-
runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces", "<Madoka homu={ true } saya={ (true) } />;", "<Madoka homu={true} saya={(true)} />;");
10+
runTest("1", "<Madoka homu={ true } saya={ (true) } />;", "<Madoka homu={true} saya={(true)} />;");
11+
runTest("2", " { ...this._getButtonProps() }", " {...this._getButtonProps()}");
712

813

9-
function runTest(propertyName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) {
14+
function runTest(markerName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) {
15+
const propertyName = "InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces";
16+
1017
// Go to the correct file
11-
goTo.marker(propertyName);
18+
goTo.marker(markerName);
1219

1320
// Set the option to false first
1421
format.setOption(propertyName, false);
@@ -17,7 +24,7 @@ function runTest(propertyName: string, expectedStringWhenTrue: string, expectedS
1724
format.document();
1825

1926
// Verify
20-
goTo.marker(propertyName);
27+
goTo.marker(markerName);
2128
verify.currentLineContentIs(expectedStringWhenFalse);
2229

2330
// Set the option to true
@@ -27,6 +34,6 @@ function runTest(propertyName: string, expectedStringWhenTrue: string, expectedS
2734
format.document();
2835

2936
// Verify
30-
goTo.marker(propertyName);
37+
goTo.marker(markerName);
3138
verify.currentLineContentIs(expectedStringWhenTrue);
3239
}

0 commit comments

Comments
 (0)