diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 8da3368742ca9..de22396383207 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -606,6 +606,11 @@ namespace ts.formatting { if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217 return rangeIsOnOneLine(sourceFile, child!); } + if (parent.kind === SyntaxKind.BinaryExpression && sourceFile && child && childKind === SyntaxKind.JsxElement) { + const parentStartLine = sourceFile.getLineAndCharacterOfPosition(skipTrivia(sourceFile.text, parent.pos)).line; + const childStartLine = sourceFile.getLineAndCharacterOfPosition(skipTrivia(sourceFile.text, child.pos)).line; + return parentStartLine !== childStartLine; + } if (parent.kind !== SyntaxKind.BinaryExpression) { return true; } diff --git a/tests/cases/fourslash/formatSelectionJsxWithBinaryExpression.ts b/tests/cases/fourslash/formatSelectionJsxWithBinaryExpression.ts new file mode 100644 index 0000000000000..f9510e5af78b9 --- /dev/null +++ b/tests/cases/fourslash/formatSelectionJsxWithBinaryExpression.ts @@ -0,0 +1,36 @@ +/// <reference path="fourslash.ts" /> + +//@Filename: file.tsx +//// function TestWidget() { +//// const test = true; +//// return ( +//// <div> +//// {test && +//// <div> +//// /*1*/ <div>some text</div>/*2*/ +//// <div>some text</div> +//// <div>some text</div> +//// </div> +//// } +//// <div>some text</div> +//// </div> +//// ); +//// } + +format.selection("1", "2"); +verify.currentFileContentIs( + `function TestWidget() { + const test = true; + return ( + <div> + {test && + <div> + <div>some text</div> + <div>some text</div> + <div>some text</div> + </div> + } + <div>some text</div> + </div> + ); +}`)