fix: nodeWillIndentChild judge for BinaryExpression with JsxElement child (#44695)

This commit is contained in:
Jm 2021-08-13 05:01:52 +08:00 committed by GitHub
parent 88d8d1ccee
commit 7139f37201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View File

@ -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;
}

View File

@ -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>
);
}`)