Skip to content

Commit

Permalink
fix binding to module-level variables (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry authored Feb 3, 2020
1 parent 83d461f commit 3cbe38c
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 3cbe38c

Please sign in to comment.