From 60914b86fdffedd2f87434a0a3f280851fbfe2d6 Mon Sep 17 00:00:00 2001 From: Bryan Terce Date: Sun, 23 Jun 2019 05:34:36 -0700 Subject: [PATCH] Fix binding to values in a component when it uses `$$props` (#2725) --- src/compiler/compile/render-dom/index.ts | 2 +- .../samples/binding-using-props/TextInput.svelte | 6 ++++++ .../runtime/samples/binding-using-props/_config.js | 14 ++++++++++++++ .../samples/binding-using-props/main.svelte | 7 +++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/binding-using-props/TextInput.svelte create mode 100644 test/runtime/samples/binding-using-props/_config.js create mode 100644 test/runtime/samples/binding-using-props/main.svelte diff --git a/src/compiler/compile/render-dom/index.ts b/src/compiler/compile/render-dom/index.ts index 46aa705bfb..9a49bc0c35 100644 --- a/src/compiler/compile/render-dom/index.ts +++ b/src/compiler/compile/render-dom/index.ts @@ -80,7 +80,7 @@ export default function dom( ${$$props} => { ${uses_props && component.invalidate('$$props', `$$props = @assign(@assign({}, $$props), $$new_props)`)} ${writable_props.map(prop => - `if ('${prop.export_name}' in $$props) ${component.invalidate(prop.name, `${prop.name} = $$props.${prop.export_name}`)};` + `if ('${prop.export_name}' in ${$$props}) ${component.invalidate(prop.name, `${prop.name} = ${$$props}.${prop.export_name}`)};` )} ${component.slots.size > 0 && `if ('$$scope' in ${$$props}) ${component.invalidate('$$scope', `$$scope = ${$$props}.$$scope`)};`} diff --git a/test/runtime/samples/binding-using-props/TextInput.svelte b/test/runtime/samples/binding-using-props/TextInput.svelte new file mode 100644 index 0000000000..da9e7e4a0e --- /dev/null +++ b/test/runtime/samples/binding-using-props/TextInput.svelte @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/binding-using-props/_config.js b/test/runtime/samples/binding-using-props/_config.js new file mode 100644 index 0000000000..dcb34c4357 --- /dev/null +++ b/test/runtime/samples/binding-using-props/_config.js @@ -0,0 +1,14 @@ +export default { + async test({ assert, target, window }) { + const input = target.querySelector('input'); + + const event = new window.Event('input'); + input.value = 'changed'; + await input.dispatchEvent(event); + + assert.htmlEqual(target.innerHTML, ` + +

changed

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/binding-using-props/main.svelte b/test/runtime/samples/binding-using-props/main.svelte new file mode 100644 index 0000000000..543bd28d49 --- /dev/null +++ b/test/runtime/samples/binding-using-props/main.svelte @@ -0,0 +1,7 @@ + + + +

{actualValue}

\ No newline at end of file