Skip to content

fix: allow async destructured deriveds #16444

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

Merged
merged 4 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tweak
  • Loading branch information
Rich-Harris committed Jul 19, 2025
commit ed237a69eea137dbca9a1ae748400303db79fc57
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,14 @@ export function VariableDeclaration(node, context) {
context.state.transform[id.name] = { read: get_value };

const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
const call = b.call('$.derived', expression);
return b.declarator(
id,
dev
? b.call(
'$.tag',
call,
b.literal(
`[$state ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`
)
)
: call
);
let call = b.call('$.derived', expression);

if (dev) {
const label = `[$state ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`;
call = b.call('$.tag', call, b.literal(label));
}

return b.declarator(id, call);
}),
...paths.map((path) => {
const value = /** @type {Expression} */ (context.visit(path.expression));
Expand Down Expand Up @@ -242,12 +237,15 @@ export function VariableDeclaration(node, context) {
in_derived: rune === '$derived'
})
);

let rhs = value;

if (rune !== '$derived' || init.arguments[0].type !== 'Identifier') {
const id = b.id(context.state.scope.generate('$$d'));
rhs = b.call('$.get', id);
let call = b.call('$.derived', rune === '$derived' ? b.thunk(expression) : expression);

rhs = b.call('$.get', id);

if (is_async) {
const location = dev && !is_ignored(init, 'await_waterfall') && locate_node(init);
call = b.call(
Expand All @@ -257,15 +255,12 @@ export function VariableDeclaration(node, context) {
);
call = b.call(b.await(b.call('$.save', call)));
}

if (dev) {
call = b.call(
'$.tag',
call,
b.literal(
`[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`
)
);
const label = `[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`;
call = b.call('$.tag', call, b.literal(label));
}

declarations.push(b.declarator(id, call));
}

Expand Down
8 changes: 8 additions & 0 deletions svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// we need this so the VS Code extension doesn't yell at us
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, meant to commit this in a separate PR. oh well never mind

export default {
compilerOptions: {
experimental: {
async: true
}
}
};
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy