Skip to content

Commit

Permalink
add if_block existence check in block.p (sveltejs#4633)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushkine authored and taylorzane committed Dec 17, 2020
1 parent e4fd22f commit 9847fe7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/compiler/compile/render_dom/wrappers/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9847fe7

Please sign in to comment.