|
3 | 3 | /** @import { Context } from '../types' */ |
4 | 4 | import * as b from '#compiler/builders'; |
5 | 5 | import { dev } from '../../../../state.js'; |
| 6 | +import { get_parent } from '../../../../utils/ast.js'; |
6 | 7 | import { get_name } from '../../../nodes.js'; |
7 | 8 |
|
8 | 9 | /** |
@@ -76,23 +77,21 @@ export function ClassBody(node, context) { |
76 | 77 | if (dev) value = b.call('$.tag', value, b.literal(name)); |
77 | 78 | body.push(b.prop_def(definition.key, value)); |
78 | 79 | } else if (field.node === definition) { |
79 | | - const member = b.member(b.this, field.key); |
| 80 | + let call = /** @type {CallExpression} */ (context.visit(field.value, child_state)); |
| 81 | + |
| 82 | + if (dev) { |
| 83 | + const declaration = /** @type {ClassDeclaration | ClassExpression} */ ( |
| 84 | + get_parent(context.path, -1) |
| 85 | + ); |
| 86 | + |
| 87 | + call = b.call('$.tag', call, b.literal(`${declaration.id?.name ?? '[class]'}.${name}`)); |
| 88 | + } |
80 | 89 |
|
| 90 | + const member = b.member(b.this, field.key); |
81 | 91 | const should_proxy = field.type === '$state' && true; // TODO |
82 | | - const call = /** @type {CallExpression} */ (context.visit(field.value, child_state)); |
| 92 | + |
83 | 93 | body.push( |
84 | | - b.prop_def( |
85 | | - field.key, |
86 | | - dev |
87 | | - ? b.call( |
88 | | - '$.tag', |
89 | | - call, |
90 | | - b.literal( |
91 | | - `${/** @type {ClassDeclaration | ClassExpression} */ (context.path.at(-1))?.id?.name ?? '[class]'}.${field.key.name}` |
92 | | - ) |
93 | | - ) |
94 | | - : call |
95 | | - ), |
| 94 | + b.prop_def(field.key, call), |
96 | 95 |
|
97 | 96 | b.method('get', definition.key, [], [b.return(b.call('$.get', member))]), |
98 | 97 |
|
|
0 commit comments