From 0786d2858decb4f71cd98fc2b2ad28b0de7f00ac Mon Sep 17 00:00:00 2001 From: rixo Date: Wed, 26 Feb 2020 23:05:33 +0100 Subject: [PATCH 1/3] 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 17e5eaf750b3..71e868164602 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 127addf1d117..4eccaae7cb79 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; From dc3e9c4bedb58342737c2ca792ef341a2278275d Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 26 Feb 2020 17:06:53 -0500 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c24fa066df..ef5ba2307fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Exclude global variables from `$capture_state` ([#4463](https://github.com/sveltejs/svelte/issues/4463)) + ## 3.19.1 * Do not treat modifications to `$$props` as updates to a store called `$props` ([#4368](https://github.com/sveltejs/svelte/issues/4368)) From 7831766fa0da53aa7f5d188ffb9e15efd0106d66 Mon Sep 17 00:00:00 2001 From: Antony Jones Date: Thu, 27 Feb 2020 11:40:42 +0000 Subject: [PATCH 3/3] site: turn fancybutton into custombutton (#4476) --- .../05-dom-event-forwarding/App.svelte | 4 ++-- .../CustomButton.svelte | 22 ++++++++++++++++++ .../FancyButton.svelte | 15 ------------ .../06-dom-event-forwarding/app-a/App.svelte | 4 ++-- .../app-a/CustomButton.svelte | 22 ++++++++++++++++++ .../app-a/FancyButton.svelte | 15 ------------ .../06-dom-event-forwarding/app-b/App.svelte | 4 ++-- .../app-b/CustomButton.svelte | 22 ++++++++++++++++++ .../app-b/FancyButton.svelte | 15 ------------ .../05-events/06-dom-event-forwarding/text.md | 2 +- .../thumbnails/dom-event-forwarding.jpg | Bin 4128 -> 2409 bytes .../samples/extended-builtin/_config.js | 8 +++---- .../samples/extended-builtin/custom-button.js | 2 ++ .../samples/extended-builtin/fancy-button.js | 2 -- .../samples/extended-builtin/main.svelte | 4 ++-- .../samples/extended-builtin/test.js | 2 +- 16 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 site/content/examples/04-events/05-dom-event-forwarding/CustomButton.svelte delete mode 100644 site/content/examples/04-events/05-dom-event-forwarding/FancyButton.svelte create mode 100644 site/content/tutorial/05-events/06-dom-event-forwarding/app-a/CustomButton.svelte delete mode 100644 site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte create mode 100644 site/content/tutorial/05-events/06-dom-event-forwarding/app-b/CustomButton.svelte delete mode 100644 site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte create mode 100644 test/custom-elements/samples/extended-builtin/custom-button.js delete mode 100644 test/custom-elements/samples/extended-builtin/fancy-button.js diff --git a/site/content/examples/04-events/05-dom-event-forwarding/App.svelte b/site/content/examples/04-events/05-dom-event-forwarding/App.svelte index 1429cae207d8..e75c78106ac3 100644 --- a/site/content/examples/04-events/05-dom-event-forwarding/App.svelte +++ b/site/content/examples/04-events/05-dom-event-forwarding/App.svelte @@ -1,9 +1,9 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/site/content/examples/04-events/05-dom-event-forwarding/CustomButton.svelte b/site/content/examples/04-events/05-dom-event-forwarding/CustomButton.svelte new file mode 100644 index 000000000000..f521c1f4713a --- /dev/null +++ b/site/content/examples/04-events/05-dom-event-forwarding/CustomButton.svelte @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/site/content/examples/04-events/05-dom-event-forwarding/FancyButton.svelte b/site/content/examples/04-events/05-dom-event-forwarding/FancyButton.svelte deleted file mode 100644 index 68dcc68636a9..000000000000 --- a/site/content/examples/04-events/05-dom-event-forwarding/FancyButton.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - - \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte index 1429cae207d8..e75c78106ac3 100644 --- a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte @@ -1,9 +1,9 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/CustomButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/CustomButton.svelte new file mode 100644 index 000000000000..0955930b5d59 --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/CustomButton.svelte @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte deleted file mode 100644 index b75f19a1f25c..000000000000 --- a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - - \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte index 1429cae207d8..e75c78106ac3 100644 --- a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte @@ -1,9 +1,9 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/CustomButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/CustomButton.svelte new file mode 100644 index 000000000000..f521c1f4713a --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/CustomButton.svelte @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte deleted file mode 100644 index 68dcc68636a9..000000000000 --- a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - - \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/text.md b/site/content/tutorial/05-events/06-dom-event-forwarding/text.md index 0959e1d98b17..be9ae77f8912 100644 --- a/site/content/tutorial/05-events/06-dom-event-forwarding/text.md +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/text.md @@ -4,7 +4,7 @@ title: DOM event forwarding Event forwarding works for DOM events too. -We want to get notified of clicks on our `` — to do that, we just need to forward `click` events on the ` \ No newline at end of file + \ No newline at end of file diff --git a/test/custom-elements/samples/extended-builtin/test.js b/test/custom-elements/samples/extended-builtin/test.js index d676fd137b53..3886ae11498f 100644 --- a/test/custom-elements/samples/extended-builtin/test.js +++ b/test/custom-elements/samples/extended-builtin/test.js @@ -11,5 +11,5 @@ export default function (target) { const el = target.querySelector('custom-element'); const button = el.shadowRoot.querySelector('button'); - assert.ok(button instanceof customElements.get('fancy-button')); + assert.ok(button instanceof customElements.get('custom-button')); } \ No newline at end of file