make component-exported state work

pull/10523/head
Rich Harris 3 years ago
parent 0d8bafa690
commit fdbf2d5146

@ -966,9 +966,6 @@ export const validation_runes = merge(validation, a11y_validators, {
if (state.analysis.instance.scope !== state.scope) return;
error(node, 'invalid-legacy-export');
},
ExportSpecifier(node, { state }) {
validate_export(node, state.scope, node.local.name);
},
CallExpression(node, { state, path }) {
validate_call_expression(node, state.scope, path);
},

@ -52,7 +52,10 @@ export function get_assignment_value(node, { state, visit }) {
*/
export function is_state_source(binding, state) {
return (
(binding.kind === 'state' || binding.kind === 'frozen_state') &&
(binding.kind === 'state' ||
binding.kind === 'frozen_state' ||
binding.kind === 'derived' ||
binding.kind === 'prop') &&
(!state.analysis.immutable || binding.reassigned || state.analysis.accessors)
);
}

@ -7,6 +7,6 @@ export default test({
btn?.click();
await Promise.resolve();
assert.htmlEqual(target.innerHTML, '0 1 <button>0 / 1</button>');
assert.htmlEqual(target.innerHTML, '1 2 <button>1 / 2</button>');
}
});

@ -4,4 +4,4 @@
</script>
<Sub bind:this={sub} />
<button on:click={() => sub.increment()}>{sub?.count1.value} / {sub?.count2.value}</button>
<button on:click={() => sub.increment()}>{sub?.count} / {sub?.doubled}</button>

@ -1,15 +1,13 @@
<script>
export const count1 = $state.frozen({value: 0});
export const count2 = $state({value: 0});
export function increment() {
count2.value += 1;
}
let count = $state(0);
let doubled = $derived(count * 2);
</script>
export { count, doubled };
{count1.value}
{count2.value}
export function increment() {
count += 1;
}
</script>
<!-- so that count1/2 become sources -->
<svelte:options accessors />
{count}
{doubled}

Loading…
Cancel
Save