From 0204140045d556c3fcbc359270d9ac122bb2dd48 Mon Sep 17 00:00:00 2001 From: Daniel Imfeld Date: Fri, 15 May 2020 20:34:23 +0000 Subject: [PATCH] Fix check for uninitialized `condition` Fixes #4840 --- src/compiler/compile/render_dom/wrappers/IfBlock.ts | 2 +- .../RRR.svelte | 1 + .../_config.js | 3 +++ .../main.svelte | 13 +++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/if-block-static-with-elseif-else-and-outros/RRR.svelte create mode 100644 test/runtime/samples/if-block-static-with-elseif-else-and-outros/_config.js create mode 100644 test/runtime/samples/if-block-static-with-elseif-else-and-outros/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index e18d9f3b6bc3..220b52990201 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -392,7 +392,7 @@ export default class IfBlockWrapper extends Wrapper { ${snippet && ( dependencies.length > 0 ? b`if (${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}` - : b`if (${condition} == -1) ${condition} = !!${snippet}` + : b`if (${condition} == null) ${condition} = !!${snippet}` )} if (${condition}) return ${i};` : b`return ${i};`)} diff --git a/test/runtime/samples/if-block-static-with-elseif-else-and-outros/RRR.svelte b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/RRR.svelte new file mode 100644 index 000000000000..724237324909 --- /dev/null +++ b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/RRR.svelte @@ -0,0 +1 @@ +rrr \ No newline at end of file diff --git a/test/runtime/samples/if-block-static-with-elseif-else-and-outros/_config.js b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/_config.js new file mode 100644 index 000000000000..8b2c6d2d6671 --- /dev/null +++ b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/_config.js @@ -0,0 +1,3 @@ +export default { + html: 'eee' +}; diff --git a/test/runtime/samples/if-block-static-with-elseif-else-and-outros/main.svelte b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/main.svelte new file mode 100644 index 000000000000..b60885722e55 --- /dev/null +++ b/test/runtime/samples/if-block-static-with-elseif-else-and-outros/main.svelte @@ -0,0 +1,13 @@ + + +{#if "Eva".startsWith('E')} + eee +{:else if x} + def +{:else} + +{/if}