-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Normalize whitespaces in attribute values during compilation #6004
Comments
As of version 1.3.0, via sveltejs/prettier-plugin-svelte#145, the Prettier plugin no longer formats I have mixed feelings about whether the compiler should collapse whitespace in |
@Conduitry Okay, but even if Prettier doesn't do that anymore, it still makes perfect sense to format your classes that way if you have a lot of them; otherwise if they're all on a single line it would become ridiculously long and pretty hard to look at! Wouldn't you agree?
I can't think of any cases where that could be undesirable or problematic, since it would make no functional difference whatsoever. (in the case of the |
I agree. I think not only the classes but all the whitespaces in the entire HTML should be taken car eof, any redundant whitespaces should be removed. There is no reason not to do this. As mentioned, they just increase the bundle size completely unnecessarily.
Why shouldn't it?! In what attribute does that make any difference? |
Removing whitespace inside HTML content (not attributes) can be dangerous because people might style the element such that it should preserve whitespace. |
@dummdidumm Sure, I don't think Svelte should collapse whitespaces inside tags, although it'd be nice if we could have an option for that too, such that the developer could make the decision themself, because after all, most of the multiwhitespaces are just there for formatting, and so they ultimately add to the bundle size totally unnecessarily). But in the case of attribute values, again, I can't think of any cases where multiple whitespaces would make any difference at all, and therefore there is no reason to preserve them there. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi there again. |
In 3.42.2, |
Is your feature request related to a problem? Please describe.
It's not unusual to want to format your code (in this example particularly your CSS classes) in the following style:
In fact, I think Prettier and some other formatting tools encourage a similar thing, namely breaking a long line of code into several shorter ones, and Prettier specifically does it with CSS classes.
But this apparently causes the Svelte compiler to generate code like this:
Notice all the unnecessary "\r"s, "\n"s, and multiple whitespace characters.
These:
Screenshot from Chrome DevTools
Describe the solution you'd like
Since multiple whitespaces, tabs, and line breaks inside HTML attribute values are always ignored by browsers and cause no functional difference, the Svelte compiler could easily ignore these characters, and "normalize" the whitespaces in attribute values, without causing any harm.
So that the result would look like this:
The text was updated successfully, but these errors were encountered: