diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index ef0c32b6a0..bd7b99bd8f 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -228,7 +228,7 @@ export default function dom( return b`${`$$subscribe_${name}`}()`; } - const callback = x`$$value => { $$invalidate('${value}', ${value} = $$value) }`; + const callback = x`$$value => $$invalidate('${value}', ${value} = $$value)`; let insert = b`@component_subscribe($$self, ${name}, $${callback})`; if (component.compile_options.dev) { @@ -356,7 +356,7 @@ export default function dom( if (store && store.reassigned) { const unsubscribe = `$$unsubscribe_${name}`; const subscribe = `$$subscribe_${name}`; - return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => { $$invalidate('${$name}', ${$name} = $$value); }), ${name})`; + return b`let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate('${$name}', ${$name} = $$value)), ${name})`; } return b`let ${$name};`; diff --git a/test/js/samples/component-store-access-invalidate/expected.js b/test/js/samples/component-store-access-invalidate/expected.js index e332a0dbb5..029c0a6d21 100644 --- a/test/js/samples/component-store-access-invalidate/expected.js +++ b/test/js/samples/component-store-access-invalidate/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -12,44 +11,37 @@ import { set_data, text } from "svelte/internal"; + import { writable } from "svelte/store"; function create_fragment(ctx) { - var h1, t; + let h1; + let t; return { c() { h1 = element("h1"); t = text(ctx.$foo); }, - m(target, anchor) { insert(target, h1, anchor); append(h1, t); }, - p(changed, ctx) { - if (changed.$foo) { - set_data(t, ctx.$foo); - } + if (changed.$foo) set_data(t, ctx.$foo); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(h1); - } + if (detaching) detach(h1); } }; } function instance($$self, $$props, $$invalidate) { let $foo; - - const foo = writable(0); component_subscribe($$self, foo, $$value => $$invalidate('$foo', $foo = $$value)); - + const foo = writable(0); + component_subscribe($$self, foo, $$value => $$invalidate("$foo", $foo = $$value)); return { foo, $foo }; } diff --git a/test/js/samples/component-store-file-invalidate/expected.js b/test/js/samples/component-store-file-invalidate/expected.js index 286701ada2..8082d6e7ee 100644 --- a/test/js/samples/component-store-file-invalidate/expected.js +++ b/test/js/samples/component-store-file-invalidate/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, component_subscribe, @@ -7,6 +6,7 @@ import { safe_not_equal, set_store_value } from "svelte/internal"; + import { count } from "./store.js"; function create_fragment(ctx) { @@ -22,8 +22,7 @@ function create_fragment(ctx) { function instance($$self, $$props, $$invalidate) { let $count; - - component_subscribe($$self, count, $$value => $$invalidate('$count', $count = $$value)); + component_subscribe($$self, count, $$value => $$invalidate("$count", $count = $$value)); function increment() { set_store_value(count, $count++, $count); diff --git a/test/js/samples/component-store-reassign-invalidate/expected.js b/test/js/samples/component-store-reassign-invalidate/expected.js index 31215da1f9..fc3cc65366 100644 --- a/test/js/samples/component-store-reassign-invalidate/expected.js +++ b/test/js/samples/component-store-reassign-invalidate/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, append, @@ -14,10 +13,15 @@ import { subscribe, text } from "svelte/internal"; + import { writable } from "svelte/store"; function create_fragment(ctx) { - var h1, t0, t1, button, dispose; + let h1; + let t0; + let t1; + let button; + let dispose; return { c() { @@ -28,44 +32,35 @@ function create_fragment(ctx) { button.textContent = "reset"; dispose = listen(button, "click", ctx.click_handler); }, - m(target, anchor) { insert(target, h1, anchor); append(h1, t0); insert(target, t1, anchor); insert(target, button, anchor); }, - p(changed, ctx) { - if (changed.$foo) { - set_data(t0, ctx.$foo); - } + if (changed.$foo) set_data(t0, ctx.$foo); }, - i: noop, o: noop, - d(detaching) { - if (detaching) { - detach(h1); - detach(t1); - detach(button); - } - + if (detaching) detach(h1); + if (detaching) detach(t1); + if (detaching) detach(button); dispose(); } }; } function instance($$self, $$props, $$invalidate) { - let $foo, $$unsubscribe_foo = noop, $$subscribe_foo = () => ($$unsubscribe_foo(), $$unsubscribe_foo = subscribe(foo, $$value => $$invalidate('$foo', $foo = $$value)), foo); + let $foo, + $$unsubscribe_foo = noop, + $$subscribe_foo = () => ($$unsubscribe_foo(), $$unsubscribe_foo = subscribe(foo, $$value => $$invalidate("$foo", $foo = $$value)), foo); $$self.$$.on_destroy.push(() => $$unsubscribe_foo()); - - let foo = writable(0); $$subscribe_foo(); - - const click_handler = () => $$subscribe_foo($$invalidate('foo', foo = writable(0))); - + let foo = writable(0); + $$subscribe_foo(); + const click_handler = () => $$subscribe_foo($$invalidate("foo", foo = writable(0))); return { foo, $foo, click_handler }; } diff --git a/test/js/samples/window-binding-online/expected.js b/test/js/samples/window-binding-online/expected.js index 96271a1faf..30087ca615 100644 --- a/test/js/samples/window-binding-online/expected.js +++ b/test/js/samples/window-binding-online/expected.js @@ -1,4 +1,3 @@ -/* generated by Svelte vX.Y.Z */ import { SvelteComponent, add_render_callback, @@ -10,8 +9,7 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var dispose; - + let dispose; add_render_callback(ctx.onlinestatuschanged); return { @@ -21,12 +19,10 @@ function create_fragment(ctx) { listen(window, "offline", ctx.onlinestatuschanged) ]; }, - m: noop, p: noop, i: noop, o: noop, - d(detaching) { run_all(dispose); } @@ -37,7 +33,7 @@ function instance($$self, $$props, $$invalidate) { let online; function onlinestatuschanged() { - $$invalidate('online', online = navigator.onLine); + $$invalidate("online", online = navigator.onLine); } return { online, onlinestatuschanged };