-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: handle derived destructured iterators #16015
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
Conversation
🦋 Changeset detectedLatest commit: 02f48a1 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 |
|
Nothing to apologise for! It seemed like a totally reasonable solution. I personally haven't yet formed the right mental habits around generators, so I tend to miss these sorts of issues |
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.
Looks good, hence approving, but can't help but wonder if we should generate a name within extract_paths
that is deduplicated at the root scope level instead. That would save us from having to do id.name = ...
at all call sites, and also makes this less prone to bugs where the id node is somehow switched out inside some visitor. You could also pass in the scope id generator function and/or a preferred variable name, if it's about readability.
Oh and this needs a changeset
I did wonder about that, but the fact that we're using |
Co-authored-by: Simon H <[email protected]>
I think all the call sites use a well-known scope function, so as an alternative you could pass the id creator function into - const { inserts, paths } = extract_paths(node.context, unwrapped);
+ const { inserts, paths } = extract_paths(node.context, unwrapped, context.state.scope.generate);
for (const { id, value } of inserts) {
- id.name = context.state.scope.generate('$$array');
child_state.transform[id.name] = { read: get_value };
const expression = /** @type {Expression} */ (context.visit(b.thunk(value), child_state));
declarations.push(b.var(id, b.call('$.derived', expression)));
} but not too concerned about the current state either; your choice |
Thing is you'd need to pass an arrow function, since it's not bound, so the diff would actually look like this... - const { inserts, paths } = extract_paths(node.context, unwrapped);
+ const { inserts, paths } = extract_paths(
+ node.context,
+ unwrapped,
+ (name) => context.state.scope.generate(name)
+ );
for (const { id, value } of inserts) {
- id.name = context.state.scope.generate('$$array');
child_state.transform[id.name] = { read: get_value };
const expression = /** @type {Expression} */ (context.visit(b.thunk(value), child_state));
declarations.push(b.var(id, b.call('$.derived', expression)));
} ...so you don't really gain anything except indirection |
It seems this commit caused our builds to start failing. We haven't yet migrated all our components to rune based syntax so one of these older components had something like:
This started causing pretty weird: Stack trace:
I was able to get past this by changing the implementation to:
Breaking version is |
@kkarikos please open a new issue with an actual reproduction...the generated code from this snippet you posted is not different between |
…ident (Note that you need plugins to import files that are not JavaScript) sveltejs/svelte#16015 looks related
* add excel and CSV export functions to new table-export.ts (prev html-to-img.ts) - new `xlsx` dependency for Excel export - `generate_csv` and `generate_excel` functions handle CSV and Excel file generation - new CSV and Excel download buttons on landing page - new vitest tests to cover all export formats * bump site deps * guard against empty worksheet in generate_excel * workaround src/routes/tasks/diatomics/+page.svelte (43:17): Expected ident (Note that you need plugins to import files that are not JavaScript) sveltejs/svelte#16015 looks related
I believe this PR breaks Zag JS. I've found that it breaks their menu component; it seems like a proxied state set (or get) doesn't work correctly anymore, see chakra-ui/zag#2502. It might also be the other change in |
It's already fixed in the latest version of svelte |
No, it's not, wait... Oh, dang, it's a Firefox-only issue. This spices things up a bit. |
Closes #15996
I've sunk way too much time into this and can't justify sinking any more right now, but basically this reverts #15813 (sorry @Ocean-OS, I should have been more careful before merging it), tweaks some of the
extract_paths
logic, and adds a failing test.Right now this is broken...
...because the
let [$$1, $$2, $$3] = $.get($$d)
gets generated for each ofa
,b
andc
. But after the first one, the generator is 'spent', and everything after is undefined.We instead need to do the destructuring once to create the array, and reference members of that array (or, in the case of a rest element,
$$array.slice(index)
). Or as an alternative to destructuring we could probably do something like this:Another issue with #15813 is that it only changes the logic in the
VariableDeclaration
visitor, but if we want to be rigorous we need similar handling for other places whereextract_paths
is used, e.g. each blocks.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