Skip to content

Commit

Permalink
fix: "foreign" namespace elements should still allow binding 'this' (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsauravsahu authored Jan 29, 2021
1 parent eeeeb49 commit 87417e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,12 @@ export default class Element extends Node {

validate_bindings_foreign() {
this.bindings.forEach(binding => {
this.component.error(binding, {
code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this`
});
if (binding.name !== 'this') {
this.component.error(binding, {
code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding. Foreign elements only support bind:this`
});
}
});
}

Expand Down
13 changes: 13 additions & 0 deletions test/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,17 @@ describe('validate', () => {
});
}, /Invalid namespace 'foriegn' \(did you mean 'foreign'\?\)/);
});

it('does not throw error if \'this\' is bound for foreign element', () => {
assert.doesNotThrow(() => {
svelte.compile(`
<script>
let whatever;
</script>
<div bind:this={whatever} />`, {
name: 'test',
namespace: 'foreign'
});
});
});
});

0 comments on commit 87417e5

Please sign in to comment.