diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts
index 7e3249a31e..d568461b10 100644
--- a/src/compiler/compile/render_dom/Block.ts
+++ b/src/compiler/compile/render_dom/Block.ts
@@ -393,16 +393,34 @@ export default class Block {
const block = dev && this.get_unique_name('block');
- const init_statements = Array.from(this.variables.values()).filter(({ init }) => init !== undefined).map(({ id, init }) => {
- return b`${id} = ${init}`;
+ const init_declarations = [];
+ const init_statements = [];
+
+ Array.from(this.variables.values()).forEach(({ id, init }) => {
+ init_declarations.push(b`let ${id};`);
+
+ if (init) {
+ init_statements.push(b`${id} = ${init}`);
+ }
+ });
+
+ console.log("H");
+ this.chunks.init.forEach(node => {
+ if (Array.isArray(node) && node[0].type === "VariableDeclaration") {
+ node[0].declarations.forEach(({ id, init }) => {
+ console.log(id);
+ init_declarations.push(b`let ${id};`);
+ init_statements.push(b`${id} = ${init}`);
+ });
+ } else {
+ init_declarations.push(node);
+ }
});
const body = b`
${this.chunks.declarations}
- ${Array.from(this.variables.values()).map(({ id }) => {
- return b`let ${id}`;
- })}
+ ${init_declarations}
${init_statements.length > 0
? b`
@@ -414,8 +432,6 @@ export default class Block {
: ''
}
- ${this.chunks.init}
-
${dev
? b`
const ${block} = ${return_value};
diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts
index cebc42ecd0..dd1fba8f7a 100644
--- a/src/compiler/compile/render_dom/index.ts
+++ b/src/compiler/compile/render_dom/index.ts
@@ -454,35 +454,41 @@ export default function dom(
let instance_javascript_with_ctx = [];
let initializedIdentifiers = [];
- instance_javascript.forEach(node => {
- instance_javascript_with_ctx.push(node);
-
- if (Array.isArray(node) && node[0].type === "VariableDeclaration" ) {
- walk(node[0], {
- enter(declaration: Identifier) {
- if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) {
- let index = renderer.initial_context.findIndex(member => member.name === declaration.name);
-
- if (index >= 0) {
- node.push(x`#return_values[${index}] = ${declaration}`);
- initializedIdentifiers.push(declaration.name);
+
+ if (instance_javascript === null) {
+ instance_javascript_with_ctx = instance_javascript;
+ } else {
+ instance_javascript.forEach(node => {
+ instance_javascript_with_ctx.push(node);
+
+ if (Array.isArray(node) && node[0].type === "VariableDeclaration" ) {
+ walk(node[0], {
+ enter(declaration: Identifier) {
+ if (declaration.type === 'Identifier' && !initializedIdentifiers.includes(declaration.name)) {
+ let index = renderer.initial_context.findIndex(member => member.name === declaration.name);
+
+ if (index >= 0) {
+ node.push(x`#return_values[${index}] = ${declaration}`);
+ initializedIdentifiers.push(declaration.name);
+ }
}
}
- }
- });
- }
-
- if (node.type === "FunctionDeclaration") {
- if (!initializedIdentifiers.includes(node.id.name)) {
- let index = renderer.initial_context.findIndex(member => member.name === node.id.name);
-
- if (index >= 0) {
- instance_javascript_with_ctx.push(x`#return_values[${index}] = ${node.id.name}`);
- initializedIdentifiers.push(node.id.name);
+ });
+ }
+
+ if (node.type === "FunctionDeclaration") {
+ if (!initializedIdentifiers.includes(node.id.name)) {
+ let index = renderer.initial_context.findIndex(member => member.name === node.id.name);
+
+ if (index >= 0) {
+ instance_javascript_with_ctx.push(x`#return_values[${index}] = ${node.id.name}`);
+ initializedIdentifiers.push(node.id.name);
+ }
}
}
- }
- });
+ });
+ }
+
const instance_try_block: any = b`
try {
diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts
index e352b610f9..6f85ae9830 100644
--- a/src/compiler/compile/render_ssr/index.ts
+++ b/src/compiler/compile/render_ssr/index.ts
@@ -182,11 +182,13 @@ export default function ssr(
return $$rendered;
`
: b`
- ${reactive_declarations}
+ try {
+ ${instance_javascript}
- ${reactive_store_unsubscriptions}
+ ${reactive_declarations}
+
+ ${reactive_store_unsubscriptions}
- try {
return ${literal};
} catch (e) {
@handle_error(@get_current_component(), e);
@@ -198,13 +200,13 @@ export default function ssr(
slots,
...reactive_store_declarations,
...reactive_store_subscriptions,
- b`
- try {
- ${instance_javascript}
- } catch (e) {
- @handle_error(@get_current_component(), e);
- }
- `,
+ // b`
+ // try {
+ // ${instance_javascript}
+ // } catch (e) {
+ // @handle_error(@get_current_component(), e);
+ // }
+ // `,
...parent_bindings,
css.code && b`$$result.css.add(#css);`,
main
diff --git a/test/runtime/samples/error-handling-dynamic-component/_config.js b/test/runtime/samples/error-handling-dynamic-component/_config.js
new file mode 100644
index 0000000000..acd4e2a2f0
--- /dev/null
+++ b/test/runtime/samples/error-handling-dynamic-component/_config.js
@@ -0,0 +1,5 @@
+export default {
+ test({ assert, component }) {
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-dynamic-component/child.svelte b/test/runtime/samples/error-handling-dynamic-component/child.svelte
new file mode 100644
index 0000000000..19c327680a
--- /dev/null
+++ b/test/runtime/samples/error-handling-dynamic-component/child.svelte
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-dynamic-component/main.svelte b/test/runtime/samples/error-handling-dynamic-component/main.svelte
new file mode 100644
index 0000000000..5395fbb0d3
--- /dev/null
+++ b/test/runtime/samples/error-handling-dynamic-component/main.svelte
@@ -0,0 +1,12 @@
+
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block-non-array/_config.js b/test/runtime/samples/error-handling-each-block-non-array/_config.js
new file mode 100644
index 0000000000..acd4e2a2f0
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block-non-array/_config.js
@@ -0,0 +1,5 @@
+export default {
+ test({ assert, component }) {
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block-non-array/main.svelte b/test/runtime/samples/error-handling-each-block-non-array/main.svelte
new file mode 100644
index 0000000000..b4fb0abca4
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block-non-array/main.svelte
@@ -0,0 +1,20 @@
+
+
+{#each a as item}
+ {item}
+{/each}
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js b/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js
new file mode 100644
index 0000000000..edd0bd074b
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block-reactive-non-array/_config.js
@@ -0,0 +1,10 @@
+export default {
+ async test({ assert, component, target, window }) {
+ const button = target.querySelector('button');
+ const event = new window.MouseEvent('click');
+
+ await button.dispatchEvent(event);
+
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte b/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte
new file mode 100644
index 0000000000..0a39d8a0b7
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block-reactive-non-array/main.svelte
@@ -0,0 +1,14 @@
+
+
+{#each a.b.c as item}
+ {item}
+{/each}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block/_config.js b/test/runtime/samples/error-handling-each-block/_config.js
new file mode 100644
index 0000000000..acd4e2a2f0
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block/_config.js
@@ -0,0 +1,5 @@
+export default {
+ test({ assert, component }) {
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-each-block/main.svelte b/test/runtime/samples/error-handling-each-block/main.svelte
new file mode 100644
index 0000000000..0a39d8a0b7
--- /dev/null
+++ b/test/runtime/samples/error-handling-each-block/main.svelte
@@ -0,0 +1,14 @@
+
+
+{#each a.b.c as item}
+ {item}
+{/each}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block-reactive/_config.js b/test/runtime/samples/error-handling-if-block-reactive/_config.js
new file mode 100644
index 0000000000..edd0bd074b
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block-reactive/_config.js
@@ -0,0 +1,10 @@
+export default {
+ async test({ assert, component, target, window }) {
+ const button = target.querySelector('button');
+ const event = new window.MouseEvent('click');
+
+ await button.dispatchEvent(event);
+
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block-reactive/main.svelte b/test/runtime/samples/error-handling-if-block-reactive/main.svelte
new file mode 100644
index 0000000000..e3752f2d5e
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block-reactive/main.svelte
@@ -0,0 +1,24 @@
+
+
+
+
+{#if a.b.c === true}
+ Hello world
+{/if}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block-show-component/_config.js b/test/runtime/samples/error-handling-if-block-show-component/_config.js
new file mode 100644
index 0000000000..edd0bd074b
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block-show-component/_config.js
@@ -0,0 +1,10 @@
+export default {
+ async test({ assert, component, target, window }) {
+ const button = target.querySelector('button');
+ const event = new window.MouseEvent('click');
+
+ await button.dispatchEvent(event);
+
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block-show-component/child.svelte b/test/runtime/samples/error-handling-if-block-show-component/child.svelte
new file mode 100644
index 0000000000..19c327680a
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block-show-component/child.svelte
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block-show-component/main.svelte b/test/runtime/samples/error-handling-if-block-show-component/main.svelte
new file mode 100644
index 0000000000..dbfb508df3
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block-show-component/main.svelte
@@ -0,0 +1,21 @@
+
+
+
+
+{#if show}
+
+{/if}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block/_config.js b/test/runtime/samples/error-handling-if-block/_config.js
new file mode 100644
index 0000000000..acd4e2a2f0
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block/_config.js
@@ -0,0 +1,5 @@
+export default {
+ test({ assert, component }) {
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-if-block/main.svelte b/test/runtime/samples/error-handling-if-block/main.svelte
new file mode 100644
index 0000000000..e7f50afaf6
--- /dev/null
+++ b/test/runtime/samples/error-handling-if-block/main.svelte
@@ -0,0 +1,14 @@
+
+
+{#if a.b.c === true}
+ Hello world
+{/if}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-slotted-component/_config.js b/test/runtime/samples/error-handling-slotted-component/_config.js
new file mode 100644
index 0000000000..acd4e2a2f0
--- /dev/null
+++ b/test/runtime/samples/error-handling-slotted-component/_config.js
@@ -0,0 +1,5 @@
+export default {
+ test({ assert, component }) {
+ assert.equal(component.error, true);
+ }
+}
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-slotted-component/child.svelte b/test/runtime/samples/error-handling-slotted-component/child.svelte
new file mode 100644
index 0000000000..19c327680a
--- /dev/null
+++ b/test/runtime/samples/error-handling-slotted-component/child.svelte
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-slotted-component/main.svelte b/test/runtime/samples/error-handling-slotted-component/main.svelte
new file mode 100644
index 0000000000..6ad0d0ee88
--- /dev/null
+++ b/test/runtime/samples/error-handling-slotted-component/main.svelte
@@ -0,0 +1,15 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/test/runtime/samples/error-handling-slotted-component/wrapper.svelte b/test/runtime/samples/error-handling-slotted-component/wrapper.svelte
new file mode 100644
index 0000000000..8c813a7b0e
--- /dev/null
+++ b/test/runtime/samples/error-handling-slotted-component/wrapper.svelte
@@ -0,0 +1,7 @@
+
+
+
\ No newline at end of file