fix: handle whitespace according to JSX common practice#6051
fix: handle whitespace according to JSX common practice#6051lukastaegert merged 3 commits intorollup:masterfrom
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-whitespaceNotice: 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
|
4f432c0 to
e1662aa
Compare
There was a problem hiding this comment.
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 👍🏻 |
lukastaegert
left a comment
There was a problem hiding this comment.
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 rollup@4.48.1. 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