From 3ed11fa29d8364807cf179ebe304a2d20824415e Mon Sep 17 00:00:00 2001 From: pushkin Date: Fri, 24 Apr 2020 01:51:02 +0200 Subject: [PATCH] add if_block existence check in block.p (#4633) --- .../compile/render_dom/wrappers/IfBlock.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index 9b3e56635d..78b821170f 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -334,7 +334,11 @@ export default class IfBlockWrapper extends Wrapper { `); } } else if (dynamic) { - block.chunks.update.push(b`${name}.p(#ctx, #dirty);`); + if (if_exists_condition) { + block.chunks.update.push(b`if (${if_exists_condition}) ${name}.p(#ctx, #dirty);`); + } else { + block.chunks.update.push(b`${name}.p(#ctx, #dirty);`); + } } if (if_exists_condition) { @@ -357,7 +361,7 @@ export default class IfBlockWrapper extends Wrapper { parent_node: Identifier, _parent_nodes: Identifier, dynamic, - { name, anchor, has_else, has_transitions }, + { name, anchor, has_else, has_transitions, if_exists_condition }, detaching ) { const select_block_type = this.renderer.component.get_unique_name(`select_block_type`); @@ -486,7 +490,11 @@ export default class IfBlockWrapper extends Wrapper { `); } } else if (dynamic) { - block.chunks.update.push(b`${name}.p(#ctx, #dirty);`); + if (if_exists_condition) { + block.chunks.update.push(b`if (${if_exists_condition}) ${name}.p(#ctx, #dirty);`); + } else { + block.chunks.update.push(b`${name}.p(#ctx, #dirty);`); + } } block.chunks.destroy.push(