-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixing JSX/TSX closing tag/attribute/expression formatting #4398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -387,7 +389,10 @@ namespace ts.formatting { | |||
|
|||
let indentation = inheritedIndentation; | |||
if (indentation === Constants.Unknown) { | |||
if (isSomeBlock(node.kind)) { | |||
if (isIndentPreventedChildNode(parent.kind, node.kind)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would inline the body of isIndentPreventedChildNode,
if (parent.kind === SyntaxKind.JsxElement && child.kind === SyntaxKind.JsxClosingElement)
it is more readable this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is similar to closing braces and parens, maybe we should add it to get indentationForToken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly move getIndentationForToken to a new helper, call it in getIndentationForToken, and from here and add support for jsx elements in it as well.. possibly give the new helper a better name as getIndentationForNode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhegazy I currently have no idea so I just inlined it. I agree that the closing node is similar to closing tokens but I think nodes and tokens are being processed with some differences by different functions so a merged helper may not really simplify the code.
I have to figure out how I can merge getIndentationForToken and isIndentPreventedChildNode. A simple merge breaks indentation here: let x = <div>
</div>; // works well
let y = foo
(3); // should be indented but fails PS: I've decided not to do this at least in this PR. |
Will this cover the following (parenthesis and newline)? return (
<div>
<div />
</div>
); If yes, perhaps adding a test for this specific case. |
@kuon Yes it does, and I think this PR already tests that case (where JsxElement is contained in parenthesis.) |
👍 |
can you please refresh this PR, i think we are ready to go. Thanks for your patience and sorry for the delay. |
Fixing JSX/TSX closing tag/attribute/expression formatting
Thanks @saschanaz! |
Closes #3838.
Current:
Fix: