Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/lovely-rules-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: omit this bind this arg if we know it's not a signal
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,10 @@ function serialize_inline_component(node, component_name, context) {
if (bind_this !== null) {
const prev = fn;
const assignment = b.assignment('=', bind_this, b.id('$$value'));
const bind_this_id = bind_this;
const bind_this_id = /** @type {import('estree').Expression} */ (
// if expression is not an identifier, we know it can't be a signal
bind_this.type === 'Identifier' ? bind_this : undefined
);
fn = (node_id) =>
b.call(
'$.bind_this',
Expand Down Expand Up @@ -2621,18 +2624,17 @@ export const template_visitors = {
break;
}

case 'this': {
const expression = node.expression;
case 'this':
call_expr = b.call(
`$.bind_this`,
state.node,
setter,
expression.type === 'Identifier'
? expression
: /** @type {import('estree').Expression} */ (visit(expression))
/** @type {import('estree').Expression} */ (
// if expression is not an identifier, we know it can't be a signal
node.expression.type === 'Identifier' ? node.expression : undefined
)
);
break;
}
case 'textContent':
case 'innerHTML':
case 'innerText':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../../test';

export default test({
async test({ assert, target, component }) {
assert.equal(target.querySelector('img'), component.items[0].img);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let { items = [{ src: 'https://ds' }] } = $props();
</script>

{#each items as item, i}
<img
src={item.src}
bind:this={items[i].img}
alt="slider{i}"
/>
{/each}