-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: error on invalid component name #12821
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
feat: error on invalid component name #12821
Conversation
🦋 Changeset detectedLatest commit: 5b105ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: Conduitry <[email protected]>
Per comments elsewhere, I think we need to go in the opposite direction and only allow dot notation. This works unintentionally and is buggy |
Ok so by fixing you mean disallow array access even on uppercase components? Because i think we could make it work properly in the uppercase case too. |
We definitely could make it work, but where do you draw the line? <Things[currentThing??'default']??Fallback {...props} /> Rather than creating the illusion that any JS expression is valid, we should just have clear rules — a component name can be an identifier, or a member expression with dot notation |
Fair enough...should i switch this PR to throwing an error in case the component is not in the right format? |
Just my two cents. Something that is not component shouldn't be allowed to be called like <script>
let Component = ()=>console.log("hi");
</script>
<Component /> |
Components aren't signed like snippets and don't really differ from any other function, so the runtime distinction is tricky and fragile. And it looks more like aiming their own leg, so... Also, TS completely prevents this, unless |
yes please
Exactly — this is what TypeScript is for. We don't need to do anything beyond that |
[
as a component, even if lowercase
@Rich-Harris did it...not entirely convinced on the error message. Also i've thrown directly in the parsing phase because if we know that it's already wrong why even continue parsing and i did consider it a parsing error rather than a validation one but don't know if we want to move it to the validation phase to keep the validation all in the validation phase. |
tweaked the error message:
|
One thing we're still missing — validation for things like |
I specifically avoided that validation because technically it works...the browser will create an element with I understand that this might be misleading but also since you can't have a component with array access either maybe is less of expected that this will yield a component in the first place. |
Yeah I wasn't really sure about the error message either for the same reasons...thanks for taking care of it. |
Svelte 5 rewrite
Cheap follow up to #12798 that i've quickly implemented after a brief discussion on sveltejs/kit#12573 (comment)
Given it's already allowed for uppercase components i think it makes sense to also allow tags like
arr[0]
. If we actually don't want this feel free to close it didn't take me much.Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint