first of many

pull/12530/head
Rich Harris 2 years ago
parent f6d12064f6
commit b96401b645

@ -1786,21 +1786,24 @@ export const template_visitors = {
const identifiers = extract_identifiers(declaration.id);
const tmp = b.id(state.scope.generate('computed_const'));
const getters = { ...state.getters };
// Make all identifiers that are declared within the following computed regular
// variables, as they are not signals in that context yet
for (const node of identifiers) {
const binding = /** @type {import('#compiler').Binding} */ (state.scope.get(node.name));
binding.expression = node;
getters[node.name] = node;
}
const child_state = { ...state, getters };
// TODO optimise the simple `{ x } = y` case — we can just return `y`
// instead of destructuring it only to return a new object
const fn = b.arrow(
[],
b.block([
b.const(
/** @type {Pattern} */ (visit(declaration.id)),
/** @type {Expression} */ (visit(declaration.init))
/** @type {Pattern} */ (visit(declaration.id, child_state)),
/** @type {Expression} */ (visit(declaration.init, child_state))
),
b.return(b.object(identifiers.map((node) => b.prop('init', node, node))))
])

Loading…
Cancel
Save