Skip to content

Commit 87417e5

Browse files
authored
fix: "foreign" namespace elements should still allow binding 'this' (#5942)
1 parent eeeeb49 commit 87417e5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,12 @@ export default class Element extends Node {
600600

601601
validate_bindings_foreign() {
602602
this.bindings.forEach(binding => {
603-
this.component.error(binding, {
604-
code: 'invalid-binding',
605-
message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this`
606-
});
603+
if (binding.name !== 'this') {
604+
this.component.error(binding, {
605+
code: 'invalid-binding',
606+
message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this`
607+
});
608+
}
607609
});
608610
}
609611

test/validator/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,17 @@ describe('validate', () => {
119119
});
120120
}, /Invalid namespace 'foriegn' \(did you mean 'foreign'\?\)/);
121121
});
122+
123+
it('does not throw error if \'this\' is bound for foreign element', () => {
124+
assert.doesNotThrow(() => {
125+
svelte.compile(`
126+
<script>
127+
let whatever;
128+
</script>
129+
<div bind:this={whatever} />`, {
130+
name: 'test',
131+
namespace: 'foreign'
132+
});
133+
});
134+
});
122135
});

0 commit comments

Comments
 (0)