From e71ca48735694a703f9d72ad5dd92d25a94e83b4 Mon Sep 17 00:00:00 2001 From: rster20002 Date: Thu, 29 Jul 2021 09:16:14 +0200 Subject: [PATCH] Template errors are now catched (within {}) Fixed posability for there to be an empty try block --- src/compiler/compile/render_dom/Block.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index 00440b71f3..ab8f06cfbf 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -388,6 +388,10 @@ export default class Block { const block = dev && this.get_unique_name('block'); + let init_statements = Array.from(this.variables.values()).filter(({ init }) => init !== undefined).map(({ id, init }) => { + return b`${id} = ${init}`; + }); + const body = b` ${this.chunks.declarations} @@ -395,12 +399,14 @@ export default class Block { return b`let ${id}`; })} - try { - ${Array.from(this.variables.values()).filter(({ init }) => init !== undefined).map(({ id, init }) => { - return b`${id} = ${init}`; - })} - } catch (e) { - // @handle_error(#component, e); + ${init_statements.length > 0 + ? b` + try { + ${init_statements} + } catch (e) { + @handle_error(@get_current_component(), e); + }` + : '' } ${this.chunks.init}