Skip to content

Commit 9f6c4cf

Browse files
committed
one down
1 parent b18407a commit 9f6c4cf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ export function build_component(node, component_name, context, anchor = context.
261261
let expression = /** @type {Expression} */ (context.visit(attribute.expression));
262262

263263
if (attribute.metadata.expression.has_state) {
264-
expression = b.arrow([b.id('$$node')], b.call(expression, b.id('$$node')));
264+
push_prop(b.get(b.call('$.attachment'), [b.return(expression)], true));
265+
} else {
266+
push_prop(b.prop('init', b.call('$.attachment'), expression, true));
265267
}
266-
267-
push_prop(b.prop('get', b.call('$.attachment'), expression, true));
268268
}
269269
}
270270

packages/svelte/src/compiler/utils/builders.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,18 @@ export function function_declaration(id, params, body) {
231231
}
232232

233233
/**
234-
* @param {string} name
234+
* @param {ESTree.Expression | string} name
235235
* @param {ESTree.Statement[]} body
236+
* @param {boolean} computed
236237
* @returns {ESTree.Property & { value: ESTree.FunctionExpression}}}
237238
*/
238-
export function get(name, body) {
239-
return prop('get', key(name), function_builder(null, [], block(body)));
239+
export function get(name, body, computed = false) {
240+
return prop(
241+
'get',
242+
typeof name === 'string' ? key(name) : name,
243+
function_builder(null, [], block(body)),
244+
computed
245+
);
240246
}
241247

242248
/**

0 commit comments

Comments
 (0)