From 0786d2858decb4f71cd98fc2b2ad28b0de7f00ac Mon Sep 17 00:00:00 2001 From: rixo Date: Wed, 26 Feb 2020 23:05:33 +0100 Subject: [PATCH] exclude global variables from $capture_state (#4475) --- src/compiler/compile/render_dom/index.ts | 2 +- test/js/samples/loop-protect/expected.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 17e5eaf750..71e8681646 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -167,7 +167,7 @@ export default function dom( `; } - const capturable_vars = component.vars.filter(v => !v.internal && !v.name.startsWith('$$')); + const capturable_vars = component.vars.filter(v => !v.internal && !v.global && !v.name.startsWith('$$')); if (capturable_vars.length > 0) { capture_state = x`() => ({ ${capturable_vars.map(prop => p`${prop.name}`)} })`; diff --git a/test/js/samples/loop-protect/expected.js b/test/js/samples/loop-protect/expected.js index 127addf1d1..4eccaae7cb 100644 --- a/test/js/samples/loop-protect/expected.js +++ b/test/js/samples/loop-protect/expected.js @@ -108,7 +108,7 @@ function instance($$self, $$props, $$invalidate) { }); } - $$self.$capture_state = () => ({ node, foo, console }); + $$self.$capture_state = () => ({ node, foo }); $$self.$inject_state = $$props => { if ("node" in $$props) $$invalidate(0, node = $$props.node); @@ -153,4 +153,4 @@ class Component extends SvelteComponentDev { } } -export default Component; \ No newline at end of file +export default Component;