Skip to content

Commit 7139f37

Browse files
authored
fix: nodeWillIndentChild judge for BinaryExpression with JsxElement child (#44695)
1 parent 88d8d1c commit 7139f37

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/services/formatting/smartIndenter.ts

+5
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ namespace ts.formatting {
606606
if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217
607607
return rangeIsOnOneLine(sourceFile, child!);
608608
}
609+
if (parent.kind === SyntaxKind.BinaryExpression && sourceFile && child && childKind === SyntaxKind.JsxElement) {
610+
const parentStartLine = sourceFile.getLineAndCharacterOfPosition(skipTrivia(sourceFile.text, parent.pos)).line;
611+
const childStartLine = sourceFile.getLineAndCharacterOfPosition(skipTrivia(sourceFile.text, child.pos)).line;
612+
return parentStartLine !== childStartLine;
613+
}
609614
if (parent.kind !== SyntaxKind.BinaryExpression) {
610615
return true;
611616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//@Filename: file.tsx
4+
//// function TestWidget() {
5+
//// const test = true;
6+
//// return (
7+
//// <div>
8+
//// {test &&
9+
//// <div>
10+
//// /*1*/ <div>some text</div>/*2*/
11+
//// <div>some text</div>
12+
//// <div>some text</div>
13+
//// </div>
14+
//// }
15+
//// <div>some text</div>
16+
//// </div>
17+
//// );
18+
//// }
19+
20+
format.selection("1", "2");
21+
verify.currentFileContentIs(
22+
`function TestWidget() {
23+
const test = true;
24+
return (
25+
<div>
26+
{test &&
27+
<div>
28+
<div>some text</div>
29+
<div>some text</div>
30+
<div>some text</div>
31+
</div>
32+
}
33+
<div>some text</div>
34+
</div>
35+
);
36+
}`)

0 commit comments

Comments
 (0)