-
-
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
[Svelte 5] Literal 0
(zero) cannot be set as prop without giving it any default
#10854
Comments
Should we even permit numeric literals as props? |
Maybe not. There was some dislike expressed in the |
In Svelte 4 it is possible to use bascially anything as an identifier, you could then access it through |
It's less about if it's technically feasible, but rather is it a good idea to begin with. Having a
|
We don't promote it and I hope noone does this - given that we want Svelte 5 to be upgradeable as much as possible, I vote for keep allowing it for 5.0 but add a compiler warning (we already have one for |
I should also note that since attributes are just strings, they can be non-ASCII. I'm not sure where the line should be drawn, but allowing |
I think the prop name should match js var names except for allowing |
I feel like limiting it gets weird. While I think any restriction just for the sake of not allowing weird props is a bad idea. They are just strings, which are valid in object destructuring. Disallowing literal numbers in the destructuring pattern seems reasonable since there's no way to use them, but other than that, why restrict it? |
Indeed, it makes sense to limit the first symbol of a name to Kebab-case is required to bypass and/or intercept HTML attributes. I think adequate people won't define custom props in kebab-case, except for maybe custom elements. Using weird names is a way to shoot in your leg, and the code will only confuse people. In any case, it's possible to pass a prop with whatever name via spreading and resting props. |
It seems there's already a limitation on attribute names for custom components: I think matching the spec as closely as possible would be best. EDIT: It seems as though this is the definition for valid attribute names:
Related, valid custom element names look like this:
and must not be one of these:
sources: |
I suppose it doesn't really make sense to follow the spec for web components since attributes can already be non-conformant (capital letters). |
Describe the bug
If a component exposes a literal
0
(zero) as a prop, it cannot be set by the parent without setting a default value (even ofundefined
).One alternative is to just use a string representation (i.e.,
'0'
), but it's odd that this doesn't work for0
but does for other numbers.The compiled code is odd - it's like it's treating
0
as special, even though it's actually receiving the string representation - '0
'.Reproduction
repl
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: