From 3f8203449851ed64673ff432ee7321e85a51251b Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Thu, 28 Dec 2017 12:42:06 -0800 Subject: [PATCH 1/3] Ensure spread attribute formatting options match jsxexpression --- src/services/formatting/rules.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 91c133ca352..8303770d00d 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -619,7 +619,7 @@ namespace ts.formatting { } function isJsxExpressionContext(context: FormattingContext): boolean { - return context.contextNode.kind === SyntaxKind.JsxExpression; + return context.contextNode.kind === SyntaxKind.JsxExpression || context.contextNode.kind === SyntaxKind.JsxSpreadAttribute; } function isNextTokenParentJsxAttribute(context: FormattingContext): boolean { From 05a6f343f71ae234ccfd72f83050abaf2ee1f0b7 Mon Sep 17 00:00:00 2001 From: Benjamin Lichtman Date: Thu, 28 Dec 2017 13:10:32 -0800 Subject: [PATCH 2/3] Update test --- tests/cases/fourslash/formattingOptionsChangeJsx.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/formattingOptionsChangeJsx.ts b/tests/cases/fourslash/formattingOptionsChangeJsx.ts index a3c7e28a1ef..067f0b882f2 100644 --- a/tests/cases/fourslash/formattingOptionsChangeJsx.ts +++ b/tests/cases/fourslash/formattingOptionsChangeJsx.ts @@ -1,9 +1,14 @@ /// //@Filename: file.tsx -/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces*/; +/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces1*/; +//// +//// -runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces", ";", ";"); +runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces1", ";", ";"); +runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces2", " { ...this._getButtonProps() }", " {...this._getButtonProps()}"); function runTest(propertyName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) { @@ -11,7 +16,7 @@ function runTest(propertyName: string, expectedStringWhenTrue: string, expectedS goTo.marker(propertyName); // Set the option to false first - format.setOption(propertyName, false); + format.setOption(propertyName.slice(0, -1), false); // Format format.document(); @@ -21,7 +26,7 @@ function runTest(propertyName: string, expectedStringWhenTrue: string, expectedS verify.currentLineContentIs(expectedStringWhenFalse); // Set the option to true - format.setOption(propertyName, true); + format.setOption(propertyName.slice(0, -1), true); // Format format.document(); From 624f68a8e105ce297da06f08ea5cfd461bda065c Mon Sep 17 00:00:00 2001 From: uniqueiniquity Date: Thu, 4 Jan 2018 16:51:19 -0800 Subject: [PATCH 3/3] Simplify marker names --- .../fourslash/formattingOptionsChangeJsx.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/cases/fourslash/formattingOptionsChangeJsx.ts b/tests/cases/fourslash/formattingOptionsChangeJsx.ts index 067f0b882f2..363b53fe81c 100644 --- a/tests/cases/fourslash/formattingOptionsChangeJsx.ts +++ b/tests/cases/fourslash/formattingOptionsChangeJsx.ts @@ -1,37 +1,39 @@ /// //@Filename: file.tsx -/////*InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces1*/; +/////*1*/; //// //// -runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces1", ";", ";"); -runTest("InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces2", " { ...this._getButtonProps() }", " {...this._getButtonProps()}"); +runTest("1", ";", ";"); +runTest("2", " { ...this._getButtonProps() }", " {...this._getButtonProps()}"); -function runTest(propertyName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) { +function runTest(markerName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) { + const propertyName = "InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces"; + // Go to the correct file - goTo.marker(propertyName); + goTo.marker(markerName); // Set the option to false first - format.setOption(propertyName.slice(0, -1), false); + format.setOption(propertyName, false); // Format format.document(); // Verify - goTo.marker(propertyName); + goTo.marker(markerName); verify.currentLineContentIs(expectedStringWhenFalse); // Set the option to true - format.setOption(propertyName.slice(0, -1), true); + format.setOption(propertyName, true); // Format format.document(); // Verify - goTo.marker(propertyName); + goTo.marker(markerName); verify.currentLineContentIs(expectedStringWhenTrue); } \ No newline at end of file