diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
index 53838f90b8..5b08b795ce 100644
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -1040,6 +1040,8 @@ export default class Component {
walk(fn_declaration, {
enter(node, parent) {
+ if (!hoistable) return this.skip();
+
if (map.has(node)) {
scope = map.get(node);
}
@@ -1048,7 +1050,7 @@ export default class Component {
const { name } = flatten_reference(node);
const owner = scope.find_owner(name);
- if (node.type === 'Identifier' && injected_reactive_declaration_vars.has(name)) {
+ if (injected_reactive_declaration_vars.has(name)) {
hoistable = false;
} else if (name[0] === '$' && !owner) {
hoistable = false;
diff --git a/test/runtime/samples/reactive-value-function-hoist-b/_config.js b/test/runtime/samples/reactive-value-function-hoist-b/_config.js
new file mode 100644
index 0000000000..04c4fd3f11
--- /dev/null
+++ b/test/runtime/samples/reactive-value-function-hoist-b/_config.js
@@ -0,0 +1,15 @@
+export default {
+ html: `
+
+ `,
+
+ async test({ assert, target, window }) {
+ const event = new window.MouseEvent('click');
+ const button = target.querySelector('button');
+
+ await button.dispatchEvent(event);
+ assert.htmlEqual(target.innerHTML, `
+
+ `);
+ }
+};
diff --git a/test/runtime/samples/reactive-value-function-hoist-b/main.svelte b/test/runtime/samples/reactive-value-function-hoist-b/main.svelte
new file mode 100644
index 0000000000..2e9ee6eefe
--- /dev/null
+++ b/test/runtime/samples/reactive-value-function-hoist-b/main.svelte
@@ -0,0 +1,10 @@
+
+
+