Skip to content

Commit

Permalink
fix binding to module-level variables (sveltejs#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry authored and taylorzane committed Dec 17, 2020
1 parent bbae590 commit 48906d1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Fix binding to module-level variables ([#4086](https://github.com/sveltejs/svelte/issues/4086))
* Disallow attribute/prop names from matching two-way-bound names or `{shorthand}` attribute/prop names ([#4325](https://github.com/sveltejs/svelte/issues/4325))

## 3.18.1
Expand Down
13 changes: 8 additions & 5 deletions src/compiler/compile/render_dom/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ export default class Renderer {
}

if (
variable &&
!variable.referenced &&
!variable.is_reactive_dependency &&
!variable.export_name &&
!name.startsWith('$$')
variable && (
variable.module || (
!variable.referenced &&
!variable.is_reactive_dependency &&
!variable.export_name &&
!name.startsWith('$$')
)
)
) {
return value || name;
}
Expand Down
4 changes: 4 additions & 0 deletions test/runtime/samples/module-context-bind/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
skip_if_ssr: true,
html: '<div>object</div>'
};
11 changes: 11 additions & 0 deletions test/runtime/samples/module-context-bind/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script context='module'>
let foo;
</script>

<script>
import { onMount } from 'svelte';
let bar;
onMount(() => bar = foo);
</script>

<div bind:this={foo}>{typeof bar}</div>

0 comments on commit 48906d1

Please sign in to comment.