Fix: each block binding with spread syntax

Fixes: https://github.com/sveltejs/svelte/issues/6860
pull/6883/head
raivaibhav 5 years ago
parent 990c21f7f3
commit 50f1ce2618

@ -344,7 +344,18 @@ function get_event_handler(
if (context) { if (context) {
const { object, property, store, snippet } = context; const { object, property, store, snippet } = context;
if (snippet.type === 'CallExpression' &&
lhs.type === 'MemberExpression' &&
snippet.callee.type === 'Identifier' &&
snippet.callee.name === '@object_without_properties' &&
snippet.arguments.length > 0 &&
snippet.arguments[0].type === 'MemberExpression') {
lhs.object = snippet.arguments[0];
} else {
lhs = replace_object(lhs, snippet); lhs = replace_object(lhs, snippet);
}
contextual_dependencies.add(object.name); contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name); contextual_dependencies.add(property.name);
contextual_dependencies.delete(name); contextual_dependencies.delete(name);

@ -0,0 +1,63 @@
export default {
props: {
arr: [{p: 'foo', val: 'val1', id: 'id-1'}, {p: 'bar', val: 'val2', id: 'id-2'}]
},
html: `
<input placeholder="foo">
{"val":"val1","id":"id-1"}
<br>
<input placeholder="bar">
{"val":"val2","id":"id-2"}
<br>
`,
ssrHtml: `
<input placeholder="foo" value="val1">
{"val":"val1","id":"id-1"}
<br>
<input placeholder="bar" value="val2">
{"val":"val2","id":"id-2"}
<br>
`,
async test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input');
inputs[0].value = 'val3';
await inputs[0].dispatchEvent(new window.Event('input'));
const { arr } = component;
assert.deepEqual(arr, [
{p: 'foo', val: 'val3', id: 'id-1'},
{p: 'bar', val: 'val2', id: 'id-2'}
]);
assert.htmlEqual(target.innerHTML, `
<input placeholder="foo">
{"val":"val3","id":"id-1"}
<br>
<input placeholder="bar">
{"val":"val2","id":"id-2"}
<br>
`);
inputs[1].value = 'val4';
await inputs[1].dispatchEvent(new window.Event('input'));
assert.deepEqual(arr, [
{p: 'foo', val: 'val3', id: 'id-1'},
{p: 'bar', val: 'val4', id: 'id-2'}
]);
assert.htmlEqual(target.innerHTML, `
<input placeholder="foo">
{"val":"val3","id":"id-1"}
<br>
<input placeholder="bar">
{"val":"val4","id":"id-2"}
<br>
`);
}
};

@ -0,0 +1,9 @@
<script>
export let arr;
</script>
{#each arr as {p, ...rest} (rest.id)}
<input bind:value={rest.val} placeholder={p}/>
{JSON.stringify(rest)}
<br>
{/each}
Loading…
Cancel
Save