From 6665a52bad7072f2b758875a36173aaee8a52e47 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 30 Aug 2019 13:35:05 -0400 Subject: [PATCH] update simple if-blocks with complex but static conditions --- src/compiler/compile/render_dom/wrappers/IfBlock.ts | 4 ++++ .../if-block-static-with-dynamic-contents/_config.js | 12 ++++++++++++ .../main.svelte | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/runtime/samples/if-block-static-with-dynamic-contents/_config.js create mode 100644 test/runtime/samples/if-block-static-with-dynamic-contents/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index f12929ffb1..64b90ecaf3 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -493,6 +493,10 @@ export default class IfBlockWrapper extends Wrapper { } `); } + } else if (dynamic) { + block.builders.update.add_block( + `if (${branch.condition}) ${name}.p(changed, ctx);` + ); } block.builders.destroy.add_line(`${if_name}${name}.d(${detaching});`); diff --git a/test/runtime/samples/if-block-static-with-dynamic-contents/_config.js b/test/runtime/samples/if-block-static-with-dynamic-contents/_config.js new file mode 100644 index 0000000000..c5c99c5305 --- /dev/null +++ b/test/runtime/samples/if-block-static-with-dynamic-contents/_config.js @@ -0,0 +1,12 @@ +export default { + props: { + foo: 42 + }, + + html: '

42

', + + test({ assert, component, target }) { + component.foo = 43; + assert.htmlEqual(target.innerHTML, '

43

'); + } +}; diff --git a/test/runtime/samples/if-block-static-with-dynamic-contents/main.svelte b/test/runtime/samples/if-block-static-with-dynamic-contents/main.svelte new file mode 100644 index 0000000000..57484f252f --- /dev/null +++ b/test/runtime/samples/if-block-static-with-dynamic-contents/main.svelte @@ -0,0 +1,9 @@ + + +{#if show()} +

{foo}

+{/if}