diff --git a/src/compile/Component.ts b/src/compile/Component.ts
index ca3ed818cb..b07af70a64 100644
--- a/src/compile/Component.ts
+++ b/src/compile/Component.ts
@@ -750,18 +750,18 @@ export default class Component {
}
hoist_instance_declarations() {
- // we can safely hoist `const` declarations that are
+ // we can safely hoist variable declarations that are
// initialised to literals, and functions that don't
// reference instance variables other than other
// hoistable functions. TODO others?
- const { hoistable_names, hoistable_nodes, imported_declarations } = this;
+ const { hoistable_names, hoistable_nodes, imported_declarations, instance_scope: scope } = this;
const top_level_function_declarations = new Map();
this.instance_script.content.body.forEach(node => {
- if (node.kind === 'const') { // TODO or let or var, if never reassigned in
+
+{get_answer()}
\ No newline at end of file
diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js
index 9c1db56bd7..d8763aed51 100644
--- a/test/js/samples/if-block-no-update/expected.js
+++ b/test/js/samples/if-block-no-update/expected.js
@@ -83,7 +83,7 @@ function create_fragment($$, ctx) {
d(detach) {
if_block.d(detach);
-
+
if (detach) {
detachNode(if_block_anchor);
}
diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js
index 43c99c1d53..bd6528b11c 100644
--- a/test/js/samples/if-block-simple/expected.js
+++ b/test/js/samples/if-block-simple/expected.js
@@ -57,7 +57,7 @@ function create_fragment($$, ctx) {
d(detach) {
if (if_block) if_block.d(detach);
-
+
if (detach) {
detachNode(if_block_anchor);
}
diff --git a/test/js/samples/instrumentation-template-if-no-block/expected.js b/test/js/samples/instrumentation-template-if-no-block/expected.js
index d403b12fb1..dd1f72bc04 100644
--- a/test/js/samples/instrumentation-template-if-no-block/expected.js
+++ b/test/js/samples/instrumentation-template-if-no-block/expected.js
@@ -11,7 +11,7 @@ function create_fragment($$, ctx) {
text1 = createText("\n\n");
p = createElement("p");
text2 = createText("x: ");
- text3 = createText(ctx.x);
+ text3 = createText(x);
dispose = addListener(button, "click", ctx.click_handler);
},
@@ -25,7 +25,7 @@ function create_fragment($$, ctx) {
p(changed, ctx) {
if (changed.x) {
- setData(text3, ctx.x);
+ setData(text3, x);
}
},
@@ -44,14 +44,15 @@ function create_fragment($$, ctx) {
};
}
+let x = 0;
+
function instance($$self, $$props, $$invalidate) {
- let x = 0;
function click_handler() {
if (true) { x += 1; $$invalidate('x', x); }
}
- return { x, click_handler };
+ return { click_handler };
}
class SvelteComponent extends SvelteComponent_1 {
diff --git a/test/js/samples/non-mutable-reference/expected.js b/test/js/samples/non-mutable-reference/expected.js
index 7e83850226..b7f6dc60a9 100644
--- a/test/js/samples/non-mutable-reference/expected.js
+++ b/test/js/samples/non-mutable-reference/expected.js
@@ -1,5 +1,5 @@
/* generated by Svelte vX.Y.Z */
-import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, init, insert, noop, safe_not_equal } from "svelte/internal";
+import { SvelteComponent as SvelteComponent_1, append, createElement, createText, detachNode, identity, init, insert, noop, safe_not_equal } from "svelte/internal";
function create_fragment($$, ctx) {
var h1, text0, text1, text2;
@@ -8,7 +8,7 @@ function create_fragment($$, ctx) {
c() {
h1 = createElement("h1");
text0 = createText("Hello ");
- text1 = createText(ctx.name);
+ text1 = createText(name);
text2 = createText("!");
},
@@ -31,16 +31,12 @@ function create_fragment($$, ctx) {
};
}
-function instance($$self) {
- let name = 'world';
-
- return { name };
-}
+let name = 'world';
class SvelteComponent extends SvelteComponent_1 {
constructor(options) {
super();
- init(this, options, instance, create_fragment, safe_not_equal);
+ init(this, options, identity, create_fragment, safe_not_equal);
}
}
diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js
index e42ab8a35b..eda6f1f721 100644
--- a/test/js/samples/use-elements-as-anchors/expected.js
+++ b/test/js/samples/use-elements-as-anchors/expected.js
@@ -238,7 +238,7 @@ function create_fragment($$, ctx) {
}
if (if_block4) if_block4.d(detach);
-
+
if (detach) {
detachNode(if_block4_anchor);
}