diff --git a/src/generators/nodes/IfBlock.ts b/src/generators/nodes/IfBlock.ts index 17cd92bc29..463fe4ab5e 100644 --- a/src/generators/nodes/IfBlock.ts +++ b/src/generators/nodes/IfBlock.ts @@ -313,15 +313,12 @@ function compound( const current_block_type = block.getUniqueName(`current_block_type`); const current_block_type_and = hasElse ? '' : `${current_block_type} && `; - generator.blocks.push(deindent` + block.builders.init.addBlock(deindent` function ${select_block_type}(state) { ${branches .map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block};`) .join('\n')} } - `); - - block.builders.init.addBlock(deindent` var ${current_block_type} = ${select_block_type}(state); var ${name} = ${current_block_type_and}${current_block_type}(#component, state); `); diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index 2e6975d978..28e8b500bc 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -189,6 +189,10 @@ var proto = { function create_main_fragment(component, state) { var if_block_anchor; + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } var current_block_type = select_block_type(state); var if_block = current_block_type(component, state); @@ -268,11 +272,6 @@ function create_if_block_1(component, state) { }; } -function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; -} - function SvelteComponent(options) { init(this, options); this._state = assign({}, options.data); diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index a6e7f09d8d..31b4b0f7a4 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -4,6 +4,10 @@ import { assign, createComment, createElement, detachNode, init, insertNode, noo function create_main_fragment(component, state) { var if_block_anchor; + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } var current_block_type = select_block_type(state); var if_block = current_block_type(component, state); @@ -83,11 +87,6 @@ function create_if_block_1(component, state) { }; } -function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; -} - function SvelteComponent(options) { init(this, options); this._state = assign({}, options.data); diff --git a/test/runtime/samples/if-block-else-in-each/_config.js b/test/runtime/samples/if-block-else-in-each/_config.js new file mode 100644 index 0000000000..99337dfc40 --- /dev/null +++ b/test/runtime/samples/if-block-else-in-each/_config.js @@ -0,0 +1,9 @@ +export default { + data: { + array: [true, false], + }, + html: ` +