diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 30a06ca50b..09edd49098 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -1164,9 +1164,11 @@ export default class Component { const variable = this.var_lookup.get(name); if (!variable) return name; - if (variable && variable.hoistable) return name; this.add_reference(name); // TODO we can probably remove most other occurrences of this + + if (variable.hoistable) return name; + return `ctx.${name}`; } diff --git a/test/vars/samples/actions/_config.js b/test/vars/samples/actions/_config.js index 2cda8889c9..6b6f8696e7 100644 --- a/test/vars/samples/actions/_config.js +++ b/test/vars/samples/actions/_config.js @@ -1,6 +1,16 @@ export default { test(assert, vars) { assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'hoistable_foo', + reassigned: false, + referenced: true, + writable: false + }, { export_name: null, injected: false, diff --git a/test/vars/samples/actions/input.svelte b/test/vars/samples/actions/input.svelte index fe614c760c..8ba8f0f21f 100644 --- a/test/vars/samples/actions/input.svelte +++ b/test/vars/samples/actions/input.svelte @@ -1,5 +1,7 @@ +
diff --git a/test/vars/samples/animations/_config.js b/test/vars/samples/animations/_config.js index 2cda8889c9..6b6f8696e7 100644 --- a/test/vars/samples/animations/_config.js +++ b/test/vars/samples/animations/_config.js @@ -1,6 +1,16 @@ export default { test(assert, vars) { assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'hoistable_foo', + reassigned: false, + referenced: true, + writable: false + }, { export_name: null, injected: false, diff --git a/test/vars/samples/animations/input.svelte b/test/vars/samples/animations/input.svelte index 7843ab928d..02967d0fa8 100644 --- a/test/vars/samples/animations/input.svelte +++ b/test/vars/samples/animations/input.svelte @@ -1,7 +1,11 @@ +{#each [] as x (x)} + +{/each} {#each [] as x (x)} {/each} diff --git a/test/vars/samples/transitions/_config.js b/test/vars/samples/transitions/_config.js index e42faf7d19..b2522a1b56 100644 --- a/test/vars/samples/transitions/_config.js +++ b/test/vars/samples/transitions/_config.js @@ -1,6 +1,36 @@ export default { test(assert, vars) { assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'hoistable_foo', + reassigned: false, + referenced: true, + writable: false + }, + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'hoistable_bar', + reassigned: false, + referenced: true, + writable: false + }, + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'hoistable_baz', + reassigned: false, + referenced: true, + writable: false + }, { export_name: null, injected: false, diff --git a/test/vars/samples/transitions/input.svelte b/test/vars/samples/transitions/input.svelte index 1dac9bc5ec..0db2b5289e 100644 --- a/test/vars/samples/transitions/input.svelte +++ b/test/vars/samples/transitions/input.svelte @@ -1,9 +1,13 @@ + + +