-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Consider replacing export const
and export function
with a rune
#12778
Comments
|
Right, but the suggestion is to introduce a rune for exposing things on the component instance, and then to make I still really don't think this is a good idea, though, for a few reasons. Everything else in |
That's what I was trying to get at. If you mix them up then the scoping becomes a mess as things created in the instance can't be referenced as an export too. |
@Conduitry @trueadm You are right about the scoping issue, but in my opinion, the argument that "the last pieces of Svelte that look like JavaScript but have entirely different functionality" still holds. It doesn't make sense to export something at the instance level. If we think of a component as a class, exporting something might look like this (in a programmer's mental model): export default class Counter {
count = $state(0)
export function increment() {
count++
}
} If we think of a component as a function (as is the behavior in Svelte 5): export default function Counter {
count = $state(0)
export function increment() {
count++
}
return <div />
} Neither of these examples makes sense in the context of vanilla JavaScript. The syntax is different with vanilla semantics and confusing. |
@Rich-Harris Any comment on this? |
export const
and export function
, in favor of allowing native ESM exports in Svelte 5export const
and export function
with a rune
It's true that we're using So it becomes a question of what makes things easier to work with. And it's not clear to me that a rune would really help here. The
In other words it's all downside as far as I can tell. |
@Rich-Harris Sorry for the delayed response. I gave some thought to your comments.
The same logic is also applied to other runes like
Considering we only have function $returned(args) {
return args;
}
const anArray = [0, 1, 2];
function push(value) {
anArray.push(value)
}
const stuff = { anArray, push };
const returnedValues = $returned(stuff);
returnedValues.push(3);
console.log(stuff.anArray); // [0, 1, 2, 3]
console.log(anArray); // [0, 1, 2, 3] |
Describe the problem
I just finished reading the documentation on Svelte 5. The syntax has become more JavaScript-fy, closely mirroring vanilla semantics with some magic for reactivity, except for one key difference:
export
.export const
andexport function
are the last pieces of Svelte that look like JavaScript but have entirely different functionality (which is a drawback for some). If we drop these (and perhaps move their functionality to a new rune), Svelte’s syntax would work "the same" as JavaScript, making it more approachable for newcomers from other frameworks.It would also make
<script context="module">
obsolete, as we could then export named variables just like how we do in JavaScript."Describe the proposed solution
Introduce a new rune to replace
export const
andexport function
. Maybe$this()
?Importance
would make my life easier
The text was updated successfully, but these errors were encountered: