|
|
@ -17,7 +17,13 @@ export function ConstTag(node, context) {
|
|
|
|
// TODO we can almost certainly share some code with $derived(...)
|
|
|
|
// TODO we can almost certainly share some code with $derived(...)
|
|
|
|
if (declaration.id.type === 'Identifier') {
|
|
|
|
if (declaration.id.type === 'Identifier') {
|
|
|
|
const init = build_expression(context, declaration.init, node.metadata.expression);
|
|
|
|
const init = build_expression(context, declaration.init, node.metadata.expression);
|
|
|
|
context.state.init.push(b.const(declaration.id, create_derived(context.state, b.thunk(init))));
|
|
|
|
let expression = create_derived(context.state, b.thunk(init));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
|
|
|
|
expression = b.call('$.tag', expression, b.literal(declaration.id.name));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.state.init.push(b.const(declaration.id, expression));
|
|
|
|
|
|
|
|
|
|
|
|
context.state.transform[declaration.id.name] = { read: get_value };
|
|
|
|
context.state.transform[declaration.id.name] = { read: get_value };
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +61,13 @@ export function ConstTag(node, context) {
|
|
|
|
])
|
|
|
|
])
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
context.state.init.push(b.const(tmp, create_derived(context.state, fn)));
|
|
|
|
let expression = create_derived(context.state, fn);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dev) {
|
|
|
|
|
|
|
|
expression = b.call('$.tag', expression, b.literal('[@const]'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.state.init.push(b.const(tmp, expression));
|
|
|
|
|
|
|
|
|
|
|
|
// we need to eagerly evaluate the expression in order to hit any
|
|
|
|
// we need to eagerly evaluate the expression in order to hit any
|
|
|
|
// 'Cannot access x before initialization' errors
|
|
|
|
// 'Cannot access x before initialization' errors
|
|
|
|