From ef944b571315edc785c6e43f55c187269fe4fffa Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Fri, 28 Dec 2018 21:45:03 -0500 Subject: [PATCH] prevent parent component modifying child component state - fixes #1924 --- src/compile/render-dom/index.ts | 5 ++-- src/internal/Component.js | 23 ++----------------- .../action-custom-event-handler/expected.js | 4 ++-- test/js/samples/bind-width-height/expected.js | 4 ++-- .../expected.js | 4 ++-- .../samples/computed-collapsed-if/expected.js | 4 ++-- test/js/samples/debug-empty/expected.js | 4 ++-- .../debug-foo-bar-baz-things/expected.js | 10 ++++---- test/js/samples/debug-foo/expected.js | 6 ++--- .../samples/deconflict-builtins/expected.js | 4 ++-- .../js/samples/deconflict-globals/expected.js | 4 ++-- .../expected.js | 2 +- test/js/samples/do-use-dataset/expected.js | 4 ++-- .../dont-use-dataset-in-legacy/expected.js | 4 ++-- .../dont-use-dataset-in-svg/expected.js | 4 ++-- .../each-block-changed-check/expected.js | 10 ++++---- .../each-block-keyed-animated/expected.js | 4 ++-- test/js/samples/each-block-keyed/expected.js | 4 ++-- .../js/samples/if-block-no-update/expected.js | 4 ++-- test/js/samples/if-block-simple/expected.js | 4 ++-- .../expected.js | 8 +++---- .../inline-style-optimized-url/expected.js | 4 ++-- .../inline-style-optimized/expected.js | 4 ++-- .../inline-style-unoptimized/expected.js | 8 +++---- test/js/samples/input-files/expected.js | 2 +- test/js/samples/input-range/expected.js | 2 +- .../input-without-blowback-guard/expected.js | 2 +- test/js/samples/media-bindings/expected.js | 14 +++++------ .../samples/select-dynamic-value/expected.js | 4 ++-- test/js/samples/title/expected.js | 4 ++-- .../use-elements-as-anchors/expected.js | 12 +++++----- .../samples/window-binding-scroll/expected.js | 2 +- test/runtime/samples/internal-state/Foo.html | 5 ++++ .../runtime/samples/internal-state/_config.js | 18 +++++++++++++++ test/runtime/samples/internal-state/main.html | 9 ++++++++ 35 files changed, 111 insertions(+), 99 deletions(-) create mode 100644 test/runtime/samples/internal-state/Foo.html create mode 100644 test/runtime/samples/internal-state/_config.js create mode 100644 test/runtime/samples/internal-state/main.html diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 64a219ea6a..430ffb5e6a 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -80,7 +80,7 @@ export default function dom( $$invalidate('${component.meta.props_object}', ${component.meta.props_object}); `} ${props.map(prop => - `if ('${prop.as}' in $$props) ${prop.name} = $$props.${prop.as};`)} + `if ('${prop.as}' in $$props) $$invalidate('${prop.name}', ${prop.name} = $$props.${prop.as});`)} } ` : null; @@ -231,8 +231,7 @@ export default function dom( } const args = ['$$self']; - if (component.props.length > 0 || component.has_reactive_assignments) args.push('$$props'); - if (component.has_reactive_assignments) args.push('$$invalidate'); + if (component.props.length > 0 || component.has_reactive_assignments) args.push('$$props', '$$invalidate'); builder.addBlock(deindent` function create_fragment(${component.alias('component')}, ctx) { diff --git a/src/internal/Component.js b/src/internal/Component.js index 5ee644c714..7891209db4 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.js @@ -152,16 +152,7 @@ if (typeof HTMLElement !== 'undefined') { } $set(values) { - if (this.$$) { - const { ctx, set, not_equal } = this.$$; - set(values); - for (const key in values) { - if (not_equal(ctx[key], values[key])) { - ctx[key] = values[key]; - make_dirty(this, key); - } - } - } + this.$$.set(values); } } } @@ -183,17 +174,7 @@ export class SvelteComponent { } $set(values) { - if (this.$$) { - const { ctx, set, not_equal } = this.$$; - set(values); - - for (const key in values) { - if (not_equal(ctx[key], values[key])) { - ctx[key] = values[key]; - make_dirty(this, key); - } - } - } + this.$$.set(values); } } diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index acbf370e81..77df71460d 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -43,7 +43,7 @@ function foo(node, callback) { // code goes here } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { bar } = $$props; function foo_function() { @@ -51,7 +51,7 @@ function instance($$self, $$props) { } $$self.$$.set = $$props => { - if ('bar' in $$props) bar = $$props.bar; + if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); }; return { bar, foo_function }; diff --git a/test/js/samples/bind-width-height/expected.js b/test/js/samples/bind-width-height/expected.js index d1396fe895..d8484b2be4 100644 --- a/test/js/samples/bind-width-height/expected.js +++ b/test/js/samples/bind-width-height/expected.js @@ -47,8 +47,8 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('w' in $$props) w = $$props.w; - if ('h' in $$props) h = $$props.h; + if ('w' in $$props) $$invalidate('w', w = $$props.w); + if ('h' in $$props) $$invalidate('h', h = $$props.h); }; return { w, h, div_resize_handler }; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 4e086edb68..a070ae7639 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -45,11 +45,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { foo = 42 } = $$props; $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 22e3fbcf31..35dd19fe17 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -14,7 +14,7 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { x } = $$props; function a() { @@ -26,7 +26,7 @@ function instance($$self, $$props) { } $$self.$$.set = $$props => { - if ('x' in $$props) x = $$props.x; + if ('x' in $$props) $$invalidate('x', x = $$props.x); }; return { x, a, b }; diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 9d7d110ca3..eadc8e26b2 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -54,11 +54,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { name } = $$props; $$self.$$.set = $$props => { - if ('name' in $$props) name = $$props.name; + if ('name' in $$props) $$invalidate('name', name = $$props.name); }; return { name }; diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 3a1d6265e3..e77d899067 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -139,14 +139,14 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { things, foo, bar, baz } = $$props; $$self.$$.set = $$props => { - if ('things' in $$props) things = $$props.things; - if ('foo' in $$props) foo = $$props.foo; - if ('bar' in $$props) bar = $$props.bar; - if ('baz' in $$props) baz = $$props.baz; + if ('things' in $$props) $$invalidate('things', things = $$props.things); + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); + if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); + if ('baz' in $$props) $$invalidate('baz', baz = $$props.baz); }; return { things, foo, bar, baz }; diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 92ca5ab9e1..29e1dddf9d 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -139,12 +139,12 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { things, foo } = $$props; $$self.$$.set = $$props => { - if ('things' in $$props) things = $$props.things; - if ('foo' in $$props) foo = $$props.foo; + if ('things' in $$props) $$invalidate('things', things = $$props.things); + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { things, foo }; diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 613bdb712b..b034a1ff88 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -105,11 +105,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { createElement } = $$props; $$self.$$.set = $$props => { - if ('createElement' in $$props) createElement = $$props.createElement; + if ('createElement' in $$props) $$invalidate('createElement', createElement = $$props.createElement); }; return { createElement }; diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index aab54e874e..7e6cc01ed1 100644 --- a/test/js/samples/deconflict-globals/expected.js +++ b/test/js/samples/deconflict-globals/expected.js @@ -15,7 +15,7 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { foo = 'bar' } = $$props; onMount(() => { @@ -23,7 +23,7 @@ function instance($$self, $$props) { }); $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 95e85df1c1..3739437cbf 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -58,7 +58,7 @@ function instance($$self, $$props, $$invalidate) { let bar; $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; $$self.$$.update = ($$dirty = { foo: 1 }) => { diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index 47249c25ee..cbbb5f72e1 100644 --- a/test/js/samples/do-use-dataset/expected.js +++ b/test/js/samples/do-use-dataset/expected.js @@ -43,11 +43,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { bar } = $$props; $$self.$$.set = $$props => { - if ('bar' in $$props) bar = $$props.bar; + if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); }; return { bar }; diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected.js b/test/js/samples/dont-use-dataset-in-legacy/expected.js index d1ef2aeb78..f8349e8adc 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected.js @@ -43,11 +43,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { bar } = $$props; $$self.$$.set = $$props => { - if ('bar' in $$props) bar = $$props.bar; + if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); }; return { bar }; diff --git a/test/js/samples/dont-use-dataset-in-svg/expected.js b/test/js/samples/dont-use-dataset-in-svg/expected.js index de9f6e587d..6f72cd2e06 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected.js @@ -41,11 +41,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { bar } = $$props; $$self.$$.set = $$props => { - if ('bar' in $$props) bar = $$props.bar; + if ('bar' in $$props) $$invalidate('bar', bar = $$props.bar); }; return { bar }; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 42d4afea00..e124ab686e 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -145,14 +145,14 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { comments, elapsed, time, foo } = $$props; $$self.$$.set = $$props => { - if ('comments' in $$props) comments = $$props.comments; - if ('elapsed' in $$props) elapsed = $$props.elapsed; - if ('time' in $$props) time = $$props.time; - if ('foo' in $$props) foo = $$props.foo; + if ('comments' in $$props) $$invalidate('comments', comments = $$props.comments); + if ('elapsed' in $$props) $$invalidate('elapsed', elapsed = $$props.elapsed); + if ('time' in $$props) $$invalidate('time', time = $$props.time); + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { comments, elapsed, time, foo }; diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 18227c1cee..5db84eeac1 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -120,11 +120,11 @@ function foo(node, animation, params) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { things } = $$props; $$self.$$.set = $$props => { - if ('things' in $$props) things = $$props.things; + if ('things' in $$props) $$invalidate('things', things = $$props.things); }; return { things }; diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index 77becc6b94..e074314d89 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -90,11 +90,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { things } = $$props; $$self.$$.set = $$props => { - if ('things' in $$props) things = $$props.things; + if ('things' in $$props) $$invalidate('things', things = $$props.things); }; return { things }; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index f6b460ab87..59ac917c87 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -93,11 +93,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { foo } = $$props; $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index a7c2f6b460..0996ca7018 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -69,11 +69,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { foo } = $$props; $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { foo }; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 92804c1983..92be082bd0 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -41,13 +41,13 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { color, x, y } = $$props; $$self.$$.set = $$props => { - if ('color' in $$props) color = $$props.color; - if ('x' in $$props) x = $$props.x; - if ('y' in $$props) y = $$props.y; + if ('color' in $$props) $$invalidate('color', color = $$props.color); + if ('x' in $$props) $$invalidate('x', x = $$props.x); + if ('y' in $$props) $$invalidate('y', y = $$props.y); }; return { color, x, y }; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 992d072638..7acc501554 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -36,11 +36,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { data } = $$props; $$self.$$.set = $$props => { - if ('data' in $$props) data = $$props.data; + if ('data' in $$props) $$invalidate('data', data = $$props.data); }; return { data }; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index fcf7a926fc..a1c41969ea 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -36,11 +36,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { color } = $$props; $$self.$$.set = $$props => { - if ('color' in $$props) color = $$props.color; + if ('color' in $$props) $$invalidate('color', color = $$props.color); }; return { color }; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index b28fef6680..c2bd693cef 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -47,13 +47,13 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { style, key, value } = $$props; $$self.$$.set = $$props => { - if ('style' in $$props) style = $$props.style; - if ('key' in $$props) key = $$props.key; - if ('value' in $$props) value = $$props.value; + if ('style' in $$props) $$invalidate('style', style = $$props.style); + if ('key' in $$props) $$invalidate('key', key = $$props.key); + if ('value' in $$props) $$invalidate('value', value = $$props.value); }; return { style, key, value }; diff --git a/test/js/samples/input-files/expected.js b/test/js/samples/input-files/expected.js index bf8c9fac76..1aac0c4416 100644 --- a/test/js/samples/input-files/expected.js +++ b/test/js/samples/input-files/expected.js @@ -50,7 +50,7 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('files' in $$props) files = $$props.files; + if ('files' in $$props) $$invalidate('files', files = $$props.files); }; return { files, input_input_handler }; diff --git a/test/js/samples/input-range/expected.js b/test/js/samples/input-range/expected.js index 18c54e508e..9a95cb9c3d 100644 --- a/test/js/samples/input-range/expected.js +++ b/test/js/samples/input-range/expected.js @@ -53,7 +53,7 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('value' in $$props) value = $$props.value; + if ('value' in $$props) $$invalidate('value', value = $$props.value); }; return { value, input_change_input_handler }; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 2c11490964..5b1d063d10 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -49,7 +49,7 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('foo' in $$props) foo = $$props.foo; + if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; return { foo, input_change_handler }; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 9815abc548..d18679b5ee 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -94,13 +94,13 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('buffered' in $$props) buffered = $$props.buffered; - if ('seekable' in $$props) seekable = $$props.seekable; - if ('played' in $$props) played = $$props.played; - if ('currentTime' in $$props) currentTime = $$props.currentTime; - if ('duration' in $$props) duration = $$props.duration; - if ('paused' in $$props) paused = $$props.paused; - if ('volume' in $$props) volume = $$props.volume; + if ('buffered' in $$props) $$invalidate('buffered', buffered = $$props.buffered); + if ('seekable' in $$props) $$invalidate('seekable', seekable = $$props.seekable); + if ('played' in $$props) $$invalidate('played', played = $$props.played); + if ('currentTime' in $$props) $$invalidate('currentTime', currentTime = $$props.currentTime); + if ('duration' in $$props) $$invalidate('duration', duration = $$props.duration); + if ('paused' in $$props) $$invalidate('paused', paused = $$props.paused); + if ('volume' in $$props) $$invalidate('volume', volume = $$props.volume); }; return { diff --git a/test/js/samples/select-dynamic-value/expected.js b/test/js/samples/select-dynamic-value/expected.js index c84f284223..82e1c16fb0 100644 --- a/test/js/samples/select-dynamic-value/expected.js +++ b/test/js/samples/select-dynamic-value/expected.js @@ -63,11 +63,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { current } = $$props; $$self.$$.set = $$props => { - if ('current' in $$props) current = $$props.current; + if ('current' in $$props) $$invalidate('current', current = $$props.current); }; return { current }; diff --git a/test/js/samples/title/expected.js b/test/js/samples/title/expected.js index 107bbb9a40..8b93886347 100644 --- a/test/js/samples/title/expected.js +++ b/test/js/samples/title/expected.js @@ -22,11 +22,11 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { custom } = $$props; $$self.$$.set = $$props => { - if ('custom' in $$props) custom = $$props.custom; + if ('custom' in $$props) $$invalidate('custom', custom = $$props.custom); }; return { custom }; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 742635f9c2..2730ab2d07 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -249,15 +249,15 @@ function create_fragment(component, ctx) { }; } -function instance($$self, $$props) { +function instance($$self, $$props, $$invalidate) { let { a, b, c, d, e } = $$props; $$self.$$.set = $$props => { - if ('a' in $$props) a = $$props.a; - if ('b' in $$props) b = $$props.b; - if ('c' in $$props) c = $$props.c; - if ('d' in $$props) d = $$props.d; - if ('e' in $$props) e = $$props.e; + if ('a' in $$props) $$invalidate('a', a = $$props.a); + if ('b' in $$props) $$invalidate('b', b = $$props.b); + if ('c' in $$props) $$invalidate('c', c = $$props.c); + if ('d' in $$props) $$invalidate('d', d = $$props.d); + if ('e' in $$props) $$invalidate('e', e = $$props.e); }; return { a, b, c, d, e }; diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index 0931e5a971..f5a3044ffb 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -64,7 +64,7 @@ function instance($$self, $$props, $$invalidate) { } $$self.$$.set = $$props => { - if ('y' in $$props) y = $$props.y; + if ('y' in $$props) $$invalidate('y', y = $$props.y); }; return { y, onwindowscroll }; diff --git a/test/runtime/samples/internal-state/Foo.html b/test/runtime/samples/internal-state/Foo.html new file mode 100644 index 0000000000..300a81fca4 --- /dev/null +++ b/test/runtime/samples/internal-state/Foo.html @@ -0,0 +1,5 @@ + + +

internal: {internal}

\ No newline at end of file diff --git a/test/runtime/samples/internal-state/_config.js b/test/runtime/samples/internal-state/_config.js new file mode 100644 index 0000000000..09ea61a8eb --- /dev/null +++ b/test/runtime/samples/internal-state/_config.js @@ -0,0 +1,18 @@ +export default { + html: ` +

internal: 1

+ + `, + + async test({ assert, target, window }) { + const button = target.querySelector('button'); + const click = new window.MouseEvent('click'); + + await button.dispatchEvent(click); + + assert.htmlEqual(target.innerHTML, ` +

internal: 1

+ + `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/internal-state/main.html b/test/runtime/samples/internal-state/main.html new file mode 100644 index 0000000000..81151cea80 --- /dev/null +++ b/test/runtime/samples/internal-state/main.html @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file