-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSX formatting does not de-indent closing tag with text body #20766
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
Comments
@mhegazy I've been working on this, and it looks like this doesn't get formatted because the linebreak and whitespace between The fix is along the lines of stopping after the linebreak, which will make the closing |
sounds reasonable. I have not looked at the formatting scanner in a while, so i will need to look at the change, and look around to see if i can poke holes into the fix. |
It's getting late on a Friday, so I'm leaving myself some notes: Today the text nodes inside the JSXText are this range: <div>
|text
|</div> Which includes the trailing whitespace. To fix this bug I've explored (a): <div>
|text|
</div> and (b) <div>
|text
| </div> b is is what Mosho1 recommends above, and a seems promising but needs some finessing somewhere also. Issues:
There's a good chance the first one is a fencepost error somewhere, but the second I've not figured out yet. WIP here |
After amending the parser, it looks like the next issues is that we don't handle JSX siblings affecting indentation: All of these (
<div>
<span/>
<span/>
<div id="x">
<p>OK</p>
</div>
<span/>
<span/>
</div>
) Which on master today formats to: (
<div>
<span/>
< span />
<div id= "x" >
<p>OK < /p>
< /div>
< span />
<span/>
< /div>
) Which is kinda wild because that code isn't legit JSX. |
It wasn't legit JSX, because it wasn't declared to be a JSX file - doh. |
From microsoft/vscode#40454 (comment)
TypeScript Version: 2.7.0-dev.20171214
Code
Run format
Expected behavior:
Actual behavior:
No change. Content remains:
The
</div>
is de-indented if the body is a tag instead of text:The text was updated successfully, but these errors were encountered: