From 48906d1b7c139c4abc37086b749b39972a8bb542 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 3 Feb 2020 12:12:01 -0500 Subject: [PATCH] fix binding to module-level variables (#4352) --- CHANGELOG.md | 1 + src/compiler/compile/render_dom/Renderer.ts | 13 ++++++++----- test/runtime/samples/module-context-bind/_config.js | 4 ++++ .../runtime/samples/module-context-bind/main.svelte | 11 +++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/runtime/samples/module-context-bind/_config.js create mode 100644 test/runtime/samples/module-context-bind/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e23686eaeb..359ab910f5f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/compiler/compile/render_dom/Renderer.ts b/src/compiler/compile/render_dom/Renderer.ts index 046a90b68400..8fa36a91209a 100644 --- a/src/compiler/compile/render_dom/Renderer.ts +++ b/src/compiler/compile/render_dom/Renderer.ts @@ -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; } diff --git a/test/runtime/samples/module-context-bind/_config.js b/test/runtime/samples/module-context-bind/_config.js new file mode 100644 index 000000000000..32bc9c4ce95d --- /dev/null +++ b/test/runtime/samples/module-context-bind/_config.js @@ -0,0 +1,4 @@ +export default { + skip_if_ssr: true, + html: '
object
' +}; diff --git a/test/runtime/samples/module-context-bind/main.svelte b/test/runtime/samples/module-context-bind/main.svelte new file mode 100644 index 000000000000..1580102bd8fe --- /dev/null +++ b/test/runtime/samples/module-context-bind/main.svelte @@ -0,0 +1,11 @@ + + + + +
{typeof bar}