Skip to content

Commit 0a2a2e2

Browse files
authored
fix: add labels to @const tags and props (#16454)
* fix: add labels to `@const` tags and props * changeset
1 parent 5033c8e commit 0a2a2e2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.changeset/four-spiders-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: add labels to `@const` tags and props

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ export function ConstTag(node, context) {
1717
// TODO we can almost certainly share some code with $derived(...)
1818
if (declaration.id.type === 'Identifier') {
1919
const init = build_expression(context, declaration.init, node.metadata.expression);
20-
context.state.init.push(b.const(declaration.id, create_derived(context.state, b.thunk(init))));
20+
let expression = create_derived(context.state, b.thunk(init));
21+
22+
if (dev) {
23+
expression = b.call('$.tag', expression, b.literal(declaration.id.name));
24+
}
25+
26+
context.state.init.push(b.const(declaration.id, expression));
2127

2228
context.state.transform[declaration.id.name] = { read: get_value };
2329

@@ -55,7 +61,13 @@ export function ConstTag(node, context) {
5561
])
5662
);
5763

58-
context.state.init.push(b.const(tmp, create_derived(context.state, fn)));
64+
let expression = create_derived(context.state, fn);
65+
66+
if (dev) {
67+
expression = b.call('$.tag', expression, b.literal('[@const]'));
68+
}
69+
70+
context.state.init.push(b.const(tmp, expression));
5971

6072
// we need to eagerly evaluate the expression in order to hit any
6173
// 'Cannot access x before initialization' errors

packages/svelte/src/internal/client/reactivity/props.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ export function prop(props, key, flags, fallback) {
393393
return getter();
394394
});
395395

396+
if (DEV) {
397+
d.label = key;
398+
}
399+
396400
// Capture the initial value if it's bindable
397401
if (bindable) get(d);
398402

0 commit comments

Comments
 (0)