mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
Merge pull request #1199 from sveltejs/gh-1195
Fix select_block_type scoping issue
This commit is contained in:
commit
da165be1bf
@ -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);
|
||||
`);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
9
test/runtime/samples/if-block-else-in-each/_config.js
Normal file
9
test/runtime/samples/if-block-else-in-each/_config.js
Normal file
@ -0,0 +1,9 @@
|
||||
export default {
|
||||
data: {
|
||||
array: [true, false],
|
||||
},
|
||||
html: `
|
||||
<div>foo</div>
|
||||
<div>bar</div>
|
||||
`,
|
||||
};
|
7
test/runtime/samples/if-block-else-in-each/main.html
Normal file
7
test/runtime/samples/if-block-else-in-each/main.html
Normal file
@ -0,0 +1,7 @@
|
||||
{{#each array as item}}
|
||||
{{#if item}}
|
||||
<div>foo</div>
|
||||
{{else}}
|
||||
<div>bar</div>
|
||||
{{/if}}
|
||||
{{/each}}
|
Loading…
Reference in New Issue
Block a user