-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
JSX whitespace coalescing should work like regular HTML #65
Comments
+1 Similar to how closure's soy templates do this, it might be useful to retain the whitespace in this instance, where the space is clearly between two elements on a single line. However, seems ideal to delete all whitespace if the elements are on separate lines, so that:
would still be equivalent to |
Ugly, but I use the following until a fix:
|
@adambrunner yep, that's the only way right now (though I use |
I'm currently looking into amending this and have done some experimentation with good results. My current implementation basically removes all whitespace that is broken by a newline, and after that all remaining whitespace is collapsed into a single space (and it properly retains whitespace in the produced code). Basically code can be arbitrarily spread over multiple lines without whitespace being produced, and any explicit whitespace within a line produces a single space (i.e,
To me the output of my current rules seem intuitive, except for the last one, it seems like it should produce a whitespace in the middle (or perhaps not?), and that would be easy to fix. But, are there other things to consider perhaps? Is this change to the implementation acceptable or is remaining 100% compatible more important now? |
I agree that those all seem pretty reasonable except the last one. I wouldn't personally find keeping newlines between two tags helpful, though it's at least worth considering because removing it is inconsistent with HTML. |
I'm personally perhaps kind of biased in this as I've always run a preprocessor similar to this over all my HTML, because whitespace would otherwise creep in everywhere causing unwanted spacing to appear "randomly". I personally don't know why anyone would ever want to have a newline translate into whitespace. To be consistent with HTML all whitespace would have to be kept as-is (CSS white-space: pre, etc), but if you ever want that behavior then Here's an intentionally horrible example along with the code it currently produces with my patch, note that now
With my fix it produces the following code: Thought... perhaps the whitespace between the two w's should be kept as-is, i.e, produce
This is what JSXTransformer currently produces:
|
cc @jeffmo |
I like where this is going, and agree with your proposed next step: whitespace that does not contain a newline should not be collapsed. Hopefully since react is not at 1.0 yet, this would still within the range of acceptable compatibility breakages, given a proper writeup in the docs. |
I think I'm onboard with this conceptually. I think this set of rules is, at least, the most intuitive we've come up with thus far. Sounds like everyone else is on board too, so lets do it. (man, whitespace is a bitch...) |
FYI, pull request and more detailed information available at #480 |
Is this something we could provide a codemod/recast script for? When we tweaked this.props.children from always being an array to sometimes being an array it was a huge headache for IG since every callsite had to be manually tested. I want to make sure we don't have to test every callsite and look at whitespace to be sure. |
Fixed by #480. |
Currently, when two escaped entities are outputted the space between them is removed. For the code below the expected output is "Hello World", but the actual output is "HelloWorld" (without a space between "Hello" and "World").
Link to discussion on Google Groups
The text was updated successfully, but these errors were encountered: