fix: add labels to `@const` tags and props (#16454)

* fix: add labels to `@const` tags and props

* changeset
pull/16456/head
Rich Harris 2 months ago committed by GitHub
parent 5033c8e965
commit 0a2a2e213a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: add labels to `@const` tags and props

@ -17,7 +17,13 @@ export function ConstTag(node, context) {
// TODO we can almost certainly share some code with $derived(...) // TODO we can almost certainly share some code with $derived(...)
if (declaration.id.type === 'Identifier') { if (declaration.id.type === 'Identifier') {
const init = build_expression(context, declaration.init, node.metadata.expression); const init = build_expression(context, declaration.init, node.metadata.expression);
context.state.init.push(b.const(declaration.id, create_derived(context.state, b.thunk(init)))); let expression = create_derived(context.state, b.thunk(init));
if (dev) {
expression = b.call('$.tag', expression, b.literal(declaration.id.name));
}
context.state.init.push(b.const(declaration.id, expression));
context.state.transform[declaration.id.name] = { read: get_value }; context.state.transform[declaration.id.name] = { read: get_value };
@ -55,7 +61,13 @@ export function ConstTag(node, context) {
]) ])
); );
context.state.init.push(b.const(tmp, create_derived(context.state, fn))); let expression = create_derived(context.state, fn);
if (dev) {
expression = b.call('$.tag', expression, b.literal('[@const]'));
}
context.state.init.push(b.const(tmp, expression));
// we need to eagerly evaluate the expression in order to hit any // we need to eagerly evaluate the expression in order to hit any
// 'Cannot access x before initialization' errors // 'Cannot access x before initialization' errors

@ -393,6 +393,10 @@ export function prop(props, key, flags, fallback) {
return getter(); return getter();
}); });
if (DEV) {
d.label = key;
}
// Capture the initial value if it's bindable // Capture the initial value if it's bindable
if (bindable) get(d); if (bindable) get(d);

Loading…
Cancel
Save