Skip to content

Fix: each block binding with spread syntax #6883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/compiler/compile/render_dom/wrappers/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,18 @@ function get_event_handler(

if (context) {
const { object, property, store, snippet } = context;
lhs = replace_object(lhs, snippet);

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);
}

contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name);
contextual_dependencies.delete(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
`);
}
};
Original file line number Diff line number Diff line change
@@ -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}