sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.4k stars 4.11k forks source link

Add a way to comment out props/attributes/directives #5213

Closed trbrc closed 4 years ago

trbrc commented 4 years ago

Is your feature request related to a problem? Please describe. A weakness of most XML-like syntaxes is that they don't support a good way to comment out attributes. This problem affects Svelte too. It can be frustrating when you quickly want to toggle some code off while debugging. It also makes it slightly more inconvenient to document what attributes do, although that's probably a secondary concern as it's easier to give such comments a legal placement.

Describe the solution you'd like I would like Svelte to support comments in the body of start tags. The specific syntax doesn't matter so much, but I would probably expect JS-like comments:

<div
  // style="color: pink"
  /* style="
    color: magenta;
  " */
  style="color: purple"
>...</div>

Describe alternatives you've considered There are no convenient workarounds that I can think of. Someone suggested prefixing the attribute name with an underscore. That works OK for plain HTML, but is not a practical solution in Svelte, as Svelte will still include potentially invalid JavaScript expressions in the attribute value, and try to set the whole thing as an attribute.

You can wrap the comment in a spread so the comment ends up inside JS expression, but that's very clunky:

<div
  {...{/* style="
    color: magenta;
  " */}}
>...</div>

How important is this feature to you? Not hugely, but it would be convenient.

Additional context One potential counter-argument is that Svelte should stick to what HTML does natively here; I'm not sure I agree since Svelte already has plenty of custom syntax around attributes.

Conduitry commented 4 years ago

This has come up before, although it looks like only in chat and not in an issue - https://discord.com/channels/457912077277855764/507200834837151754/650023325988290560 - I'm not going to copy and paste the whole huge discussion here, but there are a few reasons we don't want to do this.