Skip to content

Commit be331d7

Browse files
committed
only do it for bind:this
1 parent 3cd9344 commit be331d7

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,14 @@ export const template_visitors = {
28302830

28312831
if (
28322832
expression.type === 'MemberExpression' &&
2833-
(!property || property.bidirectional) &&
2833+
(node.name !== 'this' ||
2834+
path.some(
2835+
({ type }) =>
2836+
type === 'IfBlock' ||
2837+
type === 'EachBlock' ||
2838+
type === 'AwaitBlock' ||
2839+
type === 'KeyBlock'
2840+
)) &&
28342841
context.state.options.dev &&
28352842
context.state.analysis.runes
28362843
) {

packages/svelte/tests/runtime-runes/samples/binding-property-static/_config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ export default test({
77

88
async test({ assert, warnings }) {
99
assert.deepEqual(warnings, [
10-
`\`bind:value={pojo.value}\` (main.svelte:50:7) is binding to a non-reactive property`,
11-
`\`bind:value={frozen.value}\` (main.svelte:51:7) is binding to a non-reactive property`,
12-
`\`bind:value={pojo.value}\` (main.svelte:52:7) is binding to a non-reactive property`,
13-
`\`bind:value={frozen.value}\` (main.svelte:53:7) is binding to a non-reactive property`
10+
'`bind:value={pojo.value}` (main.svelte:50:7) is binding to a non-reactive property',
11+
'`bind:value={frozen.value}` (main.svelte:51:7) is binding to a non-reactive property',
12+
'`bind:value={pojo.value}` (main.svelte:52:7) is binding to a non-reactive property',
13+
'`bind:value={frozen.value}` (main.svelte:53:7) is binding to a non-reactive property',
14+
'`bind:this={pojo.value}` (main.svelte:55:6) is binding to a non-reactive property'
1415
]);
1516
}
1617
});

packages/svelte/tests/runtime-runes/samples/binding-property-static/main.svelte

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,15 @@
5151
<input bind:value={frozen.value} />
5252
<Child bind:value={pojo.value} />
5353
<Child bind:value={frozen.value} />
54+
{#if value}
55+
<div bind:this={pojo.value}></div>
56+
{/if}
5457

55-
<!-- should not warn (because reactive value) -->
58+
<!-- should not warn -->
5659
<input bind:value={reactive.value} />
5760
<input bind:value={accessors.value} />
5861
<input bind:value={proxy.value} />
5962
<Child bind:value={reactive.value} />
6063
<Child bind:value={accessors.value} />
6164
<Child bind:value={proxy.value} />
62-
63-
<!-- should not warn (because one-way binding) -->
64-
<svelte:window
65-
bind:innerHeight={pojo.value}
66-
bind:innerWidth={pojo.value}
67-
bind:outerHeight={pojo.value}
68-
bind:outerWidth={pojo.value}
69-
bind:online={pojo.value}
70-
bind:devicePixelRatio={pojo.value}
71-
/>
72-
<svelte:document
73-
bind:activeElement={pojo.value}
74-
bind:fullscreenElement={pojo.value}
75-
bind:pointerLockElement={pojo.value}
76-
bind:visibilityState={pojo.value}
77-
/>
78-
<!-- can't test size bindings because it's not available in JSDom https://github.com/jsdom/jsdom/issues/3368 -->
7965
<div bind:this={pojo.value}></div>
80-
<video
81-
bind:duration={pojo.value}
82-
bind:buffered={pojo.value}
83-
bind:played={pojo.value}
84-
bind:seeking={pojo.value}
85-
bind:readyState={pojo.value}
86-
bind:videoHeight={pojo.value}
87-
bind:videoWidth={pojo.value}
88-
></video>
89-
<img bind:naturalHeight={pojo.value} bind:naturalWidth={pojo.value} />

0 commit comments

Comments
 (0)