Skip to content

Commit dd4b8b9

Browse files
committed
fix state declarations in constructors
1 parent 437e663 commit dd4b8b9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ const callees = {
5252
* @returns {Expression | null}
5353
*/
5454
function build_assignment(operator, left, right, context) {
55-
if (context.state.analysis.runes && left.type === 'MemberExpression') {
55+
if (
56+
context.state.analysis.runes &&
57+
left.type === 'MemberExpression' &&
58+
left.object.type === 'ThisExpression'
59+
) {
5660
const name = get_name(left.property);
5761
const field = name && context.state.state_fields.get(name);
5862

@@ -70,7 +74,14 @@ function build_assignment(operator, left, right, context) {
7074
let value = /** @type {Expression} */ (context.visit(right, child_state));
7175

7276
if (dev) {
73-
value = b.call('$.tag', value, b.literal(name));
77+
const declaration = context.path.find(
78+
(parent) => parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression'
79+
);
80+
value = b.call(
81+
'$.tag',
82+
value,
83+
b.literal(`${declaration?.id?.name ?? '[class]'}.${name}`)
84+
);
7485
}
7586

7687
return b.assignment(operator, b.member(b.this, field.key), value);

0 commit comments

Comments
 (0)