-
-
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
Component arguments that are not valid JS identifiers #887
Comments
Thanks! Yeah, something should be done about this. I'm wondering though whether it might be better to instead disallow attributes like |
I think once #1106 gets settled, we should do the same thing here. |
I think there probably are more sweeping changes we want to make here. Data properties in components whose names aren't valid identifiers can't be accessed in template tags. It's true that If we make those be dev warnings (and not dev exceptions), does it still make sense to disallow non-identifier-safe component arguments at compile time, or should that too be a warning and we just quote the key in the compiled component? Not sure what's best. How much limiting of the component author is helpful and how much is overbearing? |
Additionally, a way to access these data fields from template tags could be added, though I can't think of a nice syntax.. |
My inclination here would be to disallow invalid identifiers as component properties, because there are so many caveats around their use (e.g. you can't use them in computed props, etc). The one thing holding me back is the possibility of us introducing spread props, where leftover props could be added to an element: <!-- App.html -->
<Widget data-foo='bar'/>
<!-- Widget.html -->
<div ...someSubsetOfProps>...</div> |
This fixes sveltejs#887 by quoting name of attributes if those are invalid JS identifiers when passing data to nested components.
REPL
When
b-c='2'
is changed to, say,b_c='2'
it works.The problem is the generated code has
data: {b-c: 2}
, whereb-c
is not quoted.The text was updated successfully, but these errors were encountered: