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

pull/16454/head
Rich Harris 2 months ago
parent 5033c8e965
commit c7f64f08ab

@ -17,7 +17,13 @@ export function ConstTag(node, context) {
// TODO we can almost certainly share some code with $derived(...)
if (declaration.id.type === 'Identifier') {
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 };
@ -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
// 'Cannot access x before initialization' errors

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

Loading…
Cancel
Save