-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Allow non-object literals for component registration #594
Comments
The main issue is that Svelte has to be able to statically analyze the components, which isn't possible when calling some sort of Object.assign method. |
Yeah, am in two minds about this for that reason. I see why it's valuable when you have a great many imported components, but it does mean that Svelte has less ability to analyse your code. Some of that has concrete disadvantages e.g. in terms of code size — if Svelte can't link a component tag to an import, then it has to reference it as e.g. Meanwhile, if Then there are things that we're not currently taking advantage of but could, because static analysability is part of the design:
Of course, you only lose those benefits if you opt out of the object expression form (where object spread counts as opting out). My worry is that by relaxing the current constraint people might lose the benefits without realising they've done so, because the tradeoffs aren't totally straightforward to communicate. (The same applies to lots of other things — But maybe the practical considerations outweigh those benefits. Open to persuasion! |
I think this can be closed. There's a boilerplate-reducing proposal in #1038, which still allows for compile-time analysis. We can re-open if someone disagrees. |
Currently Svelte requires the
components
declaration to be an object literal. A very handy feature would be to allow non-object literals so we can bundle components into modules.http://babeljs.io/docs/plugins/transform-object-rest-spread/
http://babeljs.io/docs/plugins/transform-object-assign
Either of these babel plugins would allow for this syntax and prevent us from having to do the following in every component that needs to use a form:
This might not look so bad, but when you are importing from other bundled libraries the problem compounds and becomes quite significant.
Angular has solved this problem with their module system, but their module system is insane. Svelte can achieve the same benefit just by using native javascript modules and a transpiler.
The text was updated successfully, but these errors were encountered: