Skip to content

Commit ed237a6

Browse files
committed
tweak
1 parent 6564171 commit ed237a6

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,14 @@ export function VariableDeclaration(node, context) {
171171
context.state.transform[id.name] = { read: get_value };
172172

173173
const expression = /** @type {Expression} */ (context.visit(b.thunk(value)));
174-
const call = b.call('$.derived', expression);
175-
return b.declarator(
176-
id,
177-
dev
178-
? b.call(
179-
'$.tag',
180-
call,
181-
b.literal(
182-
`[$state ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`
183-
)
184-
)
185-
: call
186-
);
174+
let call = b.call('$.derived', expression);
175+
176+
if (dev) {
177+
const label = `[$state ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`;
178+
call = b.call('$.tag', call, b.literal(label));
179+
}
180+
181+
return b.declarator(id, call);
187182
}),
188183
...paths.map((path) => {
189184
const value = /** @type {Expression} */ (context.visit(path.expression));
@@ -242,12 +237,15 @@ export function VariableDeclaration(node, context) {
242237
in_derived: rune === '$derived'
243238
})
244239
);
240+
245241
let rhs = value;
246242

247243
if (rune !== '$derived' || init.arguments[0].type !== 'Identifier') {
248244
const id = b.id(context.state.scope.generate('$$d'));
249-
rhs = b.call('$.get', id);
250245
let call = b.call('$.derived', rune === '$derived' ? b.thunk(expression) : expression);
246+
247+
rhs = b.call('$.get', id);
248+
251249
if (is_async) {
252250
const location = dev && !is_ignored(init, 'await_waterfall') && locate_node(init);
253251
call = b.call(
@@ -257,15 +255,12 @@ export function VariableDeclaration(node, context) {
257255
);
258256
call = b.call(b.await(b.call('$.save', call)));
259257
}
258+
260259
if (dev) {
261-
call = b.call(
262-
'$.tag',
263-
call,
264-
b.literal(
265-
`[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`
266-
)
267-
);
260+
const label = `[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`;
261+
call = b.call('$.tag', call, b.literal(label));
268262
}
263+
269264
declarations.push(b.declarator(id, call));
270265
}
271266

svelte.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// we need this so the VS Code extension doesn't yell at us
2+
export default {
3+
compilerOptions: {
4+
experimental: {
5+
async: true
6+
}
7+
}
8+
};

0 commit comments

Comments
 (0)