Skip to content

Commit 9754204

Browse files
authored
fix: silence assignment warning on more function bindings (#15644)
* fix: silence assignment warning on more function bindings fixes #15550 * Update packages/svelte/tests/html_equal.js
1 parent 046145f commit 9754204

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

.changeset/rare-falcons-admire.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: silence assignment warning on more function bindings

packages/svelte/src/compiler/phases/3-transform/client/visitors/AssignmentExpression.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ function build_assignment(operator, left, right, context) {
165165
path.at(-1) === 'SvelteComponent' ||
166166
(path.at(-1) === 'ArrowFunctionExpression' &&
167167
path.at(-2) === 'SequenceExpression' &&
168-
(path.at(-3) === 'Component' || path.at(-3) === 'SvelteComponent'))
168+
(path.at(-3) === 'Component' ||
169+
path.at(-3) === 'SvelteComponent' ||
170+
path.at(-3) === 'BindDirective'))
169171
) {
170172
should_transform = false;
171173
}

packages/svelte/tests/html_equal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function normalize_html(
8686
clean_children(node);
8787
return node.innerHTML;
8888
} catch (err) {
89-
throw new Error(`Failed to normalize HTML:\n${html}`);
89+
throw new Error(`Failed to normalize HTML:\n${html}\nCause: ${err}`);
9090
}
9191
}
9292

packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/_config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default test({
66
dev: true
77
},
88

9-
html: `<button>items: null</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`,
9+
html: `<button>items: null</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2"><input>`,
1010

1111
test({ assert, target, warnings }) {
1212
const btn = target.querySelector('button');
@@ -15,13 +15,13 @@ export default test({
1515
flushSync(() => btn.click());
1616
assert.htmlEqual(
1717
target.innerHTML,
18-
`<button>items: []</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`
18+
`<button>items: []</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2"><input>`
1919
);
2020

2121
flushSync(() => btn.click());
2222
assert.htmlEqual(
2323
target.innerHTML,
24-
`<button>items: [0]</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2">`
24+
`<button>items: [0]</button> <div>x</div> <input type="checkbox" value="1"><input type="checkbox" value="2"><input>`
2525
);
2626

2727
const input = target.querySelector('input');
@@ -30,7 +30,7 @@ export default test({
3030
flushSync(() => input.dispatchEvent(new Event('change', { bubbles: true })));
3131

3232
assert.deepEqual(warnings, [
33-
'Assignment to `items` property (main.svelte:8:24) will evaluate to the right-hand side, not the value of `items` following the assignment. This may result in unexpected behaviour.'
33+
'Assignment to `items` property (main.svelte:9:24) will evaluate to the right-hand side, not the value of `items` following the assignment. This may result in unexpected behaviour.'
3434
]);
3535
}
3636
});

packages/svelte/tests/runtime-runes/samples/proxy-coercive-assignment-warning/main.svelte

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
let entries = $state([]);
55
let object = $state({ items: null, group: [] });
6+
let elementFunBind = $state();
67
</script>
78

89
<button onclick={() => (object.items ??= []).push(object.items.length)}>
@@ -13,6 +14,12 @@
1314
<div bind:this={entries[0]}>x</div>
1415
<input type="checkbox" value=1 bind:group={object.group}>
1516
<input type="checkbox" value=2 bind:group={object.group}>
17+
1618
<Test bind:this={entries[1]}></Test>
1719
<Test bind:this={() => entries[2], (v) => (entries[2] = v)}></Test>
1820
<Test bind:x={entries[3]}></Test>
21+
22+
{#snippet funBind(context)}
23+
<input bind:this={() => {}, (e) => (context.element = e)} />
24+
{/snippet}
25+
{@render funBind({ set element(e) { elementFunBind = e } })}

0 commit comments

Comments
 (0)