-
-
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
fix: hoist imports on top #13082
fix: hoist imports on top #13082
Conversation
🦋 Changeset detectedLatest commit: d908861 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 |
packages/svelte/src/compiler/phases/3-transform/client/transform-client.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about the other option (introducing a separate state.imports
array) but concluded this is fine and possibly even a bit more robust to future changes
This reverts commit 81b32d8.
It doesn't work like that —
That's because the sort order is engine-dependent — something that yields the desired results in Chrome might fail in Firefox and vice-versa |
🤯🤯🤯 TIL |
However, since ES10 / ES2019 specs require the sorting to be stable if the comparator is consistent (in this PR, it isn't):
MDN - look at the There is a number of conditions when the order becomes "implementation-defined", but for ordinary arrays, only the comparator consistency and pureness of all involved methods matter. |
Svelte 5 rewrite
Closes #13081
Initially i thought of having a separate
hoisted
array that put everything higher up but i think that would become confusing very quickly...this will sort the body to put every import on the top so that if you reference it it will actually be available. Personally i think it's good enough but you guys tell me.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