Skip to content

Commit

Permalink
fix: nodeWillIndentChild judge for BinaryExpression with JsxElement c…
Browse files Browse the repository at this point in the history
…hild (#44695)
  • Loading branch information
hanzooo authored Aug 12, 2021
1 parent 88d8d1c commit 7139f37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/services/formatting/smartIndenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/cases/fourslash/formatSelectionJsxWithBinaryExpression.ts
Original file line number Diff line number Diff line change
@@ -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>
);
}`)

0 comments on commit 7139f37

Please sign in to comment.