-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: rewrite destructuring logic to handle iterators #15813
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 6ecdba5 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 |
|
This may produce multiple spreadings: example // source
let [first, second, third] = $state(array);
// output
let tmp = array,
first = $.state($.proxy([...tmp][0])),
second = $.state($.proxy([...tmp][1])),
third = $.state($.proxy([...tmp][2])); while it would be better let tmp = [...array],
first = $.state($.proxy(tmp[0])),
second = $.state($.proxy(tmp[1])),
third = $.state($.proxy(tmp[2])); or even function to_array(iterable) {
return Array.isArray(iterable) ? iterable : [...iterable]
}
let tmp = to_array(array),
... though I'm not sure about TypedArrays |
I'll try the second one, and see how well it works. The only issue is assignments, which don't always result in a temporary variable being made. |
Still the same behavior 🤔 |
Just realized that since generator functions are iterators, then this sort of thing (which I use very often) would break. |
Currently, the compiler assumes that whenever you use array destructuring that the object you're destructuring is an array, and can be interpreted as this:
However, due to iterators, and anything else using
Symbol.iterator
, this breaks things. This fixes that by reusing the original destructuring logic, like so:Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint