-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: handle whitespace according to JSX common practice #6051
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
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6051 +/- ##
=======================================
Coverage 98.79% 98.79%
=======================================
Files 271 271
Lines 10610 10620 +10
Branches 2834 2838 +4
=======================================
+ Hits 10482 10492 +10
Misses 88 88
Partials 40 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install cyyynthia/rollup#jsx-whitespace Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. or load it into the REPL: |
Performance report
|
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.
See my example, but in general this looks good, thanks for tackling this issue! I could confirm that for single line-breaks at the beginning/end, the text is completely tree-shaken in the output, which matches what Babel does here as well.
4f432c0
to
e1662aa
Compare
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.
Thanks! I just stumbled across another issue with the tree-shaking of white-space text. Compare this https://rollup-90iirwpg8-rollup-js.vercel.app/repl/?pr=6051&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwZnVuY3Rpb24lMjBmKCklMjAlN0IlNUNuJTIwJTIwJTIwJTIwcmV0dXJuJTIwKCU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlM0MlM0UlM0NkaXYlMkYlM0UlM0MlMkYlM0UlNUNuJTIwJTIwJTIwJTIwKSUzQiU1Q24lN0QlNUNuJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJqc3glMjIlM0ElMjJyZWFjdC1qc3glMjIlMkMlMjJvdXRwdXQlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiU3RCU3RCU3RA== with this https://rollup-90iirwpg8-rollup-js.vercel.app/repl/?pr=6051&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyZXhwb3J0JTIwZnVuY3Rpb24lMjBmKCklMjAlN0IlNUNuJTIwJTIwJTIwJTIwcmV0dXJuJTIwKCU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlM0MlM0UlNUNuJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTNDZGl2JTJGJTNFJTVDbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUzQyUyRiUzRSU1Q24lMjAlMjAlMjAlMjApJTNCJTVDbiU3RCU1Q24lMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmpzeCUyMiUzQSUyMnJlYWN0LWpzeCUyMiUyQyUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTdEJTdEJTdE
If a text is completely removed because the text only contains a line-break with spaces, then it might use the jsxs
function even though it should rather switch to the jsx
function. In the example, it is particularly problematic because it uses the jsxs
function without an array.
So the logic to detect whether to use an array correctly detects this case, but the logic to decide whether to use jsxs/jsx
does not...
Ah! You're good with coming up with these edge cases, I should've been a bit more careful when implementing it 😄 Adjusted the logic and added a test case 👍🏻 |
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.
Ah! You're good with coming up with these edge cases
Thanks, but no worries. Admittedly, I would have nearly overlooked it myself, but after some recent hiccups, I thought I spend a little more time in the REPL.
Looks really good now. Without your initiative, this issue would still be largely ignored at this point I fear...
This PR has been released as part of [email protected]. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
This PR fixes the handling of whitespace within JSX text, matching the generally agreed (for the lack of a proper spec) upon behavior of whitespace in React.
It also fixes an edge-case where invalid JS code was generated if a plaintext attribute had a newline in it. Those do not obey to the same whitespace rules as text.
References