Skip to content
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

Suggestion: Comments in the middle of attribute lists #6087

Closed
CherryDT opened this issue Mar 14, 2021 · 2 comments
Closed

Suggestion: Comments in the middle of attribute lists #6087

CherryDT opened this issue Mar 14, 2021 · 2 comments

Comments

@CherryDT
Copy link

CherryDT commented Mar 14, 2021

Is your feature request related to a problem? Please describe.
In the case of complex components which take a ton of attributes (something like a generic CrudForm or things like that) I usually split them up to one per line. In this case it would sometimes be useful to add comments to specific attributes to explain something about them. Right now there is no way (that I know of) to add any sort comment in the middle of an attribute list.

Describe the solution you'd like
I would like to be able to add comments of some sort in the middle of an attribute list, for example:

<ComplexComponent
  stuff1="stuff1"
  stuff2="STUFF2" <<< I'd like to write something about why stuff2 is uppercase here
  stuff3="stuff3"
/>

An idea of how this could look would be to use {/* ... */} as syntax (and in extension to allow, albeit meaningless, {} and just emit a warning for it - right now it crashes, see #6086):

<ComplexComponent
  stuff1="stuff1"
  stuff2="STUFF2" {/* stuff2 needs to be uppercase because reasons */}
  stuff3="stuff3"
/>

Open to better ideas of course...

Describe alternatives you've considered
One alternative would be to pass props using {...{a: 'a', b: 'b'}} instead of a="a" b="b" (which is a JS expression and therefore allows /* ... */ in the middle), but that means that it looks and behaves differently from other usages of attributes, so it's not ideal. Also, you can't do that with bind:x, let:x, on:x or slot then.

<ComplexComponent {...{
  stuff1: 'stuff1',
  stuff2: 'STUFF2' // stuff2 needs to be uppercase because reasons
  stuff3: 'stuff3'
}} />

The way I currently use is {...{/* comment */}} which works but is ugly of course.

<ComplexComponent
  stuff1="stuff1"
  stuff2="STUFF2" {...{/* stuff2 needs to be uppercase because reasons */}}
  stuff3="stuff3"
/>

How important is this feature to you?
Not that important, just a nice-to-have

@dummdidumm
Copy link
Member

Duplicate of sveltejs/rfcs#43

@dummdidumm dummdidumm marked this as a duplicate of sveltejs/rfcs#43 Mar 14, 2021
@CherryDT
Copy link
Author

Oh. Good to know someone else had the exact same idea already, I looked in the issues here but not in RFCs. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants